Interactive interface for browsing global, full-resolution satellite imagery
#2399 add unit tests for date/time snapping to interval
Jason Kenta246538080da
diff --git a/web/js/modules/animation/util.test.js b/web/js/modules/animation/util.test.jsindex 16c2f51bf..fd8391dd7 100644--- a/web/js/modules/animation/util.test.js+++ b/web/js/modules/animation/util.test.js@@ -1,9 +1,12 @@-import { mapLocationToAnimationState } from './util';+import {+ mapLocationToAnimationState,+ snapToIntervalDelta+} 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 stateFromLocation = { animation: defaultState };+ const PERMALINK_STATE = { ab: true, playanim: true };const response = mapLocationToAnimationState(PERMALINK_STATE,stateFromLocation@@ -11,3 +14,75 @@ test('mapLocationToAnimationState updates state to have isPlaying bool true if pexpect(stateFromLocation.animation.isPlaying).toBeFalsy();expect(response.animation.isPlaying).toBeTruthy();});++test('snapToIntervalDelta snaps at the year interval', () => {+ const currentDate = new Date('2010-06-23');+ const startDate = new Date(' 2000-04-15');+ const endDate = new Date(' 2019-08-24');+ const expected = new Date(' 2010-04-15');+ const snappedDate = snapToIntervalDelta(currentDate, startDate, endDate, 'year', 1);+ expect(snappedDate.valueOf()).toBe(expected.valueOf());+});++test('snapToIntervalDelta snaps at the month interval', () => {+ const currentDate = new Date('2018-6-23');+ const startDate = new Date(' 2018-4-15');+ const endDate = new Date(' 2019-8-24');+ const expected = new Date(' 2018-6-15');+ const snappedDate = snapToIntervalDelta(currentDate, startDate, endDate, 'month', 1);+ expect(snappedDate.valueOf()).toBe(expected.valueOf());+});++test('snapToIntervalDelta snaps at the day interval', () => {+ const currentDate = new Date('2018-07-04 12:34:00Z');+ const startDate = new Date(' 2018-04-15 08:00:00Z');+ const endDate = new Date(' 2018-08-24');+ const expected = new Date(' 2018-07-04 08:00:00Z');+ const snappedDate = snapToIntervalDelta(currentDate, startDate, endDate, 'day', 1);+ expect(snappedDate.valueOf()).toBe(expected.valueOf());+});++test('snapToIntervalDelta snaps at the hour interval', () => {+ const currentDate = new Date('2018-07-04 12:34:00Z');+ const startDate = new Date(' 2018-04-15 08:00:00Z');+ const endDate = new Date(' 2018-08-24');+ const expected = new Date(' 2018-07-04 12:00:00Z');+ const snappedDate = snapToIntervalDelta(currentDate, startDate, endDate, 'hour', 1);+ expect(snappedDate.valueOf()).toBe(expected.valueOf());+});++test('snapToIntervalDelta snaps at the minute interval', () => {+ const currentDate = new Date('2018-04-19 08:24:56Z');+ const startDate = new Date(' 2018-04-19 08:15:30Z');+ const endDate = new Date(' 2018-04-19 08:30:30Z');+ const expected = new Date(' 2018-04-19 08:24:30Z');+ const snappedDate = snapToIntervalDelta(currentDate, startDate, endDate, 'minute', 1);+ expect(snappedDate.valueOf()).toBe(expected.valueOf());+});++test('snapToIntervalDelta snaps at a custom hour interval', () => {+ const currentDate = new Date('2018-04-02 06:15:23Z');+ const startDate = new Date(' 2018-04-01 00:00:00Z');+ const endDate = new Date(' 2018-04-19 00:00:00Z');+ const expected = new Date(' 2018-04-02 06:00:00Z');+ const snappedDate = snapToIntervalDelta(currentDate, startDate, endDate, 'hour', 5);+ expect(snappedDate.valueOf()).toBe(expected.valueOf());+});++test('snapToIntervalDelta snaps to startDate if currentDate is after endDate', () => {+ const currentDate = new Date('2019-05-15 08:00:00Z');+ const startDate = new Date(' 2018-04-19 08:15:30Z');+ const endDate = new Date(' 2018-04-19 08:30:30Z');+ const expected = new Date(' 2018-04-19 08:15:30Z');+ const snappedDate = snapToIntervalDelta(currentDate, startDate, endDate, 'minute', 1);+ expect(snappedDate.valueOf()).toBe(expected.valueOf());+});++test('snapToIntervalDelta snaps to startDate if currentDate is before startDate', () => {+ const currentDate = new Date('2018-03-22 08:00:00');+ const startDate = new Date(' 2018-04-19 08:15:30Z');+ const endDate = new Date(' 2018-04-19 08:30:30Z');+ const expected = new Date(' 2018-04-19 08:15:30Z');+ const snappedDate = snapToIntervalDelta(currentDate, startDate, endDate, 'minute', 1);+ expect(snappedDate.valueOf()).toBe(expected.valueOf());+});