Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

add compare tests

Benjamin King3d4948f7095d
diff --git a/web/js/modules/compare/actions.test.js b/web/js/modules/compare/actions.test.js
new file mode 100644
index 000000000..256021ebf
--- /dev/null
+++ b/web/js/modules/compare/actions.test.js
@@ -0,0 +1,65 @@
+import * as CONSTANTS from './constants';
+import configureMockStore from 'redux-mock-store';
+import {
+ toggleActiveCompareState,
+ toggleCompareOnOff,
+ deactivateCompare,
+ setValue,
+ changeMode
+} from './actions';
+import thunk from 'redux-thunk';
+import { INIT_SECOND_LAYER_GROUP } from '../layers/constants';
+import fixtures from '../../fixtures';
+const middlewares = [thunk];
+const state = fixtures.getState();
+
+test('toggleCompareOnOff dispactches two actions', () => {
+ const mockStore = configureMockStore(middlewares);
+ const store = mockStore(state);
+ store.dispatch(toggleCompareOnOff());
+ const firstResponse = store.getActions()[0];
+ const secondResponse = store.getActions()[1];
+
+ expect(firstResponse.type).toEqual(INIT_SECOND_LAYER_GROUP);
+ expect(secondResponse.type).toEqual(CONSTANTS.TOGGLE_ON_OFF);
+});
+
+test(
+ 'toggleActiveCompareState returns ' + CONSTANTS.CHANGE_STATE + ' action type',
+ () => {
+ const expectedAction = {
+ type: CONSTANTS.CHANGE_STATE
+ };
+ expect(toggleActiveCompareState()).toEqual(expectedAction);
+ }
+);
+test(
+ 'deactivateCompare returns ' + CONSTANTS.DEACTIVATE + ' action type',
+ () => {
+ const expectedAction = {
+ type: CONSTANTS.DEACTIVATE
+ };
+ expect(deactivateCompare()).toEqual(expectedAction);
+ }
+);
+test(
+ 'setValue returns ' + CONSTANTS.CHANGE_VALUE + ' action type and value',
+ () => {
+ const expectedAction = {
+ type: CONSTANTS.CHANGE_VALUE,
+ value: 3
+ };
+ expect(setValue(3)).toEqual(expectedAction);
+ }
+);
+
+test(
+ 'changeMode returns ' + CONSTANTS.CHANGE_MODE + ' action type and mode value',
+ () => {
+ const expectedAction = {
+ type: CONSTANTS.CHANGE_MODE,
+ mode: 'some-mode'
+ };
+ expect(changeMode('some-mode')).toEqual(expectedAction);
+ }
+);
diff --git a/web/js/modules/compare/reducers.test.js b/web/js/modules/compare/reducers.test.js
new file mode 100644
index 000000000..75735888e
--- /dev/null
+++ b/web/js/modules/compare/reducers.test.js
@@ -0,0 +1,29 @@
+import { initialCompareState, compareReducer } from './reducers';
+import * as CONSTANTS from './constants';
+
+test('CHANGE_STATE update active state and activeString', () => {
+ const response = compareReducer(initialCompareState, {
+ type: CONSTANTS.CHANGE_STATE
+ });
+ expect(initialCompareState.activeString).toEqual('active');
+ expect(initialCompareState.isCompareA).toBeTruthy();
+ expect(response.activeString).toEqual('activeB');
+ expect(response.isCompareA).toBeFalsy();
+});
+
+test('TOGGLE_ON_OFF toggles compare feature on and off', () => {
+ const response = compareReducer(initialCompareState, {
+ type: CONSTANTS.TOGGLE_ON_OFF
+ });
+ expect(initialCompareState.active).toBeFalsy();
+ expect(response.active).toBeTruthy();
+});
+
+test('CHANGE_MODE updates mode', () => {
+ const response = compareReducer(initialCompareState, {
+ type: CONSTANTS.CHANGE_MODE,
+ mode: 'new-mode'
+ });
+ expect(initialCompareState.mode).toEqual('swipe');
+ expect(response.mode).toEqual('new-mode');
+});
diff --git a/web/js/modules/compare/util.test.js b/web/js/modules/compare/util.test.js
new file mode 100644
index 000000000..4b50fc1d9
--- /dev/null
+++ b/web/js/modules/compare/util.test.js
@@ -0,0 +1,13 @@
+import { mapLocationToCompareState } from './util';
+import { initialCompareState } from './reducers';
+const stateFromLocation = { compare: initialCompareState };
+const PERMALINK_STATE = { ca: '' };
+
+test('mapLocationToCompareState sets compare as active is ca is defined permalink', () => {
+ const response = mapLocationToCompareState(
+ PERMALINK_STATE,
+ stateFromLocation
+ );
+ expect(stateFromLocation.compare.active).toBeFalsy();
+ expect(response.compare.active).toBeTruthy();
+});