Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #188 from USGS-WiM/staging
Browse files Browse the repository at this point in the history
Staging into Master
  • Loading branch information
amedenblik authored May 9, 2022
2 parents c3e805c + efa1332 commit c48bb13
Show file tree
Hide file tree
Showing 7 changed files with 340 additions and 29 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- Contact email address

### Fixed
### Removed

- Forests parameter from fire hydrology basin characteristics

-
## [v0.1.0-beta.1](https://github.com/USGS-WiM/StreamStats-National/releases/tag/v0.1.0-beta.1) - 2022-04-20

### Added
Expand Down
161 changes: 144 additions & 17 deletions src/app/map/map.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,81 @@ import { HttpClient } from '@angular/common/http';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ToastrModule } from 'ngx-toastr';
import { MapComponent } from './map.component';
import { Workflow } from '../shared/interfaces/workflow/workflow';
import { ConfigService } from '../shared/config/config.service';

describe('MapComponent', () => {
let component: MapComponent;
let fixture: ComponentFixture<MapComponent>;

// Mock workflow
let workflow: Workflow = {
title: "Fire Hydrology",
description: "",
functionality: "",
icon: "",
steps: [
{
"label": "Select a Fire Hydrology Query Method",
"name": "selectFireHydroProcess",
"type": "checkbox",
"value": "",
"options":
[
{
"text": "Query by Basin",
"selected": true,
"nestedSteps":
[
{
"label": "Select a Point",
"name": "selectFireHydroBasin",
"type": "subscription",
"value": "",
"validators":
{
"required": true
},
"options":
[
{
"text": "Click on the map",
"selected": false
}
]
},
]
},
{
"text": "Query by Fire Perimeters",
"selected": false,
"nestedSteps":
[
{
"label": "Select a Fire Perimeter",
"name": "selectFireHydroPerimeter",
"type": "subscription",
"value": "",
"validators":
{
"required": true
},
"options":
[
{
"text": "Click on the map",
"selected": false
}
]
}
]
}
]
}
],
output: []
};

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
Expand Down Expand Up @@ -46,6 +115,24 @@ describe('MapComponent', () => {
}
},
];

component["configSettings"] = {
workflowLayers: [
{
"name": "NHD Flowlines",
"url": "https://labs.waterdata.usgs.gov/geoserver/gwc/service/",
"type": "WMS",
"layerOptions": {
"layers": "wmadata:nhdflowline_network",
"minZoom": 13,
"maxZoom": 19,
"zIndex": 9999,
"format": "image/png",
"transparent": "true"
}
},
]
};
fixture.detectChanges();
});

Expand All @@ -54,23 +141,6 @@ describe('MapComponent', () => {
});

it('should create workflow layers', () => {
component["configSettings"] = {
workflowLayers: [
{
"name": "NHD Flowlines",
"url": "https://labs.waterdata.usgs.gov/geoserver/gwc/service/",
"type": "WMS",
"layerOptions": {
"layers": "wmadata:nhdflowline_network",
"minZoom": 13,
"maxZoom": 19,
"zIndex": 9999,
"format": "image/png",
"transparent": "true"
}
},
]
};
// Method is private
component["loadLayers"]();
expect(component.workflowLayers["NHD Flowlines"].options.layers).toEqual("wmadata:nhdflowline_network");
Expand All @@ -84,4 +154,61 @@ describe('MapComponent', () => {
fixture.detectChanges();
expect(clickSpy).toHaveBeenCalledWith(click["latlng"])
});

it('should remove workflow layers', () => {
// Need to load the layers and add to map first to test removing them
component["loadLayers"]();
component["addLayers"]("NHD Flowlines", true);
// Remove layers
component["removeWorkFlowLayers"]();
expect(component._mapService.map.hasLayer(component.workflowLayers["NHD Flowlines"])).toBeFalse();
});

it('should check available layers in workflow and add Query by Basin layers', () => {
let addLayerSpy = spyOn(component, "addLayers");
component.selectedWorkflow = workflow;
component.workflowData = workflow;

component.workflowData.steps[0].options[0].selected = true;
component.workflowData.steps[0].options[1].selected = false;
// Check available layers
component["checkAvailableLayers"]();
expect(addLayerSpy).toHaveBeenCalledWith("NHD Flowlines", true);
expect(addLayerSpy).toHaveBeenCalledWith("Archived Wildland Fire Perimeters", true);
});

it('should check available layers in workflow and add Query by Fire Parameters layers', () => {
let addLayerSpy = spyOn(component, "addLayers");

component.selectedWorkflow = workflow;
component.workflowData = workflow;

component.workflowData.steps[0].options[0].selected = false;
component.workflowData.steps[0].options[1].selected = true;
// Check available layers
component["checkAvailableLayers"]();
expect(addLayerSpy).not.toHaveBeenCalledWith("NHD Flowlines", true);
expect(addLayerSpy).toHaveBeenCalledWith("Archived Wildland Fire Perimeters", true);
});

it('should add layers', () => {
let setWorkflowLayersSpy = spyOn(component._mapService, "setWorkflowLayers");

// Need to load layers to test adding them to the map
component["configSettings"] = {workflowLayers: component._mapService.workflowLayers};
component["loadLayers"]();
// Check available layers
component.addLayers("NHD Flowlines", true);
expect(setWorkflowLayersSpy).toHaveBeenCalled();
});

it('should set streamgage bounding box', () => {
let setStreamgagesSpy = spyOn(component._mapService, "setStreamgages");

component.currentZoom = 10;
component.streamgageLayerStatus = true;
// Check available layers
component.setBbox();
expect(setStreamgagesSpy).toHaveBeenCalled();
});
});
4 changes: 2 additions & 2 deletions src/app/shared/interfaces/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export interface Config {
visible: boolean,
maxZoom: number
}];
workflowLayers: [];
overlays: [];
workflowLayers: Array<any>;
overlays: Array<any>;
parameters: [{
fcpg_parameter: string,
description: string,
Expand Down
25 changes: 25 additions & 0 deletions src/app/shared/services/app.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { Config } from '../interfaces/config/config';

import { AppService } from './app.service';

Expand All @@ -21,4 +22,28 @@ describe('AppService', () => {
it('should be created', () => {
expect(service).toBeTruthy();
});

it('should set layer visibility to false', () => {
// Mock config settings
service["configSettings"] = <Config>{};
service["configSettings"].workflowLayers = [
{
"name": "Streamgages",
"url": "https://streamstats.usgs.gov/gagestatsservices/stations",
"layerOptions": {
"minZoom": 8
},
"visible": true
}, {
"name": "Test",
"url": "",
"layerOptions": {
"minZoom": 8
},
"visible": false
}
]
service.setLayerVisibility("Streamgages");
expect(service["configSettings"].workflowLayers[0].visible).toBeFalse();
});
});
Loading

0 comments on commit c48bb13

Please sign in to comment.