Interactive interface for browsing global, full-resolution satellite imagery
add anim unit tests
Benjamin Kingb089f96efc65
diff --git a/web/js/modules/animation/reducer.test.js b/web/js/modules/animation/reducer.test.jsindex d6209b095..0954cfb6b 100644--- a/web/js/modules/animation/reducer.test.js+++ b/web/js/modules/animation/reducer.test.js@@ -1,10 +1,11 @@import { defaultState, animationReducer } from './reducers';import * as CONSTANTS from './constants';import util from '../../util/util';+import update from 'immutability-helper';const now = new Date();const then = util.dateAdd(now, 'day', -7);-test('OPEN_ANIMATION action updates start and end s', () => {+test('OPEN_ANIMATION action updates start and end dates', () => {const response = animationReducer(defaultState, {type: CONSTANTS.OPEN_ANIMATION,date: now@@ -13,3 +14,89 @@ test('OPEN_ANIMATION action updates start and end s', () => {expect(response.endDate).toEqual(now);expect(response.isActive).toEqual(true);});++test('EXIT_ANIMATION action toggles isPlaying and isActive values', () => {+ let updatedState = update(defaultState, { isActive: { $set: true } });+ updatedState = update(updatedState, { isPlaying: { $set: true } });+ const response = animationReducer(updatedState, {+ type: CONSTANTS.EXIT_ANIMATION+ });+ expect(updatedState.isActive).toEqual(true);+ expect(updatedState.isPlaying).toEqual(true);+ expect(response.isActive).toEqual(false);+ expect(response.isPlaying).toEqual(false);+});+test('PLAY_ANIMATION action makes isPlaying truthy', () => {+ const response = animationReducer(defaultState, {+ type: CONSTANTS.PLAY_ANIMATION+ });+ expect(defaultState.isPlaying).toEqual(false);+ expect(response.isPlaying).toEqual(true);+});+test('UPDATE_FRAME_RATE action changes speed value', () => {+ const response = animationReducer(defaultState, {+ type: CONSTANTS.UPDATE_FRAME_RATE,+ value: 5+ });+ expect(defaultState.speed).toEqual(3);+ expect(response.speed).toEqual(5);+});+test('UPDATE_START_AND_END_DATE action updates dates', () => {+ const response = animationReducer(defaultState, {+ type: CONSTANTS.UPDATE_START_AND_END_DATE,+ startDate: then,+ endDate: now+ });+ expect(defaultState.startDate).toBeUndefined();+ expect(defaultState.endDate).toBeUndefined();+ expect(response.startDate).toEqual(then);+ expect(response.endDate).toEqual(now);+});+test('UPDATE_START_DATE action changes startDate value', () => {+ const response = animationReducer(defaultState, {+ type: CONSTANTS.UPDATE_START_DATE,+ value: then+ });+ expect(defaultState.startDate).toBeUndefined();+ expect(response.startDate).toEqual(then);+});+test('UPDATE_END_DATE action changes endDate value', () => {+ const response = animationReducer(defaultState, {+ type: CONSTANTS.UPDATE_END_DATE,+ value: now+ });+ expect(defaultState.startDate).toBeUndefined();+ expect(response.endDate).toEqual(now);+});+test('TOGGLE_LOOPING action toggles loop value', () => {+ const response = animationReducer(defaultState, {+ type: CONSTANTS.TOGGLE_LOOPING+ });+ expect(defaultState.loop).toBeFalsy();+ expect(response.loop).toBeTruthy();+});+test('TOGGLE_GIF action toggles gifActive bool value', () => {+ const response = animationReducer(defaultState, {+ type: CONSTANTS.TOGGLE_GIF+ });+ expect(defaultState.gifActive).toBeFalsy();+ expect(response.gifActive).toBeTruthy();+});++test('KEY_PRESS_ACTION action toggles isPlaying bool when animation is active', () => {+ let updatedState = update(defaultState, { isActive: { $set: true } });+ const response = animationReducer(updatedState, {+ type: 'KEY_PRESS_ACTION',+ keyCode: 32+ });+ expect(updatedState.isPlaying).toBeFalsy();+ expect(response.isPlaying).toBeTruthy();+});+test('KEY_PRESS_ACTION action does not toggle isPlaying bool when animation is inActive', () => {+ const response = animationReducer(defaultState, {+ type: 'KEY_PRESS_ACTION',+ keyCode: 32+ });+ expect(defaultState.isPlaying).toBeFalsy();+ expect(response.isPlaying).toBeFalsy();+});diff --git a/web/js/modules/animation/reducers.js b/web/js/modules/animation/reducers.jsindex 1c34fc5a6..546bd78d6 100644--- a/web/js/modules/animation/reducers.js+++ b/web/js/modules/animation/reducers.js@@ -13,7 +13,7 @@ import {TOGGLE_GIF} from './constants';-const defaultState = {+export const defaultState = {isActive: false,isPlaying: false,loop: false,diff --git a/web/js/modules/animation/util.test.js b/web/js/modules/animation/util.test.jsnew file mode 100644index 000000000..16c2f51bf--- /dev/null+++ b/web/js/modules/animation/util.test.js@@ -0,0 +1,13 @@+import { mapLocationToAnimationState } from './util';+import { defaultState } from './reducers';+const stateFromLocation = { animation: defaultState };+const PERMALINK_STATE = { ab: true, playanim: true };++test('mapLocationToAnimationState updates state to have isPlaying bool true if playanim and ab keys are present', () => {+ const response = mapLocationToAnimationState(+ PERMALINK_STATE,+ stateFromLocation+ );+ expect(stateFromLocation.animation.isPlaying).toBeFalsy();+ expect(response.animation.isPlaying).toBeTruthy();+});