Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

add datearray building unit tests, modify fixtures used in tests, remove previous date from being returned in getMinStartDate

Ed Plato3c5de57b316b
diff --git a/web/js/fixtures.js b/web/js/fixtures.js
index bdb55fd1a..7a1e30500 100644
--- a/web/js/fixtures.js
+++ b/web/js/fixtures.js
@@ -218,8 +218,15 @@ fixtures.config = function() {
'terra-cr': {
id: 'terra-cr',
group: 'baselayers',
+ dateRanges: [
+ {
+ dateInterval: '1',
+ endDate: '2020-05-20T00:00:00Z',
+ startDate: '2000-02-24T00:00:00Z',
+ },
+ ],
period: 'daily',
- startDate: '2000-01-01',
+ startDate: '2000-02-24T00:00:00Z',
projections: {
geographic: {},
arctic: {},
diff --git a/web/js/modules/layers/util.js b/web/js/modules/layers/util.js
index df67d4990..b84d0f9e5 100644
--- a/web/js/modules/layers/util.js
+++ b/web/js/modules/layers/util.js
@@ -211,7 +211,7 @@ const getMinStartDate = (timeDiff, period, interval, startDateLimit, minYear, mi
timeUnit = util.getTimezoneOffsetDate(timeUnit);
const timeUnitTime = timeUnit.getTime();
- if (timeUnitTime >= startDateLimitTime) {
+ if (timeUnitTime > startDateLimitTime) {
minStartDate = prevDate;
} else {
prevDate = timeUnit;
diff --git a/web/js/modules/layers/util.test.js b/web/js/modules/layers/util.test.js
index 36efc5712..7237ff49a 100644
--- a/web/js/modules/layers/util.test.js
+++ b/web/js/modules/layers/util.test.js
@@ -1,5 +1,6 @@
import { assign } from 'lodash';
import {
+ datesinDateRanges,
serializeLayers,
layersParse12,
removeLayer,
@@ -238,4 +239,68 @@ describe('permalink 1.1', () => {
expect(activeLayers[0].id).toBe('terra-cr');
expect(activeLayers[0].visible).toBeFalsy();
});
+ test('test limited date range returned for layer with single date range and interval', () => {
+ const parameters = {
+ products: 'terra-cr',
+ };
+
+ const stateFromLocation = mapLocationToLayerState(
+ parameters,
+ defaultStateFromLocation,
+ globalState,
+ config,
+ );
+ const activeLayers = stateFromLocation.layers.active;
+ const dates = datesinDateRanges(activeLayers[0], new Date('2020-01-01'));
+ expect(dates.length).toBe(3);
+ });
+ test('test only next date returned (out of range past)', () => {
+ const parameters = {
+ products: 'terra-cr',
+ };
+
+ const stateFromLocation = mapLocationToLayerState(
+ parameters,
+ defaultStateFromLocation,
+ globalState,
+ config,
+ );
+ const activeLayers = stateFromLocation.layers.active;
+ const dates = datesinDateRanges(activeLayers[0], new Date('1990-01-01'));
+ expect(dates.length).toBe(1);
+ });
+ test('test no dates returned (out of range future)', () => {
+ const parameters = {
+ products: 'terra-cr',
+ };
+
+ const stateFromLocation = mapLocationToLayerState(
+ parameters,
+ defaultStateFromLocation,
+ globalState,
+ config,
+ );
+ const activeLayers = stateFromLocation.layers.active;
+ const dates = datesinDateRanges(activeLayers[0], new Date('2030-01-01'));
+ expect(dates.length).toBe(0);
+ });
+ test('test date range returned from given start/end date range for data panel', () => {
+ const parameters = {
+ products: 'terra-cr',
+ };
+
+ const stateFromLocation = mapLocationToLayerState(
+ parameters,
+ defaultStateFromLocation,
+ globalState,
+ config,
+ );
+ const activeLayers = stateFromLocation.layers.active;
+ const dates = datesinDateRanges(activeLayers[0], new Date('2018-01-01'), new Date('2017-12-01'), new Date('2018-02-01'), new Date('2020-01-01'));
+ const isFirstDateEqual = dates[0].toISOString() === '2017-12-01T00:00:00.000Z';
+ const isLastDateEqual = dates[dates.length - 1].toISOString() === '2018-01-31T00:00:00.000Z';
+ expect(dates.length).toBe(62);
+ expect(isFirstDateEqual).toBeTruthy();
+ expect(isLastDateEqual).toBeTruthy();
+ });
});