Skip to content
Snippets Groups Projects
index.spec.js 8.9 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { select } from 'd3-selection';
    import { attachToNode } from './index';
    
    import { Actions, configureStore } from '../../store';
    
                '00010:current': {
                    points: [{
    
                        dateTime: 1514926800000,
    
                        value: 4,
                        qualifiers: ['P']
                    }],
                    method: 'method1',
    
                    tsKey: 'current:P7D',
    
                    variable: '45807190'
                },
    
                        dateTime: 1514926800000,
    
                    tsKey: 'current:P7D',
    
                        dateTime: 1514926800000,
    
                    tsKey: 'compare:P7D',
    
                },
                'coll4': {
                    variable: '45807190',
                    timeSeries: ['00010:current']
    
                'current:P7D': {
    
                    notes: {
                        'filter:timeRange':  {
                            mode: 'PERIOD',
                            periodDays: 7
                        },
    
                        requestDT: 1522425600000
    
                'current:P7D': {
    
                'compare:P7D': {
    
                    timeSeriesCollections: ['coll2', 'col4']
    
                    variableCode: {
                        value: '00060'
                    },
    
                    variableName: 'Test title for 00060',
    
                    variableDescription: 'Test description for 00060',
    
                },
                '45807190': {
                    variableCode: {
                        value: '00010'
                    },
                    oid: '45807190',
                    unit: {
                        unitCode: 'unitCode'
                    }
    
            },
            methods: {
                'method1': {
                    methodDescription: 'method description'
                }
    
                    '1234': [
                        {
                            month_nu: '2',
                            day_nu: '20',
                            p50_va: '40',
                            begin_yr: '1970',
                            end_yr: '2017',
                            loc_web_ds: 'This method'
                        }, {
                            month_nu: '2',
                            day_nu: '21',
                            p50_va: '41',
                            begin_yr: '1970',
                            end_yr: '2017',
                            loc_web_ds: 'This method'
                        }, {
                            month_nu: '2',
                            day_nu: '22',
                            p50_va: '42',
                            begin_yr: '1970',
                            end_yr: '2017',
                            loc_web_ds: 'This method'
                        }
                    ]
                }
            }
        },
    
        timeSeriesState: {
    
            currentDateRange: 'P7D',
    
            requestedTimeRange: null,
    
    describe('Loading indicators and data alerts', () => {
    
            let body = select('body');
    
            component.append('div').attr('class', 'loading-indicator-container');
    
            component.append('div').attr('class', 'graph-container');
    
            component.append('div').attr('class', 'select-time-series-container');
    
            component.append('div').attr('class', 'provisional-data-alert');
    
    
            graphNode = document.getElementById('hydrograph');
    
        describe('hiding/showing provisional alert', () => {
    
            it('Expects the provisional alert to be visible when time series data is provided', () => {
                let store = configureStore(TEST_STATE);
                attachToNode(store, graphNode, {siteno: '12345678'});
    
                expect(select(graphNode).select('.provisional-data-alert').attr('hidden')).toBeNull();
            });
    
            it('Expects the provisional alert to be hidden when no time series data is provided', () => {
                let store = configureStore({
                    ...TEST_STATE,
                    series: {},
    
                    timeSeriesState: {
                        ...TEST_STATE.timeSeriesState,
    
                });
                attachToNode(store, graphNode, {siteno: '12345678'});
    
                expect(select(graphNode).select('.provisional-data-alert').attr('hidden')).toBe('true');
            });
        });
    
        describe('Tests for loading indicators', () => {
    
    
            it('Expects the graph loading indicator to be visible if the current 7 day data is being loaded', () => {
                const newTestState = {
                    ...TEST_STATE,
                    timeSeriesState: {
                        ...TEST_STATE.timeSeriesState,
                        currentDateRange: 'P7D',
                        loadingTSKeys: ['current:P7D']
                    }
                };
                let store = configureStore(newTestState);
    
                spyOn(store, 'dispatch').and.callThrough();
    
                attachToNode(store, graphNode, {siteno: '12345678'});
    
                expect(select(graphNode).select('.loading-indicator-container').select('.loading-indicator').size()).toBe(1);
            });
    
            it('Expects the graph loading indicator to not be visible if the current 7 day data is not being loaded', () => {
    
                const newTestState = {
                    ...TEST_STATE,
                    timeSeriesState: {
                        ...TEST_STATE.timeSeriesState,
                        currentDateRange: 'P7D'
                    }
                };
                let store = configureStore(newTestState);
                spyOn(store, 'dispatch').and.callThrough();
    
                attachToNode(store, graphNode, {siteno: '12345678'});
    
                store.dispatch(Actions.removeTimeSeriesLoading(['current:P7D']));
    
    
                expect(select(graphNode).select('.loading-indicator-container').select('.loading-indicator').size()).toBe(0);
            });
    
            it('Expects the date range control loading indicator to be visible if loading is in progress for the selected date range', () => {
                const newTestState = {
                    ...TEST_STATE,
                    timeSeriesState: {
                        ...TEST_STATE.timeSeriesState,
                        currentDateRange: 'P30D',
                        loadingTSKeys: ['current:P30D:00060']
                    }
                };
                let store = configureStore(newTestState);
                attachToNode(store, graphNode, {siteno: '12345678'});
    
                expect(select(graphNode).select('#ts-daterange-select-container').select('.loading-indicator').size()).toBe(1);
            });
    
            it('Expects the date range control loading indicator to notbe visible if not loading for the selected date range', () => {
                const newTestState = {
                    ...TEST_STATE,
                    timeSeriesState: {
                        ...TEST_STATE.timeSeriesState,
                        currentDateRange: 'P30D',
                        loadingTSKeys: ['compare:P30D:00060']
                    }
                };
                let store = configureStore(newTestState);
                attachToNode(store, graphNode, {siteno: '12345678'});
    
                expect(select(graphNode).select('#ts-daterange-select-container').select('.loading-indicator').size()).toBe(0);
            });
    
            it('Expects that the no data alert will not be shown if there is data', () => {
                let store = configureStore(TEST_STATE);
                attachToNode(store, graphNode, {siteno: '12345678'});
    
                expect(select(graphNode).select('#no-data-message').size()).toBe(0);
            });
        });