From f59c7a07e9adbd4d3a54c113e80b41915ddf3fbc Mon Sep 17 00:00:00 2001
From: gpetrochenkov-usgs <gpetrochenkov@usgs.gov>
Date: Tue, 26 May 2020 09:49:29 -0400
Subject: [PATCH] Almost done addressing tests

---
 assets/karma.conf.js                          |  2 +-
 .../hydrograph/drawing-data.spec.js           |  8 ++--
 .../components/hydrograph/index.spec.js       | 21 ++++++++-
 .../components/hydrograph/legend.spec.js      |  2 +-
 .../hydrograph/time-series-graph.spec.js      | 43 ++++++++++++++++---
 .../selectors/flood-data-selector.spec.js     |  6 +--
 .../scripts/store/flood-inundation.spec.js    |  2 +-
 assets/src/scripts/web-services/flood-data.js |  1 -
 .../scripts/web-services/flood-data.spec.js   |  2 +-
 9 files changed, 67 insertions(+), 20 deletions(-)

diff --git a/assets/karma.conf.js b/assets/karma.conf.js
index 56d8955ee..c2942d2fa 100644
--- a/assets/karma.conf.js
+++ b/assets/karma.conf.js
@@ -60,7 +60,7 @@ module.exports = function (config) {
         // test results reporter to use
         // possible values: 'dots', 'progress'
         // available reporters: https://npmjs.org/browse/keyword/karma-reporter
-        reporters: ['spec'],
+        reporters: ['dots'],
 
         // web server port
         port: 9876,
diff --git a/assets/src/scripts/components/hydrograph/drawing-data.spec.js b/assets/src/scripts/components/hydrograph/drawing-data.spec.js
index 82ae49f7a..5fdb1d265 100644
--- a/assets/src/scripts/components/hydrograph/drawing-data.spec.js
+++ b/assets/src/scripts/components/hydrograph/drawing-data.spec.js
@@ -1055,7 +1055,7 @@ describe('drawingData module', () => {
                     queryInfo: {
                         'current:P7D': {
                             notes: {
-                                requestDT: 1488388500000,
+                                requestDT: 1520966700000,
                                 'filter:timeRange': {
                                     mode: 'PERIOD',
                                     periodDays: '7',
@@ -1106,7 +1106,7 @@ describe('drawingData module', () => {
 
             it('Return the expected data points', () => {
                 let result = getWaterwatchFloodLevelDataPoints(TEST_STATE);
-                expect(result.length).toBe(1);
+                expect(result.length).toBe(4);
                 expect(result[0].length).toBe(2);
                 expect(result[0][0]).toEqual({
                     value: 1,
@@ -1114,7 +1114,7 @@ describe('drawingData module', () => {
                         year: 2018,
                         month: 3,
                         day: 6,
-                        hour: 15,
+                        hour: 13,
                         minute: 45,
                         second: 0,
                         zone: 'America/Chicago'
@@ -1124,7 +1124,7 @@ describe('drawingData module', () => {
 
             it('Return the expected data points', () => {
                 let result = getWaterwatchFloodLevelDataPoints(TEST_STATE);
-                expect(result.length).toBe(1);
+                expect(result.length).toBe(4);
                 expect(result[0].length).toBe(2);
                 expect(result[0][1]).toEqual({
                     value: 1,
diff --git a/assets/src/scripts/components/hydrograph/index.spec.js b/assets/src/scripts/components/hydrograph/index.spec.js
index 1f4685631..58e24a6a5 100644
--- a/assets/src/scripts/components/hydrograph/index.spec.js
+++ b/assets/src/scripts/components/hydrograph/index.spec.js
@@ -4,6 +4,7 @@ import {configureStore} from '../../store';
 import {Actions as ivTimeSeriesDataActions} from '../../store/instantaneous-value-time-series-data';
 import {Actions as statisticsDataActions} from '../../store/statistics-data';
 import {Actions as timeZoneActions} from '../../store/time-zone';
+import {Actions as floodStateActions} from '../../store/flood-inundation';
 
 
 const TEST_STATE = {
@@ -147,6 +148,12 @@ const TEST_STATE = {
     },
     ui: {
         width: 400
+    },
+    floodState: {
+        actionStage: 1,
+        floodStage: 2,
+        moderateFloodStage: 3,
+        majorFloodStage: 4
     }
 };
 
@@ -444,11 +451,17 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => {
                 ui: {
                     windowWidth: 400,
                     width: 400
-                }
+                },
+                 floodState: {
+                     actionStage: 1,
+                     floodStage: 2,
+                     moderateFloodStage: 3,
+                     majorFloodStage: 4
+                 }
 
             });
 
-            attachToNode(store, graphNode, {siteno: '123456788'});
+            attachToNode(store, graphNode, {siteno: '12345678'});
             window.requestAnimationFrame(() => {
                 done();
             });
@@ -516,9 +529,13 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => {
     describe('hide elements when showOnlyGraph is set to true', () => {
         let store;
         beforeEach(() => {
+            spyOn(floodStateActions, 'retrieveWaterwatchData').and.returnValue(function() {
+                return Promise.resolve({});
+            });
             spyOn(ivTimeSeriesDataActions, 'retrieveIVTimeSeries').and.returnValue(function() {
                 return Promise.resolve({});
             });
+
             store = configureStore({
                 ...TEST_STATE,
                 ivTimeSeriesData: {
diff --git a/assets/src/scripts/components/hydrograph/legend.spec.js b/assets/src/scripts/components/hydrograph/legend.spec.js
index d271dce10..7bfe7c501 100644
--- a/assets/src/scripts/components/hydrograph/legend.spec.js
+++ b/assets/src/scripts/components/hydrograph/legend.spec.js
@@ -143,7 +143,7 @@ describe('UV: Legend module', () => {
             };
             const result = legendMarkerRowsSelector(newData);
 
-            expect(result.length).toBe(1);
+            expect(result.length).toBe(5);
             expect(result[0].length).toBe(3);
             expect(result[0][0].type).toEqual(textOnlyMarker);
             expect(result[0][1].type).toEqual(lineMarker);
diff --git a/assets/src/scripts/components/hydrograph/time-series-graph.spec.js b/assets/src/scripts/components/hydrograph/time-series-graph.spec.js
index 39d57b6fb..86abd4900 100644
--- a/assets/src/scripts/components/hydrograph/time-series-graph.spec.js
+++ b/assets/src/scripts/components/hydrograph/time-series-graph.spec.js
@@ -97,9 +97,20 @@ const TEST_STATE = {
         variables: {
             '45807197': {
                 variableCode: {
-                    value: '00065'
+                    value: '00060'
                 },
                 oid: '45807197',
+                variableName: 'Test title for 00060',
+                variableDescription: 'Test description for 00060',
+                unit: {
+                    unitCode: 'unitCode'
+                }
+            },
+            '45809999': {
+                variableCode: {
+                    value: '00065'
+                },
+                oid: '45809999',
                 variableName: 'Test title for 00065',
                 variableDescription: 'Test description for 00065',
                 unit: {
@@ -166,6 +177,12 @@ const TEST_STATE = {
     },
     ui: {
         width: 400
+    },
+    floodState: {
+        actionStage: 1,
+        floodStage: 2,
+        moderateFloodStage: 3,
+        majorFloodStage: 4
     }
 };
 
@@ -278,10 +295,16 @@ describe('time series graph', () => {
 
     describe('flood level lines', () => {
 
-        beforeEach(() => {
-            div.call(drawTimeSeriesGraph, store, '12345678', false, false);
-        });
+        let tempStore;
 
+        tempStore = {
+                ...TEST_STATE,
+                ivTimeSeriesState: {
+                    ...TEST_STATE.ivTimeSeriesState,
+                    currentIVVariableID: '45809999'
+                }
+            };
+        div.call(drawTimeSeriesGraph, configureStore(tempStore), '12345678', false, false);
         it('Should render four lines', () => {
             expect(selectAll('#flood-level-points .action-stage').size()).toBe(1);
             expect(selectAll('#flood-level-points .flood-stage').size()).toBe(1);
@@ -289,8 +312,16 @@ describe('time series graph', () => {
             expect(selectAll('#flood-level-points .major-flood-stage').size()).toBe(1);
         });
 
-        it('Should remove the lines when removing the median statistics data', (done) => {
-            store.dispatch(Actions.setCurrentIVVariable(45807190));
+        tempStore = {
+                ...TEST_STATE,
+                ivTimeSeriesState: {
+                    ...TEST_STATE.ivTimeSeriesState,
+                    currentIVVariableID: '45807197'
+                }
+            };
+        div.call(drawTimeSeriesGraph, configureStore(tempStore), '12345678', false, false);
+
+        it('Should remove the lines when removing the waterwatch flood levels data', (done) => {
             window.requestAnimationFrame(() => {
                 expect(selectAll('#flood-level-points').size()).toBe(0);
                 done();
diff --git a/assets/src/scripts/selectors/flood-data-selector.spec.js b/assets/src/scripts/selectors/flood-data-selector.spec.js
index e9f4173cf..0388f3caf 100644
--- a/assets/src/scripts/selectors/flood-data-selector.spec.js
+++ b/assets/src/scripts/selectors/flood-data-selector.spec.js
@@ -91,9 +91,9 @@ describe('flood-data-selector', () => {
             })).toBeFalsy();
         });
 
-        it('return true if flood stages are available', () => {
+        it('return true if waterwatch flood levels are available', () => {
             expect(hasWaterwatchData({
-                loodState: {
+                floodState: {
                     actionStage: 1,
                     floodStage: null,
                     moderateFloodStage: null,
@@ -112,7 +112,7 @@ describe('flood-data-selector', () => {
                     moderateFloodStage: 3,
                     majorFloodStage: 4
                 }
-            })).toBe([1,2,3,4]);
+            })).toEqual([1,2,3,4]);
         });
     });
 
diff --git a/assets/src/scripts/store/flood-inundation.spec.js b/assets/src/scripts/store/flood-inundation.spec.js
index 7e51ed10d..2668d50da 100644
--- a/assets/src/scripts/store/flood-inundation.spec.js
+++ b/assets/src/scripts/store/flood-inundation.spec.js
@@ -2,7 +2,7 @@ import { applyMiddleware, combineReducers, createStore } from 'redux';
 import {default as thunk} from 'redux-thunk';
 
 import {Actions, floodDataReducer, floodStateReducer} from './flood-inundation';
-import MOCK_WATERWATCH_FLOOD_LEVELS from "../mock-service-data";
+import {MOCK_WATERWATCH_FLOOD_LEVELS} from "../mock-service-data";
 
 describe('store/flood-inundation module', () => {
     /* eslint no-use-before-define: 0 */
diff --git a/assets/src/scripts/web-services/flood-data.js b/assets/src/scripts/web-services/flood-data.js
index 477920f7b..d57f46953 100644
--- a/assets/src/scripts/web-services/flood-data.js
+++ b/assets/src/scripts/web-services/flood-data.js
@@ -64,7 +64,6 @@ const fetchWaterwatchData = function(waterwatchQuery, siteno) {
 
 // waterwatch webservice calls
 export const fetchWaterwatchFloodLevels = function(siteno) {
-    console.log(`${waterwatchUrl}/floodstage?format=${format}&site=${siteno}`);
     const waterwatchQuery = `${waterwatchUrl}/floodstage?format=${format}&site=${siteno}`;
     return fetchWaterwatchData(waterwatchQuery, siteno);
 };
diff --git a/assets/src/scripts/web-services/flood-data.spec.js b/assets/src/scripts/web-services/flood-data.spec.js
index 7a041752e..adafd4357 100644
--- a/assets/src/scripts/web-services/flood-data.spec.js
+++ b/assets/src/scripts/web-services/flood-data.spec.js
@@ -1,6 +1,6 @@
 import {fetchFloodExtent, fetchFloodFeatures,
     fetchWaterwatchFloodLevels} from './flood-data';
-import MOCK_WATERWATCH_FLOOD_LEVELS from '../mock-service-data';
+import {MOCK_WATERWATCH_FLOOD_LEVELS} from '../mock-service-data';
 
 
 describe('flood_data module', () => {
-- 
GitLab