diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/download-links.js b/assets/src/scripts/monitoring-location/components/hydrograph/download-links.js index f1d908e65ee13a6467ed79fe0c548425391216cc..db0ea8c84a5cc0888c393b55daf0af858feb6825 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/download-links.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/download-links.js @@ -7,7 +7,7 @@ import {DateTime} from 'luxon'; import {createStructuredSelector} from 'reselect'; import config from 'ui/config.js'; -import{link} from 'ui/lib/d3-redux'; +import {link} from 'ui/lib/d3-redux'; import {getIVServiceURL, getSiteMetaDataServiceURL} from 'ui/web-services/instantaneous-values'; import {getStatisticsServiceURL} from 'ui/web-services/statistics-data'; import {getGroundwaterServiceURL} from 'ui/web-services/groundwater-levels'; @@ -29,8 +29,8 @@ const getIVDataURL = function(store, siteno, timeRangeKind) { return getIVServiceURL({ siteno, parameterCode: getPrimaryParameter(currentState).parameterCode, - startDT: toISO(timeRange.start), - endDT: toISO(timeRange.end), + startTime: toISO(timeRange.start), + endTime: toISO(timeRange.end), format: 'rdb' }); }; @@ -102,6 +102,13 @@ const drawCheckboxes = function(container, { checkboxContainer.call(drawCheckbox, 'download-site-meta-data', 'About this location', 'site'); }; +/* + * Render the download form and set up all appropriate even handlers. The checkboxes drawn are tied to what data is currently + * visible on the hydrograph. + * @param {D3 selection} container + * @param {Redux store} store + * @param {String} siteno + */ export const drawDownloadForm = function(container, store, siteno) { const formContainer = container.append('form') .attr('class', 'usa-form') diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/download-links.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/download-links.test.js index 72ff852edd6fd905607fffcf3103afd2ff6da1fb..67b64fe1ab0b5357c80c744d8599473d9b0c9d54 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/download-links.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/download-links.test.js @@ -1,402 +1,131 @@ import {select} from 'd3-selection'; import config from 'ui/config'; + import {configureStore} from 'ml/store'; -import {drawDownloadLinks} from 'ivhydrograph/download-links'; +import {setCompareDataVisibility, setMedianDataVisibility, setSelectedIVMethodID} from 'ml/store/hydrograph-state'; + +import {drawDownloadForm} from './download-links'; +import {TEST_CURRENT_TIME_RANGE, TEST_PRIMARY_IV_DATA, TEST_MEDIAN_DATA, TEST_GW_LEVELS} from './mock-hydrograph-state'; describe('monitoring-location/components/hydrograph/download-links', () => { config.SERVICE_ROOT = 'https://fakeserviceroot.com'; config.PAST_SERVICE_ROOT = 'https://fakeserviceroot-more-than-120-days.com'; - config.GROUNDWATER_LEVELS_ENDPOINT = 'https://fakegroundwater.org/gw/'; - config.ivPeriodOfRecord = { - '00060': { - begin_date: '2000-01-01', - end_date: '2020-01-01' - }, - '00010': { - begin_date: '2000-01-01', - end_date: '2020-01-01' - } - }; - config.gwPeriodOfRecord = { - '72019': { - begin_date: '2000-01-01', - end_date: '2020-01-01' - } - }; + config.GROUNDWATER_LEVELS_ENDPOINT = 'https://fakegroundwater.org/gwlevels/'; config.locationTimeZone = 'America/Chicago'; - const TEST_STATE_BASE = { - 'hydrographData': { - 'currentTimeRange': { - 'start': 1614272067139, - 'end': 1614876867139 - }, - 'prioryearTimeRange': { - 'start': 1582736067139, - 'end': 1583340867139 - }, - 'medianStatisticsData': { - }, - 'primaryIVData': { - 'parameter': {}, - 'values':{'69928': {'points': [{},{}]}} - }, - 'compareIVData': {} + const TEST_STATE = { + hydrographData: { + currentTimeRange: TEST_CURRENT_TIME_RANGE, + prioryearTimeRange: TEST_CURRENT_TIME_RANGE, + primaryIVData: TEST_PRIMARY_IV_DATA, + compareIVData: TEST_PRIMARY_IV_DATA, + medianStatisticsData: TEST_MEDIAN_DATA, + groundwaterLevels: TEST_GW_LEVELS }, - 'hydrographState': { - 'showCompareIVData': false, - 'showMedianData': false, - 'selectedDateRange': 'P7D', - 'selectedParameterCode': '00060' + hydrographState: { + showCompareIVData: false, + showMedianData: false, + selectedIVMethodID: '90649' } }; - describe('drawDownloadLinks', () => { + describe('drawDownloadForm', () => { let div; + let store; + let windowSpy; beforeEach(() => { div = select('body').append('div'); + store = configureStore(TEST_STATE); + windowSpy = jest.spyOn(window, 'open').mockImplementation(() => null); + drawDownloadForm(div, store, '11112222'); }); afterEach(() => { div.remove(); }); - it('creates an unordered list and the correct number of list items and hyperlinks when only current time series is showing', () => { - let store = configureStore(TEST_STATE_BASE); - const siteNumber = '05370000'; - div.call(drawDownloadLinks, store, siteNumber); - return new Promise(resolve => { - window.requestAnimationFrame(() => { - expect(div.selectAll('ul').size()).toBe(1); - expect(div.selectAll('li').size()).toBe(2); - expect(div.selectAll('a').size()).toBe(3); - const anchorSelection = div.selectAll('a'); - const anchorElements = anchorSelection.nodes(); - - expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=05370000¶meterCd=00060&startDT=2021-02-25T10:54:27.139-06:00&endDT=2021-03-04T10:54:27.139-06:00&siteStatus=all&format=rdb'); - expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); - expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); - - resolve(); - }); - }); - }); - - it('creates an unordered list and the correct number of list items and hyperlinks when compare is selected', () => { - const TEST_STATE = { - 'hydrographData': { - ...TEST_STATE_BASE.hydrographData, - 'compareIVData': { - 'parameter': {}, - 'values':{'69928': {'points': [{},{}]}} - } - }, - 'hydrographState': { - ...TEST_STATE_BASE.hydrographState, - 'showCompareIVData': true - } - }; - let store = configureStore(TEST_STATE); - const siteNumber = '05370000'; - div.call(drawDownloadLinks, store, siteNumber); - return new Promise(resolve => { - window.requestAnimationFrame(() => { - expect(div.selectAll('ul').size()).toBe(1); - expect(div.selectAll('li').size()).toBe(3); - expect(div.selectAll('a').size()).toBe(4); - const anchorSelection = div.selectAll('a'); - const anchorElements = anchorSelection.nodes(); - - expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=05370000¶meterCd=00060&startDT=2021-02-25T10:54:27.139-06:00&endDT=2021-03-04T10:54:27.139-06:00&siteStatus=all&format=rdb'); - expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot-more-than-120-days.com/iv/?sites=05370000¶meterCd=00060&startDT=2020-02-26T10:54:27.139-06:00&endDT=2020-03-04T10:54:27.139-06:00&siteStatus=all&format=rdb'); - expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); - expect(anchorElements[3].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); - - resolve(); - }); - }); - }); - - it('creates an unordered list and the correct number of list items and hyperlinks when median is selected', () => { - const TEST_STATE = { - 'hydrographData': { - ...TEST_STATE_BASE.hydrographData, - 'medianStatisticsData': { - '69928': [{}] - }, - 'compareIVData': { - 'parameter': {}, - 'values':{'69928': {'points': [{},{}]}} - } - }, - 'hydrographState': { - ...TEST_STATE_BASE.hydrographState, - 'showCompareIVData': false, - 'showMedianData': true - } - }; - let store = configureStore(TEST_STATE); - const siteNumber = '05370000'; - div.call(drawDownloadLinks, store, siteNumber); - return new Promise(resolve => { - window.requestAnimationFrame(() => { - expect(div.selectAll('ul').size()).toBe(1); - expect(div.selectAll('li').size()).toBe(3); - expect(div.selectAll('a').size()).toBe(4); - const anchorSelection = div.selectAll('a'); - const anchorElements = anchorSelection.nodes(); - - expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=05370000¶meterCd=00060&startDT=2021-02-25T10:54:27.139-06:00&endDT=2021-03-04T10:54:27.139-06:00&siteStatus=all&format=rdb'); - expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/stat/?sites=05370000&statReportType=daily&statTypeCd=median¶meterCd=00060&format=rdb'); - expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); - expect(anchorElements[3].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); - - resolve(); - }); - }); + it('Renders form with the appropriate checkboxes and download button', () => { + expect(div.selectAll('input[type="checkbox"]').size()).toBe(3); + expect(div.selectAll('input[value="primary"]').size()).toBe(1); + expect(div.selectAll('input[value="groundwater-levels"]').size()).toBe(1); + expect(div.selectAll('input[value="site"]').size()).toBe(1); + expect(div.selectAll('button.download-selected-data').size()).toBe(1); }); - it('creates an unordered list and the correct number of list items and hyperlinks when both median and compare are selected', () => { - const TEST_STATE = { - 'hydrographData': { - ...TEST_STATE_BASE.hydrographData, - 'prioryearTimeRange': { - 'start': 1582736067139, - 'end': 1583340867139 - }, - 'medianStatisticsData': { - '69928': [{}] - }, - - 'compareIVData': { - 'parameter': {}, - 'values':{'69928': {'points': [{},{}]}} - } - }, - 'hydrographState': { - ...TEST_STATE_BASE.hydrographState, - 'showCompareIVData': true, - 'showMedianData': true - } - }; - let store = configureStore(TEST_STATE); - const siteNumber = '05370000'; - div.call(drawDownloadLinks, store, siteNumber); + it('Rerenders the checkboxes if data visibility changes', () => { + store.dispatch(setCompareDataVisibility(true)); + store.dispatch(setMedianDataVisibility(true)); return new Promise(resolve => { window.requestAnimationFrame(() => { - expect(div.selectAll('ul').size()).toBe(1); - expect(div.selectAll('li').size()).toBe(4); - expect(div.selectAll('a').size()).toBe(5); - const anchorSelection = div.selectAll('a'); - const anchorElements = anchorSelection.nodes(); - - expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=05370000¶meterCd=00060&startDT=2021-02-25T10:54:27.139-06:00&endDT=2021-03-04T10:54:27.139-06:00&siteStatus=all&format=rdb'); - expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot-more-than-120-days.com/iv/?sites=05370000¶meterCd=00060&startDT=2020-02-26T10:54:27.139-06:00&endDT=2020-03-04T10:54:27.139-06:00&siteStatus=all&format=rdb'); - expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/stat/?sites=05370000&statReportType=daily&statTypeCd=median¶meterCd=00060&format=rdb'); - expect(anchorElements[3].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); - expect(anchorElements[4].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); - + expect(div.selectAll('input[type="checkbox"]').size()).toBe(5); + expect(div.selectAll('input[value="compare"]').size()).toBe(1); + expect(div.selectAll('input[value="median"]').size()).toBe(1); resolve(); }); }); }); - it('creates an unordered list and the correct number of list items and hyperlinks if P30D is selected', () => { - const TEST_STATE = { - 'hydrographData': { - ...TEST_STATE_BASE.hydrographData, - 'medianStatisticsData': { - '69928': [{}] - }, - 'compareIVData': { - 'parameter': {}, - 'values':{'69928': {'points': [{},{}]}} - } - }, - 'hydrographState': { - 'showCompareIVData': true, - 'showMedianData': true, - 'selectedDateRange': 'P30D', - 'selectedParameterCode': '00060' - } - }; - let store = configureStore(TEST_STATE); - const siteNumber = '05370000'; - div.call(drawDownloadLinks, store, siteNumber); - return new Promise(resolve => { - window.requestAnimationFrame(() => { - expect(div.selectAll('ul').size()).toBe(1); - expect(div.selectAll('li').size()).toBe(4); - expect(div.selectAll('a').size()).toBe(5); - const anchorSelection = div.selectAll('a'); - const anchorElements = anchorSelection.nodes(); - - expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=05370000¶meterCd=00060&startDT=2021-02-25T10:54:27.139-06:00&endDT=2021-03-04T10:54:27.139-06:00&siteStatus=all&format=rdb'); - expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot-more-than-120-days.com/iv/?sites=05370000¶meterCd=00060&startDT=2020-02-26T10:54:27.139-06:00&endDT=2020-03-04T10:54:27.139-06:00&siteStatus=all&format=rdb'); - expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/stat/?sites=05370000&statReportType=daily&statTypeCd=median¶meterCd=00060&format=rdb'); - expect(anchorElements[3].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); - expect(anchorElements[4].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); - - resolve(); - }); - }); + it('Shows an error message if the download button is clicked with no checkboxes checked', () => { + const downloadButton = div.select('button.download-selected-data'); + downloadButton.dispatch('click'); + expect(div.select('.usa-alert--error').size()).toBe(1); }); - it('creates an unordered list and the correct number of list items and hyperlinks when custom days are selected', () => { - const TEST_STATE = { - 'hydrographData': { - ...TEST_STATE_BASE.hydrographData - }, - 'hydrographState': { - ...TEST_STATE_BASE.hydrographState, - 'selectedDateRange': 'P14D' - } - }; - let store = configureStore(TEST_STATE); - const siteNumber = '05370000'; - div.call(drawDownloadLinks, store, siteNumber); - return new Promise(resolve => { - window.requestAnimationFrame(() => { - expect(div.selectAll('ul').size()).toBe(1); - expect(div.selectAll('li').size()).toBe(2); - expect(div.selectAll('a').size()).toBe(3); - const anchorSelection = div.selectAll('a'); - const anchorElements = anchorSelection.nodes(); + it('Opens a window with the URL for the selected data', () => { + const downloadButton = div.select('button.download-selected-data'); + div.select('input[value="site"]').property('checked', true); + downloadButton.dispatch('click'); - expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=05370000¶meterCd=00060&startDT=2021-02-25T10:54:27.139-06:00&endDT=2021-03-04T10:54:27.139-06:00&siteStatus=all&format=rdb'); - expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); - expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); + expect(div.select('.usa-alert--error').size()).toBe(0); + expect(windowSpy.mock.calls).toHaveLength(1); + expect(windowSpy.mock.calls[0][0]).toContain('/site/'); + expect(windowSpy.mock.calls[0][0]).toContain('sites=11112222'); - resolve(); - }); - }); }); - it('creates an unordered list and the correct number of list items and hyperlinks when custom calendar dates are selected', () => { - const TEST_STATE = { - 'hydrographData': { - 'currentTimeRange': { - 'start': 1614574800000, - 'end': 1614920399999 - }, - 'primaryIVData': { - 'parameter': {}, - 'values':{'69928': {'points': [{},{}]}} - } - }, - 'hydrographState': { - 'selectedDateRange': 'custom', - 'selectedCustomDateRange': { - 'start': '2021-03-01', - 'end': '2021-03-04' - }, - 'selectedParameterCode': '00060' - } - }; - let store = configureStore(TEST_STATE); - const siteNumber = '05370000'; - div.call(drawDownloadLinks, store, siteNumber); + it('Opens a window for each selected data', () => { + const downloadButton = div.select('button.download-selected-data'); + store.dispatch(setMedianDataVisibility(true)); return new Promise(resolve => { window.requestAnimationFrame(() => { - expect(div.selectAll('ul').size()).toBe(1); - expect(div.selectAll('li').size()).toBe(2); - expect(div.selectAll('a').size()).toBe(3); - const anchorSelection = div.selectAll('a'); - const anchorElements = anchorSelection.nodes(); + div.select('input[value="primary"]').property('checked', true); + div.select('input[value="groundwater-levels"]').property('checked', true); + div.select('input[value="median"]').property('checked', true); + downloadButton.dispatch('click'); - expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=05370000¶meterCd=00060&startDT=2021-02-28T23:00:00.000-06:00&endDT=2021-03-04T22:59:59.999-06:00&siteStatus=all&format=rdb'); - expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); - expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); + expect(windowSpy.mock.calls).toHaveLength(3); - resolve(); - }); - }); - }); + expect(windowSpy.mock.calls[0][0]).toContain('/iv/'); + expect(windowSpy.mock.calls[0][0]).toContain('sites=11112222'); + expect(windowSpy.mock.calls[0][0]).toContain('parameterCd=72019'); + expect(windowSpy.mock.calls[0][0]).toContain('startDT=2020-02-24T10:15:00.000-06:00'); + expect(windowSpy.mock.calls[0][0]).toContain('endDT=2020-09-20T11:45:00.000-05:00'); - it('creates an unordered list and the correct number of list items and hyperlinks when a parameter other than 00060 is used', () => { - const TEST_STATE = { - 'hydrographData': { - 'currentTimeRange': { - 'start': 1614574800000, - 'end': 1614920399999 - }, - 'primaryIVData': { - 'parameter': {}, - 'values':{'69928': {'points': [{},{}]}} - } - }, - 'hydrographState': { - 'selectedDateRange': 'custom', - 'selectedCustomDateRange': { - 'start': '2021-03-01', - 'end': '2021-03-04' - }, - 'selectedParameterCode': '00010' - } - }; - let store = configureStore(TEST_STATE); - const siteNumber = '05370000'; - div.call(drawDownloadLinks, store, siteNumber); - return new Promise(resolve => { - window.requestAnimationFrame(() => { - expect(div.selectAll('ul').size()).toBe(1); - expect(div.selectAll('li').size()).toBe(2); - expect(div.selectAll('a').size()).toBe(3); - const anchorSelection = div.selectAll('a'); - const anchorElements = anchorSelection.nodes(); + expect(windowSpy.mock.calls[1][0]).toContain('/stat/'); + expect(windowSpy.mock.calls[1][0]).toContain('statTypeCd=median'); + expect(windowSpy.mock.calls[1][0]).toContain('parameterCd=72019'); - expect(anchorElements[0].getAttribute('href')).toBe('https://fakeserviceroot.com/iv/?sites=05370000¶meterCd=00010&startDT=2021-02-28T23:00:00.000-06:00&endDT=2021-03-04T22:59:59.999-06:00&siteStatus=all&format=rdb'); - expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); - expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); + expect(windowSpy.mock.calls[2][0]).toContain('/gwlevels/'); + expect(windowSpy.mock.calls[2][0]).toContain('sites=11112222'); + expect(windowSpy.mock.calls[0][0]).toContain('parameterCd=72019'); + expect(windowSpy.mock.calls[0][0]).toContain('startDT=2020-02-24T10:15:00.000-06:00'); + expect(windowSpy.mock.calls[0][0]).toContain('endDT=2020-09-20T11:45:00.000-05:00'); resolve(); }); }); }); - it('Renders the correct links when only groundwater data is available', () => { - const TEST_STATE = { - 'hydrographData': { - 'currentTimeRange': { - 'start': 1583340809223, - 'end': 1614876809223 - }, - 'groundwaterLevels': { - 'parameter': {}, - 'values': [{'value': 300}] - }, - 'primaryIVData': { - 'parameter': {}, - 'values':{'69928': {'points': [{},{}]}} - } - }, - 'hydrographState': { - 'selectedDateRange': 'P365D', - 'selectedParameterCode': '72019' - } - }; + it('Expects the error alert to disappear once a user checks a box and clicks download', () => { + const downloadButton = div.select('button.download-selected-data'); + downloadButton.dispatch('click'); + div.select('input[value="site"]').property('checked', true); + downloadButton.dispatch('click'); - let store = configureStore(TEST_STATE); - const siteNumber = '05370000'; - div.call(drawDownloadLinks, store, siteNumber); - return new Promise(resolve => { - window.requestAnimationFrame(() => { - expect(div.selectAll('ul').size()).toBe(1); - expect(div.selectAll('li').size()).toBe(2); - expect(div.selectAll('a').size()).toBe(3); - const anchorSelection = div.selectAll('a'); - const anchorElements = anchorSelection.nodes(); - - expect(anchorElements[0].getAttribute('href')).toContain('https://fakegroundwater.org/gw/?sites=05370000¶meterCd=72019'); - expect(anchorElements[1].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteStatus=all'); - expect(anchorElements[2].getAttribute('href')).toBe('https://fakeserviceroot.com/site/?format=rdb&sites=05370000&siteOutput=expanded&siteStatus=all'); - - resolve(); - }); - }); + expect(div.select('.usa-alert--error').size()).toBe(0); }); }); }); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/index.js b/assets/src/scripts/monitoring-location/components/hydrograph/index.js index 38c72cdd4147d3dac80d0ce7ea5f86d6cecb36a2..f191afb7ea0ecc7d2f4ad3849e3658eea6e79fd4 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/index.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/index.js @@ -129,7 +129,6 @@ export const attachToNode = function(store, nodeElem.select('#hydrograph-method-picker-container') .call(drawMethodPicker, store); - legendControlsContainer.call(drawGraphControls, store, siteno); nodeElem.select('.select-actions-container').call(drawSelectActions, store, siteno); 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 5ca8249fe3686114a34c23dab2190251a2e84f88..d353faef7af3d8ccfce412700155d9ef52b6e994 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js @@ -41,7 +41,7 @@ describe('monitoring-location/components/hydrograph module', () => { } }; - config.igwPeriodOfRecord = { + config.gwPeriodOfRecord = { '72019': { begin_date: '01-02-2000', end_date: '10-15-2015' @@ -66,13 +66,12 @@ describe('monitoring-location/components/hydrograph module', () => { .attr('href', 'https://fakeserver/link'); let component = body.append('div') .attr('id', 'hydrograph'); - component.append('div').attr('id', 'hydrograph-date-controls-container'); component.append('div').attr('id', 'hydrograph-method-picker-container'); component.append('div').attr('class', 'graph-container') .append('div') .attr('id', 'hydrograph-loading-indicator-container') .attr('class', 'loading-indicator-container'); - + 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'); @@ -315,9 +314,8 @@ describe('monitoring-location/components/hydrograph module', () => { expect(selectAll('.cursor-slider-svg').size()).toBe(1); }); - it('should have date control elements', () => { - expect(selectAll('#ts-daterange-select-container').size()).toBe(1); - expect(selectAll('#ts-customdaterange-select-container').size()).toBe(1); + it('should have date control form', () => { + expect(selectAll('#change-time-span-container').size()).toBe(1); }); it('should have method select element', () => { 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 a09a32bca78435fb605d5984b6fbcee65504a884..25a75a4147fcf85c7e719c8dc5ed8996d912e3d8 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 @@ -58,7 +58,7 @@ export const hasVisibleMedianStatisticsData = createSelector( export const hasVisibleGroundwaterLevels = createSelector( getGroundwaterLevels, - (gwLevels) => gwLevels && gwLevels.values && gwLevels.values.length + gwLevels => gwLevels && gwLevels.values ? gwLevels.values.length > 0 : false ); /* 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 98e383d31acb71805aeaa0bd243133ab937ffdf5..68cbce0d3bfe92d15d756cabc2735488b88ff59c 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 @@ -2,8 +2,8 @@ import config from 'ui/config'; import {TEST_PRIMARY_IV_DATA, TEST_MEDIAN_DATA, TEST_GW_LEVELS} from '../mock-hydrograph-state'; import { - isVisible, hasAnyVisibleData, getTitle, getDescription, getPrimaryParameterUnitCode, - getPreferredIVMethodID + isVisible, hasVisibleIVData, hasVisibleGroundwaterLevels, hasVisibleMedianStatisticsData, hasAnyVisibleData, + getTitle, getDescription, getPrimaryParameterUnitCode, getPreferredIVMethodID } from './time-series-data'; @@ -70,7 +70,103 @@ describe('monitoring-location/components/hydrograph/selectors/time-series-data m }); }); - describe('hasVisibleData', () => { + describe('hasVisibleIVData', () => { + it('return false if no data exists', () => { + expect(hasVisibleIVData('primary')({ + hydrographData: {}, + hydrographState: {} + })).toBe(false); + }); + + it('Return false if data has been selected but no data exists', () => { + expect(hasVisibleIVData('compare')(TEST_STATE)).toBe(false); + }); + + it('return true if data is selected and visible', () => { + expect(hasVisibleIVData('primary')(TEST_STATE)).toBe(true); + }); + + it('Return false if data is selected but no data points are available', () => { + expect(hasVisibleIVData('primary')({ + ...TEST_STATE, + hydrographState: { + ...TEST_STATE.hydrographState, + selectedIVMethodID: '69937' + } + })).toBe(false); + }); + }); + + describe('hasVisibleMedianStatisticsData', () => { + it('Return false if no data is available', () => { + expect(hasVisibleMedianStatisticsData({ + hydrographData: {}, + hydrographState: {} + })).toBe(false); + }); + + it('Return false if median data is available for not selected for display', () => { + expect(hasVisibleMedianStatisticsData({ + hydrographData: { + medianStatisticsData: TEST_MEDIAN_DATA + }, + hydrographState: { + showMedianData: false + } + })).toBe(false); + }); + + it('Return false if no median data is available and but is selected for display', () => { + expect(hasVisibleMedianStatisticsData({ + hydrographData: { + medianStatisticsData: {} + }, + hydrographState: { + showMedianData: true + } + })).toBe(false); + }); + + it('return true if median data is available and it is selected for display', () => { + expect(hasVisibleMedianStatisticsData({ + hydrographData: { + medianStatisticsData: TEST_MEDIAN_DATA + }, + hydrographState: { + showMedianData: true + } + })).toBe(true); + }); + }); + + describe('hasVisibleGroundwaterLevels', () => { + it('Return false if no data is available', () => { + expect(hasVisibleGroundwaterLevels({ + hydrographData: {} + })).toBe(false); + }); + + it('Return false if the data contains no points', () => { + expect(hasVisibleGroundwaterLevels({ + hydrographData: { + groundwaterLevels: { + ...TEST_GW_LEVELS, + values: [] + } + } + })).toBe(false); + }); + + it('Return true if the data contains points', () => { + expect(hasVisibleGroundwaterLevels({ + hydrographData: { + groundwaterLevels: TEST_GW_LEVELS + } + })).toBe(true); + }); + }); + + describe('hasAnyVisibleData', () => { it('Expects to return true when data is available and visible', () => { expect(hasAnyVisibleData({ hydrographData: { @@ -245,7 +341,7 @@ describe('monitoring-location/components/hydrograph/selectors/time-series-data m hydrographData: { primaryIVData: { parameter: { - parameterCode: '00030', + parameterCode: '00030' }, values: {} }