From b5eda86c7eaa6fffdd00b17a600628dfd26b7d92 Mon Sep 17 00:00:00 2001
From: Mary Bucknell <mbucknell@usgs.gov>
Date: Tue, 1 May 2018 08:30:57 -0500
Subject: [PATCH] Updated some of the test. Further work is needed.

---
 assets/src/scripts/store/index.js      | 10 +++++-----
 assets/src/scripts/store/index.spec.js | 17 +++++++++--------
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/assets/src/scripts/store/index.js b/assets/src/scripts/store/index.js
index c16784cd0..0370b82d5 100644
--- a/assets/src/scripts/store/index.js
+++ b/assets/src/scripts/store/index.js
@@ -61,7 +61,7 @@ export const Actions = {
                     startTime.setDate(endTime.getDate() - notes['filter:timeRange'].periodDays);
 
                     // Trigger a call to get last year's data
-                    dispatch(Actions.retrieveCompareTimeseries(siteno, startTime, endTime));
+                    dispatch(Actions.retrieveCompareTimeseries(siteno, 'P7D', startTime, endTime));
 
                     // Update the series data for the 'current' series
                     dispatch(Actions.addSeriesCollection('current', collection));
@@ -95,16 +95,15 @@ export const Actions = {
             });
         };
     },
-    retrieveCompareTimeseries(site, startTime, endTime) {
+    retrieveCompareTimeseries(site, period, startTime, endTime) {
         return function (dispatch, getState) {
             return getPreviousYearTimeseries({site, startTime, endTime}).then(
                 series => {
-                    const requestKey = getTsRequestKey('compare', 'P7D')(getState());
+                    const requestKey = getTsRequestKey('compare', period)(getState());
                     const collection = normalize(series, requestKey);
                     dispatch(Actions.addSeriesCollection(requestKey, collection));
-                    dispatch(Actions.toggleTimeseries('compare', false));
                 },
-                () => dispatch(Actions.resetTimeseries(getTsRequestKey('compare', 'P7D')(getState())))
+                () => dispatch(Actions.resetTimeseries(getTsRequestKey('compare', period)(getState())))
             );
         };
     },
@@ -141,6 +140,7 @@ export const Actions = {
                     series => {
                         const collection = normalize(series, requestKey);
                         dispatch(Actions.addSeriesCollection(requestKey, collection));
+                        dispatch(Actions.retrieveCompareTimeseries(site, period, startTime, endTime));
                     },
                     () => {
                         console.log(`Unable to fetch data for period ${period} and parameter code ${parmCd}`);
diff --git a/assets/src/scripts/store/index.spec.js b/assets/src/scripts/store/index.spec.js
index 2017e6f7c..d7af4f7fc 100644
--- a/assets/src/scripts/store/index.spec.js
+++ b/assets/src/scripts/store/index.spec.js
@@ -242,7 +242,7 @@ describe('Redux store', () => {
             });
 
             it('Fetches the previous year\'s time series', () => {
-                store.Actions.retrieveCompareTimeseries(SITE_NO, START_DATE, END_DATE)(mockDispatch, mockGetState);
+                store.Actions.retrieveCompareTimeseries(SITE_NO, 'P7D', START_DATE, END_DATE)(mockDispatch, mockGetState);
 
                 expect(modelsMock.getPreviousYearTimeseries.calls.count()).toBe(1);
                 expect(modelsMock.getPreviousYearTimeseries.calls.argsFor(0)[0]).toEqual({
@@ -255,13 +255,11 @@ describe('Redux store', () => {
             it('Dispatches the action to add the compare time series and to set its visibility to false', (done) => {
                 spyOn(store.Actions, 'addSeriesCollection');
                 spyOn(store.Actions, 'toggleTimeseries');
-                let p = store.Actions.retrieveCompareTimeseries(SITE_NO, START_DATE, END_DATE)(mockDispatch, mockGetState);
+                let p = store.Actions.retrieveCompareTimeseries(SITE_NO, 'P7D', START_DATE, END_DATE)(mockDispatch, mockGetState);
                 p.then(() => {
-                    expect(mockDispatch.calls.count()).toBe(2);
+                    expect(mockDispatch.calls.count()).toBe(1);
                     expect(store.Actions.addSeriesCollection.calls.count()).toBe(1);
                     expect(store.Actions.addSeriesCollection.calls.argsFor(0)[0]).toBe('compare:P7D');
-                    expect(store.Actions.toggleTimeseries.calls.count()).toBe(1);
-                    expect(store.Actions.toggleTimeseries.calls.argsFor(0)).toEqual(['compare', false]);
 
                     done();
                 });
@@ -292,7 +290,7 @@ describe('Redux store', () => {
 
             it('Dispatches the action to reset the compare time series', (done) => {
                 spyOn(store.Actions, 'resetTimeseries');
-                let p = store.Actions.retrieveCompareTimeseries(SITE_NO, START_DATE, END_DATE)(mockDispatch, mockGetState);
+                let p = store.Actions.retrieveCompareTimeseries(SITE_NO, 'P7D', START_DATE, END_DATE)(mockDispatch, mockGetState);
                 p.then(() => {
                     expect(mockDispatch).toHaveBeenCalled();
                     expect(store.Actions.resetTimeseries.calls.count()).toBe(1);
@@ -343,15 +341,18 @@ describe('Redux store', () => {
                 expect(args.endDate).toEqual(new Date('2017-03-31'));
             });
 
-            it('Should dispatch add series collection', (done) => {
+            it('Should dispatch add series collection and retrieveCompareTimeseries', (done) => {
                 mockGetState.and.returnValue(TEST_STATE);
+                spyOn(store.Actions, 'retrieveCompareTimeseries');
                 let p = store.Actions.retrieveExtendedTimeseries('12345678', 'P30D')(mockDispatch, mockGetState);
                 p.then(() => {
-                    expect(mockDispatch.calls.count()).toBe(2);
+                    expect(mockDispatch.calls.count()).toBe(3);
                     let arg = mockDispatch.calls.argsFor(1)[0];
                     expect(arg.type).toBe('ADD_TIMESERIES_COLLECTION');
                     expect(arg.key).toBe('current:P30D:00060');
 
+                    expect(store.Actions.retrieveCompareTimeseries).toHaveBeenCalled();
+                    expect(store.Actions.retrieveCompareTimeseries.calls.argsFor(0)[1]).toEqual('P30D');
                     done();
                 });
             });
-- 
GitLab