diff --git a/assets/src/scripts/mock-service-data.js b/assets/src/scripts/mock-service-data.js index e165697907f37b6ca447c59486852b0af2df7699..cdc5a87de5490df048fb0fb90e3c93d611a66bf6 100644 --- a/assets/src/scripts/mock-service-data.js +++ b/assets/src/scripts/mock-service-data.js @@ -254,6 +254,54 @@ USGS 05370000 00010 153885 1 12 1969 2017 49 15 USGS 05370000 00010 153885 1 13 1969 2017 49 15 `; +export const MOCK_STATISTICS_RDB_ALT = `# +# +# US Geological Survey, Water Resources Data +# retrieved: 2018-01-25 16:05:49 -05:00 (natwebsdas01) +# +# This file contains USGS Daily Statistics +# +# Note:The statistics generated are based on approved daily-mean data and may not match those published by the USGS in official publications. +# The user is responsible for assessment and use of statistics from this site. +# For more details on why the statistics may not match, visit http://help.waterdata.usgs.gov/faq/about-statistics. +# +# Data heading explanations. +# agency_cd -- agency code +# site_no -- Site identification number +# parameter_cd -- Parameter code +# station_nm -- Site name +# loc_web_ds -- Additional measurement description +# +# Data for the following 1 site(s) are contained in this file +# agency_cd site_no parameter_cd station_nm (loc_web_ds) +# USGS 05370000 00060 EAU GALLE RIVER AT SPRING VALLEY, WI +# +# Explanation of Parameter Codes +# parameter_cd Parameter Name +# 00060 Discharge, cubic feet per second +# +# Data heading explanations. +# month_nu ... The month for which the statistics apply. +# day_nu ... The day for which the statistics apply. +# begin_yr ... First water year of data of daily mean values for this day. +# end_yr ... Last water year of data of daily mean values for this day. +# count_nu ... Number of values used in the calculation. +# p50_va ... 50 percentile (median) of daily mean values for this day. +# +agency_cd site_no parameter_cd ts_id loc_web_ds month_nu day_nu begin_yr end_yr count_nu max_va_yr max_va min_va_yr min_va mean_va p05_va p10_va p20_va p25_va p50_va p75_va p80_va p90_va p95_va +5s 15s 5s 10n 15s 3n 3n 6n 6n 8n 12s +USGS 05370000 00010 153884 1 1 1979 2021 19 1980 3.9 2018 1.2 2.2 1.2 1.3 1.6 1.7 2.1 3 3 3 3.9 +USGS 05370000 00010 153884 1 2 1979 2021 19 1980 3.5 2018 1.3 2.2 1.3 1.5 1.8 1.8 1.9 2.9 2.9 3 3.5 +USGS 05370000 00010 153884 1 3 1979 2021 19 1980 3.7 2018 1.2 2.3 1.2 1.4 1.5 1.6 2 2.9 3 3 3.7 +USGS 05370000 00010 153884 1 4 1979 2021 19 1980 3.9 2018 1.2 2.2 1.2 1.3 1.4 1.6 2.2 3 3 3 3.9 +USGS 05370000 00010 153884 1 5 1979 2021 19 1980 3.9 2014 1.2 2.2 1.2 1.2 1.4 1.5 2.2 3 3 3.1 3.9 +USGS 05370000 00010 153884 1 6 1979 2021 19 2012 3.2 2014 1.2 2.2 1.2 1.2 1.5 1.5 2.2 2.9 3 3.1 3.2 +USGS 05370000 00010 153884 1 7 1979 2021 19 1987 3.0 1982 1.3 2.1 1.3 1.3 1.4 1.5 2.2 2.7 2.8 2.9 3 +USGS 05370000 00010 153884 1 8 1979 2021 19 1980 3.1 1982 1.4 2.2 1.4 1.4 1.6 1.6 2.2 2.7 2.9 3 3.1 +USGS 05370000 00010 153884 1 9 1979 2021 19 2012 3.2 1982 1.3 2.3 1.3 1.4 1.7 1.7 2.2 2.9 3 3 3.2 +USGS 05370000 00010 153884 1 10 1979 2021 19 2012 3.2 1982 1.3 2.3 1.3 1.5 1.6 1.8 2.2 2.9 3 3.1 3.2 +`; + export const MOCK_IV_DATA = ` {"name" : "ns1:timeSeriesResponseType", "declaredType" : "org.cuahsi.waterml.TimeSeriesResponseType", 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 b565008e9138340642da2b549d4938df1dc91ce9..97abc9d76468da64f5fafb66ce1b15bb20f96f23 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js @@ -5,6 +5,7 @@ import mockConsole from 'jest-mock-console'; import * as utils from 'ui/utils'; import config from 'ui/config'; +import * as d3Redux from 'ui/lib/d3-redux'; import {configureStore} from 'ml/store'; import {Actions as floodDataActions} from 'ml/store/flood-data'; @@ -66,6 +67,8 @@ describe('monitoring-location/components/hydrograph module', () => { let restoreConsole; + let linkSpy; + beforeAll(() => { enableFetchMocks(); restoreConsole = mockConsole(); @@ -92,6 +95,7 @@ describe('monitoring-location/components/hydrograph module', () => { component.append('div').attr('class', 'select-actions-container'); component.append('div').attr('class', 'select-time-series-container'); component.append('div').attr('id', 'iv-data-table-container'); + component.append('div').attr('id', 'stats-container'); graphNode = document.getElementById('hydrograph'); nodeElem = select(graphNode); @@ -287,6 +291,7 @@ describe('monitoring-location/components/hydrograph module', () => { return Promise.resolve(); }; }); + linkSpy = jest.spyOn(d3Redux, 'link'); attachToNode(store, graphNode, { ...INITIAL_PARAMETERS, showOnlyGraph: false @@ -357,6 +362,11 @@ describe('monitoring-location/components/hydrograph module', () => { expect(select('#iv-hydrograph-data-table-container').size()).toBe(1); expect(select('#gw-hydrograph-data-table-container').size()).toBe(1); }); + + it('expects to create a d3redux link for the daily statistics section', () => { + expect(linkSpy).toHaveBeenCalled(); + expect(linkSpy.mock.lastCall.toString()).toContain('daily-stats-container'); + }); }); describe('Tests for rendering once fetching is complete when showOnlyGraph is true', () => { @@ -399,6 +409,7 @@ describe('monitoring-location/components/hydrograph module', () => { return Promise.resolve(); }; }); + linkSpy = jest.spyOn(d3Redux, 'link'); attachToNode(store, graphNode, { ...INITIAL_PARAMETERS, showOnlyGraph: true @@ -466,5 +477,9 @@ describe('monitoring-location/components/hydrograph module', () => { expect(select('#iv-hydrograph-data-table-container').size()).toBe(0); expect(select('#gw-hydrograph-data-table-container').size()).toBe(0); }); + + it('expects to not create a d3redux link for the daily statistics section', () => { + expect(linkSpy.mock.lastCall.toString()).not.toContain('daily-stats-container'); + }); }); }); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/statistics.js b/assets/src/scripts/monitoring-location/components/hydrograph/statistics.js index 83fd68b7a8c2d010527b5533548cbeeca649c7db..2b39e53a2b4bbe7d4aaf26a44fdb8efa050575d5 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/statistics.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/statistics.js @@ -1,7 +1,6 @@ import {select} from 'd3-selection'; import {fetchSitesStatisticsRDB} from 'ui/web-services/statistics-data'; -import {getSelectedParameterCode} from 'ml/selectors/hydrograph-state-selector'; import {parseRDB} from 'ui/utils'; @@ -37,7 +36,6 @@ const drawStats = function(elem, currentData, name) { const table = tableContainer.append('table') .classed('usa-table', true) .classed('usa-table--stacked', true); - // .classed('usa-table--borderless', true); table.append('caption') .text(`Daily ${name.replace('³','³')} for ${new Date().toDateString()} based on ${currentData[1]['count_nu']} diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/statistics.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/statistics.test.js new file mode 100644 index 0000000000000000000000000000000000000000..7d422f8ef9029d49237d061bdf3eae5f5b0ee6b4 --- /dev/null +++ b/assets/src/scripts/monitoring-location/components/hydrograph/statistics.test.js @@ -0,0 +1,38 @@ +import {select} from 'd3-selection'; + +import config from 'ui/config'; + +import {configureStore} from 'ml/store'; + +import {drawStatsTable} from './statistics'; +import {TEST_PRIMARY_IV_DATA} from './mock-hydrograph-state'; +import {MOCK_STATISTICS_RDB_ALT} from 'ui/mock-service-data'; + +describe('monitoring-location/components/hydrograph/statistics', () => { + let testDiv; + let store; + + + beforeEach(() => { + testDiv = select('body').append('div'); + }); + + afterEach(() => { + testDiv.remove(); + }); + + it('Shows stats table with expected data', () => { + fetch.once(MOCK_STATISTICS_RDB_ALT, {status: 200}); + store = configureStore({ + hydrographData: { + currentTimeRange: { + start: 1582560000000, + end: 1600620000000 + }, + primaryIVData: TEST_PRIMARY_IV_DATA + } + }); + drawStatsTable(testDiv, {primaryIVData: store.getState().hydrographData.primaryIVData, siteno: '05428500'}); + + }); +});