From ff2e5502a46f642de65d28023739894354ca6ad6 Mon Sep 17 00:00:00 2001 From: Aaron Briggs <abriggs@contractor.usgs.gov> Date: Tue, 14 Jun 2022 11:32:16 -0500 Subject: [PATCH] fixed tests added tests --- .../components/hydrograph/data-table.test.js | 54 ------------------- .../components/hydrograph/index.test.js | 3 +- .../vue-components/data-table.test.js | 46 ++++++++++++++++ 3 files changed, 47 insertions(+), 56 deletions(-) diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/data-table.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/data-table.test.js index 1fec9a09a..727cbe7a3 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/data-table.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/data-table.test.js @@ -46,8 +46,6 @@ describe('monitoring-location/components/hydrograph/data-table', () => { const gwTable = testDiv.select('#gw-table-container').select('table'); expect(gwTable.select('caption').text()).toBe('Field visit data'); expect(gwTable.selectAll('tr').size()).toBe(5); - const downloadSection = testDiv.select('#download-graph-data-container-data-table'); - expect(downloadSection.selectAll('input[type="radio"]').size()).toBe(3); }); it('Shows single IV table if no GW levels', () => { @@ -93,56 +91,4 @@ describe('monitoring-location/components/hydrograph/data-table', () => { expect(testDiv.select('#iv-table-container').style('display')).toBe('none'); expect(testDiv.select('#gw-table-container').style('display')).not.toBe('none'); }); - - it('Clicking the download button shows the download container', () => { - store = configureStore({ - hydrographData: { - currentTimeRange: { - start: 1582560000000, - end: 1600620000000 - }, - primaryIVData: TEST_PRIMARY_IV_DATA - }, - groundwaterLevelData: { - all: [TEST_GW_LEVELS] - }, - hydrographState: { - selectedParameterCode: '72019', - selectedIVMethodID: '90649' - } - }); - drawDataTables(testDiv, store, '11112222', 'USGS'); - - const downloadButton = testDiv.select('#download-graph-data-container-data-table-toggle'); - expect(downloadButton.size()).toBe(1); - - downloadButton.dispatch('click'); - expect(testDiv.select('#download-graph-data-container-data-table').attr('hidden')).toBeNull(); - }); - - it('Clicking the download button twice hides the download container', () => { - store = configureStore({ - hydrographData: { - currentTimeRange: { - start: 1582560000000, - end: 1600620000000 - }, - primaryIVData: TEST_PRIMARY_IV_DATA - }, - groundwaterLevelData: { - all: [TEST_GW_LEVELS] - }, - hydrographState: { - selectedParameterCode: '72019', - selectedIVMethodID: '90649' - } - }); - drawDataTables(testDiv, store, '11112222', 'USGS'); - - const downloadButton = testDiv.select('#download-graph-data-container-data-table-toggle'); - downloadButton.dispatch('click'); - downloadButton.dispatch('click'); - - expect(testDiv.select('#download-graph-data-container-data-table').attr('hidden')).not.toBeNull(); - }); }); 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 601a46ff6..b721b8566 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js @@ -363,9 +363,8 @@ describe('monitoring-location/components/hydrograph module', () => { expect(selectAll('#change-time-span-container').size()).toBe(1); }); - it('should have two download data forms', () => { + it('should have one download container added with d3 (the vue component will not show in test)', () => { expect(selectAll('#download-graph-data-container-select-actions').size()).toBe(1); - expect(selectAll('#download-graph-data-container-data-table').size()).toBe(1); }); it('should have method select element', () => { diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/vue-components/data-table.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/vue-components/data-table.test.js index d9b5e9c6a..9a18e0ad2 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/vue-components/data-table.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/vue-components/data-table.test.js @@ -10,6 +10,7 @@ import {configureStore} from 'ml/store'; import {TEST_PRIMARY_IV_DATA, TEST_GW_LEVELS} from '../mock-hydrograph-state'; import DataTable from './data-table.vue'; +import DownloadData from './download-data.vue'; describe('monitoring-location/components/hydrograph/components/data-table.vue', () => { let store; @@ -126,4 +127,49 @@ describe('monitoring-location/components/hydrograph/components/data-table.vue', expect(wrapper.find('#iv-table-container').isVisible()).toBe(false); expect(wrapper.find('#gw-table-container').isVisible()).toBe(true); }); + + it('Shows only data retrieve button and download container', async() => { + store = configureStore({ + hydrographData: { + currentTimeRange: { + start: 1582560000000, + end: 1600620000000 + }, + primaryIVData: TEST_PRIMARY_IV_DATA + }, + groundwaterLevelData: { + all: [] + }, + hydrographState: { + selectedParameterCode: '72019', + selectedIVMethodID: '90649' + } + }); + + wrapper = mount(DataTable, { + global: { + plugins: [ + [ReduxConnectVue, { + store, + mapDispatchToPropsFactory: (actionCreators) => (dispatch) => bindActionCreators(actionCreators, dispatch), + mapStateToPropsFactory: createStructuredSelector + }] + ], + provide: { + store: store, + siteno: '11112222', + agencyCd: 'USGS', + buttonSetName: 'test-buttons' + } + } + }); + + expect(wrapper.findAll('button')).toHaveLength(1); + expect(wrapper.find('button').text()).toBe('Retrieve data'); + expect(wrapper.findAllComponents(DownloadData)).toHaveLength(0); + await wrapper.find('button').trigger('click'); + expect(wrapper.findAllComponents(DownloadData)).toHaveLength(1); + await wrapper.find('button').trigger('click'); + expect(wrapper.findAllComponents(DownloadData)).toHaveLength(0); + }); }); -- GitLab