From 6c3fce1d4d40938776559f717544b6375d934229 Mon Sep 17 00:00:00 2001
From: mbucknell <mbucknell@usgs.gov>
Date: Thu, 11 Mar 2021 13:42:58 -0600
Subject: [PATCH] All tests are now working

---
 .../hydrograph/data-indicator.test.js         |  67 +++++++++--
 .../hydrograph/date-controls.test.js          |  36 +++---
 .../components/hydrograph/graph-controls.js   |   1 -
 .../hydrograph/graph-controls.test.js         |  26 +++--
 .../components/hydrograph/index.js            |   4 +-
 .../components/hydrograph/index.test.js       |  14 +--
 .../components/hydrograph/legend.test.js      |  10 +-
 .../hydrograph/method-picker.test.js          |  10 +-
 .../components/hydrograph/parameters.test.js  |  10 +-
 .../hydrograph/selectors/iv-data.js           |   2 +-
 .../hydrograph/selectors/iv-data.test.js      |  57 +++++++++-
 .../hydrograph/selectors/legend-data.js       |   1 -
 .../hydrograph/selectors/legend-data.test.js  |  33 ++++++
 .../hydrograph/selectors/time-series-data.js  |   5 +
 .../selectors/time-series-data.test.js        | 105 ++++++++++++------
 15 files changed, 290 insertions(+), 91 deletions(-)

diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/data-indicator.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/data-indicator.test.js
index a59740d69..f5d1cf0b3 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/data-indicator.test.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/data-indicator.test.js
@@ -1,16 +1,31 @@
 import {select} from 'd3-selection';
 
+import {configureStore} from 'ml/store';
+
 import * as utils from 'ui/utils';
 
-import {showDataLoadingIndicator} from './data-loading-indicator';
+import {showDataIndicators} from './data-indicator';
+import {TEST_PRIMARY_IV_DATA} from './mock-hydrograph-state';
 
 describe('monitoring-location/components/hydrograph/data-loading-indicator', () => {
     utils.mediaQuery = jest.fn().mockReturnValue(true);
 
     let div;
+    let store;
     beforeEach(() => {
-        div = select('body').append('div')
+        div = select('body').append('div');
+        div.append('div')
             .attr('id', 'hydrograph-loading-indicator-container');
+        div.append('div')
+            .attr('id', 'hydrograph-no-data-overlay');
+        store = configureStore({
+            hydrographData: {
+                primaryIVData: TEST_PRIMARY_IV_DATA
+            },
+            hydrographState: {
+                selectedIVMethodID: '90649'
+            }
+        });
     });
 
     afterEach(() => {
@@ -18,14 +33,52 @@ describe('monitoring-location/components/hydrograph/data-loading-indicator', ()
     });
 
     it('Renders a visible loading indicator with transform appropriately set', () => {
-        showDataLoadingIndicator(true, '100');
+        store = configureStore({
+            hydrographData: {
+                primaryIVData: TEST_PRIMARY_IV_DATA
+            },
+            hydrographState: {
+                selectedIVMethodID: '90649'
+            }
+        });
+        showDataIndicators(true, store);
         expect(div.select('.loading-indicator').size()).toBe(1);
-        expect(div.style('transform')).toEqual('translateY(50px)');
+        expect(div.select('#hydrograph-loading-indicator-container').style('transform')).toBeDefined();
     });
 
-    it('Removes a visible loading indicator when isVisible is false', () => {
-        showDataLoadingIndicator(true, '100');
-        showDataLoadingIndicator(false);
+    it('Removes a visible loading indicator when isLoading is false', () => {
+        store = configureStore({
+            hydrographData: {
+                primaryIVData: TEST_PRIMARY_IV_DATA
+            },
+            hydrographState: {
+                selectedIVMethodID: '90649'
+            }
+        });
+        showDataIndicators(true, store);
+        showDataIndicators(false, store);
         expect(div.select('.loading-indicator').size()).toBe(0);
     });
+
+    it('Shows a no data notification if the store contains no visible data', () => {
+        store = configureStore({
+            hydrographData: {},
+            hydrographState: {}
+        });
+        showDataIndicators(false, store);
+        expect(select('#hydrograph-no-data-overlay div').size()).toBe(1);
+    });
+
+    it('Does not show a no data notification if the store contains data', () => {
+        store = configureStore({
+            hydrographData: {
+                primaryIVData: TEST_PRIMARY_IV_DATA
+            },
+            hydrographState: {
+                selectedIVMethodID: '90649'
+            }
+        });
+        showDataIndicators(false, store);
+        expect(select('#hydrograph-no-data-overlay div').size()).toBe(0);
+    });
 });
\ No newline at end of file
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/date-controls.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/date-controls.test.js
index c0dcd93aa..47ff981b6 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/date-controls.test.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/date-controls.test.js
@@ -11,7 +11,7 @@ import * as hydrographData from 'ml/store/hydrograph-data';
 import * as hydrographState from 'ml/store/hydrograph-state';
 
 import {drawDateRangeControls} from './date-controls';
-import * as dataLoadingIndicator from './data-loading-indicator';
+import * as dataIndicator from './data-indicator';
 
 const TEST_STATE = {
     hydrographState: {
@@ -29,7 +29,7 @@ describe('monitoring-location/components/hydrograph/date-controls', () => {
     let fakeServer;
     let store;
     let retrieveSpy;
-    let loadingIndicatorSpy;
+    let showDataIndicatorSpy;
     config.locationTimeZone = 'America/Chicago';
 
     beforeEach(() => {
@@ -37,7 +37,7 @@ describe('monitoring-location/components/hydrograph/date-controls', () => {
         store = configureStore(TEST_STATE);
         fakeServer = sinon.createFakeServer();
         retrieveSpy = jest.spyOn(hydrographData, 'retrieveHydrographData');
-        loadingIndicatorSpy = jest.spyOn(dataLoadingIndicator, 'showDataLoadingIndicator');
+        showDataIndicatorSpy = jest.spyOn(dataIndicator, 'showDataIndicators');
     });
 
     afterEach(() => {
@@ -108,8 +108,8 @@ describe('monitoring-location/components/hydrograph/date-controls', () => {
             expect(div.select('#container-radio-group-and-form-buttons').attr('hidden')).toBe('true');
             expect(getSelectedDateRange(store.getState())).toEqual('P30D');
             expect(clearBrushOffsetSpy).toHaveBeenCalled();
-            expect(loadingIndicatorSpy.mock.calls).toHaveLength(1);
-            expect(loadingIndicatorSpy.mock.calls[0][0]).toBe(true);
+            expect(showDataIndicatorSpy.mock.calls).toHaveLength(1);
+            expect(showDataIndicatorSpy.mock.calls[0][0]).toBe(true);
             expect(retrieveSpy.mock.calls).toHaveLength(1);
             expect(retrieveSpy.mock.calls[0][0]).toEqual('12345678');
             expect(retrieveSpy.mock.calls[0][1]).toEqual({
@@ -129,8 +129,8 @@ describe('monitoring-location/components/hydrograph/date-controls', () => {
             expect(div.select('#container-radio-group-and-form-buttons').attr('hidden')).toBe('true');
             expect(getSelectedDateRange(store.getState())).toEqual('P365D');
             expect(clearBrushOffsetSpy).toHaveBeenCalled();
-            expect(loadingIndicatorSpy.mock.calls).toHaveLength(1);
-            expect(loadingIndicatorSpy.mock.calls[0][0]).toBe(true);
+            expect(showDataIndicatorSpy.mock.calls).toHaveLength(1);
+            expect(showDataIndicatorSpy.mock.calls[0][0]).toBe(true);
             expect(retrieveSpy.mock.calls).toHaveLength(1);
             expect(retrieveSpy.mock.calls[0][0]).toEqual('12345678');
             expect(retrieveSpy.mock.calls[0][1]).toEqual({
@@ -150,7 +150,7 @@ describe('monitoring-location/components/hydrograph/date-controls', () => {
             expect(div.select('#container-radio-group-and-form-buttons').attr('hidden')).toBeNull();
             expect(getSelectedDateRange(store.getState())).toEqual('P7D');
             expect(clearBrushOffsetSpy).not.toHaveBeenCalled();
-            expect(loadingIndicatorSpy.mock.calls).toHaveLength(0);
+            expect(showDataIndicatorSpy.mock.calls).toHaveLength(0);
             expect(retrieveSpy).not.toHaveBeenCalled();
         });
 
@@ -164,8 +164,8 @@ describe('monitoring-location/components/hydrograph/date-controls', () => {
             expect(div.select('#container-radio-group-and-form-buttons').attr('hidden')).toBe('true');
             expect(getSelectedDateRange(store.getState())).toEqual('P7D');
             expect(clearBrushOffsetSpy).toHaveBeenCalled();
-            expect(loadingIndicatorSpy.mock.calls).toHaveLength(1);
-            expect(loadingIndicatorSpy.mock.calls[0][0]).toBe(true);
+            expect(showDataIndicatorSpy.mock.calls).toHaveLength(1);
+            expect(showDataIndicatorSpy.mock.calls[0][0]).toBe(true);
             expect(retrieveSpy.mock.calls).toHaveLength(1);
             expect(retrieveSpy.mock.calls[0][0]).toEqual('12345678');
             expect(retrieveSpy.mock.calls[0][1]).toEqual({
@@ -213,8 +213,8 @@ describe('monitoring-location/components/hydrograph/date-controls', () => {
 
             expect(clearBrushOffsetSpy).toHaveBeenCalled();
             expect(getSelectedDateRange(store.getState())).toEqual('P45D');
-            expect(loadingIndicatorSpy.mock.calls).toHaveLength(1);
-            expect(loadingIndicatorSpy.mock.calls[0][0]).toBe(true);
+            expect(showDataIndicatorSpy.mock.calls).toHaveLength(1);
+            expect(showDataIndicatorSpy.mock.calls[0][0]).toBe(true);
             expect(retrieveSpy.mock.calls[0][0]).toEqual('12345678');
             expect(retrieveSpy.mock.calls[0][1]).toEqual({
                 parameterCode: '00065',
@@ -234,7 +234,7 @@ describe('monitoring-location/components/hydrograph/date-controls', () => {
             expect(div.select('#custom-days-before-today-alert-container').attr('hidden')).toBeNull();
             expect(clearBrushOffsetSpy).not.toHaveBeenCalled();
             expect(getSelectedDateRange(store.getState())).toEqual('P7D');
-            expect(loadingIndicatorSpy.mock.calls).toHaveLength(0);
+            expect(showDataIndicatorSpy.mock.calls).toHaveLength(0);
             expect(retrieveSpy).not.toHaveBeenCalled();
         });
 
@@ -253,8 +253,8 @@ describe('monitoring-location/components/hydrograph/date-controls', () => {
                 end: '2020-01-16'
             });
             expect(clearBrushOffsetSpy).toHaveBeenCalled();
-            expect(loadingIndicatorSpy.mock.calls).toHaveLength(1);
-            expect(loadingIndicatorSpy.mock.calls[0][0]).toBe(true);
+            expect(showDataIndicatorSpy.mock.calls).toHaveLength(1);
+            expect(showDataIndicatorSpy.mock.calls[0][0]).toBe(true);
             expect(retrieveSpy.mock.calls).toHaveLength(1);
             expect(retrieveSpy.mock.calls[0][0]).toEqual('12345678');
             expect(retrieveSpy.mock.calls[0][1]).toEqual({
@@ -279,7 +279,7 @@ describe('monitoring-location/components/hydrograph/date-controls', () => {
             expect(getSelectedDateRange(store.getState())).toEqual('P7D');
             expect(getSelectedCustomDateRange(store.getState())).toBeNull();
             expect(clearBrushOffsetSpy).not.toHaveBeenCalled();
-            expect(loadingIndicatorSpy.mock.calls).toHaveLength(0);
+            expect(showDataIndicatorSpy.mock.calls).toHaveLength(0);
             expect(retrieveSpy).not.toHaveBeenCalled();
         });
 
@@ -295,7 +295,7 @@ describe('monitoring-location/components/hydrograph/date-controls', () => {
             expect(getSelectedDateRange(store.getState())).toEqual('P7D');
             expect(getSelectedCustomDateRange(store.getState())).toBeNull();
             expect(clearBrushOffsetSpy).not.toHaveBeenCalled();
-            expect(loadingIndicatorSpy.mock.calls).toHaveLength(0);
+            expect(showDataIndicatorSpy.mock.calls).toHaveLength(0);
             expect(retrieveSpy).not.toHaveBeenCalled();
         });
 
@@ -312,7 +312,7 @@ describe('monitoring-location/components/hydrograph/date-controls', () => {
             expect(getSelectedDateRange(store.getState())).toEqual('P7D');
             expect(getSelectedCustomDateRange(store.getState())).toBeNull();
             expect(clearBrushOffsetSpy).not.toHaveBeenCalled();
-            expect(loadingIndicatorSpy.mock.calls).toHaveLength(0);
+            expect(showDataIndicatorSpy.mock.calls).toHaveLength(0);
             expect(retrieveSpy).not.toHaveBeenCalled();
         });
     });
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.js b/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.js
index 9b353c93c..7ba60f0c9 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.js
@@ -14,7 +14,6 @@ import {isVisible} from './selectors/time-series-data';
 import {showDataIndicators} from './data-indicator';
 
 const hasIVData = function(parameterCode) {
-    console.log(`${config}`);
     return config.ivPeriodOfRecord && parameterCode in config.ivPeriodOfRecord;
 };
 
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.test.js
index 500e44b4c..527e982be 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.test.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.test.js
@@ -1,19 +1,23 @@
 import {select} from 'd3-selection';
 import sinon from 'sinon';
 
+import config from 'ui/config';
 import * as utils from 'ui/utils';
 
 import {configureStore} from 'ml/store';
 import * as hydrographData from 'ml/store/hydrograph-data';
 import {setSelectedDateRange} from 'ml/store/hydrograph-state';
 
+import * as dataIndicator from './data-indicator';
 import {drawGraphControls} from './graph-controls';
 import {TEST_CURRENT_TIME_RANGE} from './mock-hydrograph-state';
-import * as dataLoadingIndicator from "./data-loading-indicator";
 
 // Tests for the graph-controls module
 describe('monitoring-location/components/hydrograph/graph-controls', () => {
     utils.mediaQuery = jest.fn().mockReturnValue(true);
+    config.ivPeriodOfRecord = {
+        '72019': {}
+    };
 
     describe('drawGraphControls', () => {
 
@@ -21,7 +25,7 @@ describe('monitoring-location/components/hydrograph/graph-controls', () => {
         let fakeServer;
         let store;
         let retrievePriorYearSpy, retrieveMedianStatisticsSpy;
-        let loadingIndicatorSpy;
+        let showDataIndicatorSpy;
 
         beforeEach(() => {
             div = select('body').append('div');
@@ -39,7 +43,7 @@ describe('monitoring-location/components/hydrograph/graph-controls', () => {
             fakeServer = sinon.createFakeServer();
             retrievePriorYearSpy = jest.spyOn(hydrographData, 'retrievePriorYearIVData');
             retrieveMedianStatisticsSpy = jest.spyOn(hydrographData, 'retrieveMedianStatistics');
-            loadingIndicatorSpy = jest.spyOn(dataLoadingIndicator, 'showDataLoadingIndicator');
+            showDataIndicatorSpy = jest.spyOn(dataIndicator, 'showDataIndicators');
 
             drawGraphControls(div, store, '11112222');
         });
@@ -68,9 +72,11 @@ describe('monitoring-location/components/hydrograph/graph-controls', () => {
                 startTime: TEST_CURRENT_TIME_RANGE.start,
                 endTime: TEST_CURRENT_TIME_RANGE.end
             });
+            expect(showDataIndicatorSpy.mock.calls).toHaveLength(1);
+            expect(showDataIndicatorSpy.mock.calls[0][0]).toBe(true);
         });
 
-        it('Changing the compare visibility back to false should set the visibility but not retrieve the Prior year data', () => {
+        it('Changing the compare visibility back to false should set isLoading to false so that the no data available indicator can be set,  but not retrieve the Prior year data', () => {
             const checkbox = select('#last-year-checkbox');
             checkbox.property('checked', true);
             checkbox.dispatch('click');
@@ -79,6 +85,8 @@ describe('monitoring-location/components/hydrograph/graph-controls', () => {
             checkbox.dispatch('click');
             expect(store.getState().hydrographState.showCompareIVData).toBe(false);
             expect(retrievePriorYearSpy.mock.calls).toHaveLength(1);
+            expect(showDataIndicatorSpy.mock.calls).toHaveLength(2);
+            expect(showDataIndicatorSpy.mock.calls[1][0]).toBe(false);
         });
 
         it('Should change the checkbox to disabled if the selectedDateRange is set to custom', () => {
@@ -118,12 +126,12 @@ describe('monitoring-location/components/hydrograph/graph-controls', () => {
             checkbox.dispatch('click');
 
             expect(store.getState().hydrographState.showMedianData).toBe(true);
-            expect(loadingIndicatorSpy.mock.calls).toHaveLength(1);
-            expect(loadingIndicatorSpy.mock.calls[0][0]).toBe(true);
+            expect(showDataIndicatorSpy.mock.calls).toHaveLength(1);
+            expect(showDataIndicatorSpy.mock.calls[0][0]).toBe(true);
             expect(retrieveMedianStatisticsSpy).toHaveBeenCalledWith('11112222', '72019');
         });
 
-        it('Changing the median visibility back to false should set the visibility but not retrieve the median data', () => {
+        it('Changing the median visibility back to false should set isLoading to false to check for no data availability', () => {
             const checkbox = select('#median-checkbox');
             checkbox.property('checked', true);
             checkbox.dispatch('click');
@@ -131,8 +139,8 @@ describe('monitoring-location/components/hydrograph/graph-controls', () => {
             checkbox.property('checked', false);
             checkbox.dispatch('click');
             expect(store.getState().hydrographState.showMedianData).toBe(false);
-            expect(loadingIndicatorSpy.mock.calls).toHaveLength(1);
-            expect(loadingIndicatorSpy.mock.calls[0][0]).toBe(true);
+            expect(showDataIndicatorSpy.mock.calls).toHaveLength(2);
+            expect(showDataIndicatorSpy.mock.calls[1][0]).toBe(false);
             expect(retrieveMedianStatisticsSpy.mock.calls).toHaveLength(1);
         });
     });
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/index.js b/assets/src/scripts/monitoring-location/components/hydrograph/index.js
index 6c5e509a8..0f7a8c1a3 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/index.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/index.js
@@ -47,7 +47,7 @@ export const attachToNode = function(store,
                                      node,
                                      {
                                          siteno,
-                                         agencyCode,
+                                         agencyCd,
                                          sitename,
                                          parameterCode,
                                          compare,
@@ -115,7 +115,7 @@ export const attachToNode = function(store,
 
         showDataIndicators(false, store);
         let graphContainer = nodeElem.select('.graph-container');
-        graphContainer.call(drawTimeSeriesGraph, store, siteno, agencyCode, sitename, showMLName, !showOnlyGraph);
+        graphContainer.call(drawTimeSeriesGraph, store, siteno, agencyCd, sitename, showMLName, !showOnlyGraph);
 
         if (!showOnlyGraph) {
             graphContainer
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js
index a784d7f34..f4e38842e 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js
@@ -121,13 +121,13 @@ describe('monitoring-location/components/hydrograph module', () => {
                     period: 'P7D',
                     startTime: null,
                     endTime: null,
-                    loadCompare: undefined,
+                    loadCompare: false,
                     loadMedian: false
                 });
                 expect(store.getState().hydrographState).toEqual({
                     selectedParameterCode: '72019',
                     selectedDateRange: 'P7D',
-                    showCompareIVData: undefined,
+                    showCompareIVData: false,
                     selectedIVMethodID: undefined
                 });
             });
@@ -142,13 +142,13 @@ describe('monitoring-location/components/hydrograph module', () => {
                     period: 'P45D',
                     startTime: null,
                     endTime: null,
-                    loadCompare: undefined,
+                    loadCompare: false,
                     loadMedian: false
                 });
                 expect(store.getState().hydrographState).toEqual({
                     selectedParameterCode: '72019',
                     selectedDateRange: 'P45D',
-                    showCompareIVData: undefined,
+                    showCompareIVData: false,
                     selectedIVMethodID: undefined
                 });
             });
@@ -164,7 +164,7 @@ describe('monitoring-location/components/hydrograph module', () => {
                     period: null,
                     startTime: '2020-02-01T00:00:00.000-06:00',
                     endTime: '2020-02-15T23:59:59.999-06:00',
-                    loadCompare: undefined,
+                    loadCompare: false,
                     loadMedian: false
                 });
                 expect(store.getState().hydrographState).toEqual({
@@ -174,7 +174,7 @@ describe('monitoring-location/components/hydrograph module', () => {
                         start: '2020-02-01',
                         end: '2020-02-15'
                     },
-                    showCompareIVData: undefined,
+                    showCompareIVData: false,
                     selectedIVMethodID: undefined
                 });
             });
@@ -222,7 +222,7 @@ describe('monitoring-location/components/hydrograph module', () => {
                 period: 'P7D',
                 startTime: null,
                 endTime: null,
-                loadCompare: undefined,
+                loadCompare: false,
                 loadMedian: false
             });
             expect(store.getState().hydrographState).toEqual({});
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/legend.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/legend.test.js
index 570d3a250..6e5fc30b6 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/legend.test.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/legend.test.js
@@ -1,5 +1,6 @@
 import {select, selectAll} from 'd3-selection';
 
+import config from 'ui/config';
 import * as utils from 'ui/utils';
 
 import {configureStore} from 'ml/store';
@@ -9,13 +10,20 @@ import {TEST_PRIMARY_IV_DATA, TEST_GW_LEVELS} from './mock-hydrograph-state';
 
 describe('monitoring-location/components/hydrograph/legend module', () => {
     utils.mediaQuery = jest.fn().mockReturnValue(true);
-
+    config.ivPeriodOfRecord = {
+        '72019': {}
+    };
+    config.gwPeriodOfRecord = {
+        '72019': {}
+    };
     const TEST_STATE = {
         hydrographData: {
             primaryIVData: TEST_PRIMARY_IV_DATA,
             groundwaterLevels: TEST_GW_LEVELS
         },
         hydrographState: {
+            showCompareIVData: false,
+            showMedianData: false,
             selectedIVMethodID: '90649'
         }
     };
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/method-picker.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/method-picker.test.js
index 61fe74a17..0f454fb24 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/method-picker.test.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/method-picker.test.js
@@ -1,11 +1,15 @@
 import {select} from 'd3-selection';
 
+import * as utils from 'ui/utils';
+
 import {configureStore} from 'ml/store';
 
+import * as dataIndicator from './data-indicator';
 import {drawMethodPicker} from './method-picker';
 import {TEST_PRIMARY_IV_DATA} from './mock-hydrograph-state';
 
 describe('monitoring-location/components/hydrograph/method-picker', () => {
+    utils.mediaQuery = jest.fn().mockReturnValue(true);
 
     describe('drawMethodPicker', () => {
         const TEST_STATE = {
@@ -17,8 +21,10 @@ describe('monitoring-location/components/hydrograph/method-picker', () => {
             }
         };
         let div;
+        let showDataIndicatorSpy;
         beforeEach(() => {
             div = select('body').append('div');
+            showDataIndicatorSpy = jest.spyOn(dataIndicator, 'showDataIndicators');
         });
 
         afterEach(() => {
@@ -47,7 +53,7 @@ describe('monitoring-location/components/hydrograph/method-picker', () => {
             expect(div.select('select').property('value')).toEqual('90649');
         });
 
-        it('selecting a different method updates the store', () => {
+        it('selecting a different method updates the store and updates the no data available indicator', () => {
             let store = configureStore(TEST_STATE);
             div.call(drawMethodPicker, store);
 
@@ -57,6 +63,8 @@ describe('monitoring-location/components/hydrograph/method-picker', () => {
             div.select('select').dispatch('change');
 
             expect(store.getState().hydrographState.selectedIVMethodID).toBe('90649');
+            expect(showDataIndicatorSpy.mock.calls).toHaveLength(1);
+            expect(showDataIndicatorSpy.mock.calls[0][0]).toBe(false);
         });
 
         it('Expects if the data has only one method then the picker will be hidden', () => {
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/parameters.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/parameters.test.js
index ba27f8697..54019e27e 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/parameters.test.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/parameters.test.js
@@ -6,9 +6,9 @@ import * as utils from 'ui/utils';
 import {configureStore} from 'ml/store';
 import * as hydrographData from 'ml/store/hydrograph-data';
 
+import * as dataIndicator from './data-indicator';
 import {TEST_HYDROGRAPH_PARAMETERS} from './mock-hydrograph-state';
 import {drawSelectionTable} from './parameters';
-import * as dataLoadingIndicator from "./data-loading-indicator";
 
 describe('monitoring-location/components/hydrograph/parameters module', () => {
     utils.mediaQuery = jest.fn().mockReturnValue(true);
@@ -25,13 +25,13 @@ describe('monitoring-location/components/hydrograph/parameters module', () => {
     let fakeServer;
     let store;
     let retrieveHydrographDataSpy;
-    let loadingIndicatorSpy;
+    let showDataIndicatorSpy;
 
     beforeEach(() => {
         div = select('body').append('div');
         fakeServer = sinon.createFakeServer();
         retrieveHydrographDataSpy = jest.spyOn(hydrographData, 'retrieveHydrographData');
-        loadingIndicatorSpy = jest.spyOn(dataLoadingIndicator, 'showDataLoadingIndicator');
+        showDataIndicatorSpy = jest.spyOn(dataIndicator, 'showDataIndicators');
     });
 
     afterEach(() => {
@@ -67,8 +67,8 @@ describe('monitoring-location/components/hydrograph/parameters module', () => {
         rowOne.dispatch('click');
 
         expect(store.getState().hydrographState.selectedParameterCode).toEqual('00060');
-        expect(loadingIndicatorSpy.mock.calls).toHaveLength(1);
-        expect(loadingIndicatorSpy.mock.calls[0][0]).toBe(true);
+        expect(showDataIndicatorSpy.mock.calls).toHaveLength(1);
+        expect(showDataIndicatorSpy.mock.calls[0][0]).toBe(true);
         expect(retrieveHydrographDataSpy).toHaveBeenCalledWith('11112222', {
             parameterCode: '00060',
             period: 'P7D',
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/iv-data.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/iv-data.js
index 950f10da9..bbd3c04b9 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/iv-data.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/iv-data.js
@@ -65,7 +65,7 @@ const transformToCumulative = function(points) {
 
 /*
  * Returns a selector function that returns an Array of Objects that can be used to visualize the
- * IV data.
+ * IV data. If no data of dataKind has been fetched at all, return null.
  * Each object has the following properties:
  *      @prop {Number} value
  *      @prop {Number} dateTime - in epoch milliseconds
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/iv-data.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/iv-data.test.js
index 8a58bd70c..40c47bc1d 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/iv-data.test.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/iv-data.test.js
@@ -37,8 +37,23 @@ describe('monitoring-location/components/hydrograph/selectors/iv-data', () => {
     };
 
     describe('getIVDataPoints', () => {
-        it('Returns an empty array if  no data of data kind exists', () => {
-            expect(getIVDataPoints('compare')(TEST_STATE)).toHaveLength(0);
+        it('Returns null if no data of data kind exists', () => {
+            expect(getIVDataPoints('compare')(TEST_STATE)).toBeNull();
+        });
+
+        it('Returns an empty array if no data points exist for data kind', () => {
+            expect(getIVDataPoints('compare')({
+                ...TEST_STATE,
+                hydrographData: {
+                    ...TEST_STATE.hydrographData,
+                    compareIVData: {
+                        parameter: {
+                            parameterCode: '72019'
+                        },
+                        values: {}
+                    }
+                }
+            })).toHaveLength(0);
         });
 
         it('Returns the iv data points with the correct properties', () => {
@@ -123,8 +138,23 @@ describe('monitoring-location/components/hydrograph/selectors/iv-data', () => {
         });
     });
     describe('getIVDataSegments', () => {
-       it('Expects an empty array if no IV of the data kind exists', () => {
-           expect(getIVDataSegments('compare')(TEST_STATE)).toHaveLength(0);
+       it('Expects null if no IV of the data kind exists', () => {
+           expect(getIVDataSegments('compare')(TEST_STATE)).toBeNull();
+       });
+
+       it('Expects an empty array if IV of data kind exists but there are no points', () => {
+           expect(getIVDataSegments('compare')({
+                ...TEST_STATE,
+                hydrographData: {
+                    ...TEST_STATE.hydrographData,
+                    compareIVData: {
+                        parameter: {
+                            parameterCode: '72019'
+                        },
+                        values: {}
+                    }
+                }
+            })).toHaveLength(0);
        });
 
        it('Returns the expected data segments', () => {
@@ -179,8 +209,23 @@ describe('monitoring-location/components/hydrograph/selectors/iv-data', () => {
     });
 
     describe('getIVUniqueDataKinds', () => {
-        it('returns an empty array if no IV data of data kind exists', () => {
-            expect(getIVUniqueDataKinds('compare')(TEST_STATE)).toHaveLength(0);
+        it('returns null if no IV data of data kind exists', () => {
+            expect(getIVUniqueDataKinds('compare')(TEST_STATE)).toBeNull();
+        });
+
+        it('returns an empty array if IV data of dataKind exists but has no points', () => {
+            expect(getIVUniqueDataKinds('compare')({
+                ...TEST_STATE,
+                hydrographData: {
+                    ...TEST_STATE.hydrographData,
+                    compareIVData: {
+                        parameter: {
+                            parameterCode: '72019'
+                        },
+                        values: {}
+                    }
+                }
+            })).toHaveLength(0);
         });
 
         it('Returns expected unique data kind for the IV data', () => {
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.js
index 1ad5abf85..663e9227f 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.js
@@ -154,7 +154,6 @@ export const getLegendMarkerRows = createSelector(
     getLegendDisplay,
     displayItems => {
         const markerRows = [];
-
         const currentTsMarkerRow = displayItems.primaryIV ? getIVMarkers('primary', displayItems.primaryIV) : undefined;
         const compareTsMarkerRow = displayItems.compareIV ? getIVMarkers('compare', displayItems.compareIV) : undefined;
         const medianMarkerRows = displayItems.median ? getMedianMarkers(displayItems.median) : [];
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.test.js
index 32994c5de..8049b989f 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.test.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.test.js
@@ -1,8 +1,16 @@
+
+import config from 'ui/config';
 import {lineMarker, rectangleMarker, textOnlyMarker, circleMarker} from 'd3render/markers';
 
 import {getLegendMarkerRows} from './legend-data';
 
 describe('monitoring-location/components/hydrograph/selectors/legend-data', () => {
+    config.ivPeriodOfRecord = {
+        '72019': {}
+    };
+    config.gwPeriodOfRecord = {
+        '72019': {}
+    };
     const TEST_PRIMARY_IV_DATA = {
         parameter: {
             parameterCode: '72019'
@@ -107,5 +115,30 @@ describe('monitoring-location/components/hydrograph/selectors/legend-data', () =
             expect(compareRow[1].type).toEqual(lineMarker);
             expect(compareRow[2].type).toEqual(lineMarker);
         });
+
+        it('Should return a no data marker for compare if compare data has no points', () => {
+            const markerRows = getLegendMarkerRows({
+                ...TEST_STATE,
+                hydrographData: {
+                    ...TEST_STATE.hydrographData,
+                    compareIVData: {
+                        parameter: {
+                            parameterCode: '72019'
+                        },
+                        values: {}
+                    }
+                },
+                hydrographState: {
+                    ...TEST_STATE.hydrographState,
+                    showCompareIVData: true
+                }
+            });
+
+            expect(markerRows).toHaveLength(3);
+            const compareRow = markerRows[2];
+            expect(compareRow).toHaveLength(2);
+            expect(compareRow[0].type).toEqual(textOnlyMarker);
+            expect(compareRow[1].type).toEqual(textOnlyMarker);
+        });
     });
 });
\ No newline at end of file
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.js
index 1c70f6ce3..6f2c0dfd6 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.js
@@ -61,6 +61,11 @@ const hasVisibleGroundwaterLevels = createSelector(
     (gwLevels) => gwLevels && gwLevels.values ? gwLevels.values.length > 0 : false
 );
 
+/*
+ * Returns a selector function which returns true if there is any data that will be visible
+ * on the hydrograph.
+ * @return {Function}
+ */
 export const hasAnyVisibleData = createSelector(
     hasVisibleIVData('primary'),
     hasVisibleIVData('compare'),
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.test.js
index 7d4d27100..d1f02b029 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.test.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.test.js
@@ -1,8 +1,8 @@
 import config from 'ui/config';
 
+import {TEST_PRIMARY_IV_DATA, TEST_MEDIAN_DATA, TEST_GW_LEVELS} from '../mock-hydrograph-state';
 import {
-    isVisible, hasVisibleIVData, hasVisibleMedianStatisticisData, hasVisibleGroundwaterLevels,
-    hasAnyVisibleData, getTitle, getDescription, getPrimaryParameterUnitCode,
+    isVisible, hasAnyVisibleData, getTitle, getDescription, getPrimaryParameterUnitCode,
     getPreferredIVMethodID
 }
     from './time-series-data';
@@ -70,56 +70,97 @@ describe('monitoring-location/components/hydrograph/time-series module', () => {
         });
     });
 
-    describe('hasVisibleIVData', () => {
+    describe('hasVisibleData', () => {
         it('Expects to return true when data is available and visible', () => {
-            expect(hasVisibleIVData('primary')(TEST_STATE)).toBe(true);
-            expect(hasVisibleIVData('compare')({
-                ...TEST_STATE,
+            expect(hasAnyVisibleData({
                 hydrographData: {
-                    ...TEST_STATE.hydrographData,
-                    compareIVData: {
-                        ...TEST_STATE.hydrographData.primaryIVData
-                    }
+                    primaryIVData: TEST_PRIMARY_IV_DATA
                 },
                 hydrographState: {
-                    ...TEST_STATE.hydrographState,
-                    showCompareIVData: true
+                    showCompareIVData: false,
+                    showMedianData: true,
+                    selectedIVMethodID: '90649'
+                }
+            })).toBe(true);
+            expect(hasAnyVisibleData({
+                hydrographData: {
+                    groundwaterLevels: TEST_GW_LEVELS
+                },
+                hydrographState: {
+                    showCompareIVData: false,
+                    showMedianData: true
+                }
+            })).toBe(true);
+            expect(hasAnyVisibleData({
+                hydrographData: {
+                    medianStatisticsData: TEST_MEDIAN_DATA
+                },
+                hydrographState: {
+                    showCompareIVData: false,
+                    showMedianData: true
                 }
             })).toBe(true);
         });
 
-        it('Expects to return false if data exists but is not visible', () => {
-            expect(hasVisibleIVData('compare')({
-                ...TEST_STATE,
+        it('Expects to return false when no data is available', () => {
+            expect(hasAnyVisibleData({
                 hydrographData: {
-                    ...TEST_STATE.hydrographData,
-                    compareIVData: {
-                        ...TEST_STATE.hydrographData.primaryIVData
+                    primaryIVData: {
+                        parameter: {
+                            parameterCode: '72019'
+                        },
+                        values: {}
                     }
+                },
+                hydrographState: {
+                    showCompareIVData: false,
+                    showMedianData: true
+                }
+            })).toBe(false);
+
+            expect(hasAnyVisibleData({
+                hydrographData: {
+                    primaryIVData: {
+                        parameter: {
+                            parameterCode: '72019'
+                        },
+                        values: {
+                            '90649': {
+                                points: [],
+                                method: {
+                                    methodID: '90649'
+                                }
+                            }
+                        }
+                    }
+                },
+                hydrographState: {
+                    showCompareIVData: false,
+                    showMedianData: true,
+                    selectedIVMethodID: '90649'
+
                 }
             })).toBe(false);
         });
 
-        it('Expects to return false when no data is available and visible', () => {
-            expect(hasVisibleIVData('primary')({
-                ...TEST_STATE,
+        it('Expects to return false if data is available but not available', () => {
+            expect(hasAnyVisibleData({
+                hydrographData: {
+                    primaryIVData: TEST_PRIMARY_IV_DATA
+                },
                 hydrographState: {
-                    ...TEST_STATE.hydrographState,
-                    selectedIVMethodID: '69937'
+                    showCompareIVData: false,
+                    showMedianData: true,
+                    selectedIVMethodID: '252055'
                 }
             })).toBe(false);
-            expect(hasVisibleIVData('compare')({
-                ...TEST_STATE,
+            expect(hasAnyVisibleData({
                 hydrographData: {
-                    ...TEST_STATE.hydrographData,
-                    compareIVData: {
-                        ...TEST_STATE.hydrographData.primaryIVData
-                    }
+                    medianStatisticsData: TEST_MEDIAN_DATA
                 },
                 hydrographState: {
-                    ...TEST_STATE.hydrographState,
-                    selectedIVMethodID: '69937',
-                    showCompareIVData: true
+                    showCompareIVData: false,
+                    showMedianData: false
                 }
             })).toBe(false);
         });
-- 
GitLab