Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

unit tests for getEventsRequestURL

Jason Kent2c82253ddf80
diff --git a/web/js/fixtures.js b/web/js/fixtures.js
index 9940f73e3..1fc89d287 100644
--- a/web/js/fixtures.js
+++ b/web/js/fixtures.js
@@ -5,6 +5,7 @@ import { initialCompareState } from './modules/compare/reducers';
import { getInitialState as getInitialDateState } from './modules/date/reducers';
import { defaultState as initialAnimationState } from './modules/animation/reducers';
import { defaultAlertState } from './modules/alerts/reducer';
+import { getInitialEventsState } from './modules/natural-events/reducers';
const fixtures = {
red: 'ff0000ff',
@@ -23,7 +24,15 @@ fixtures.getState = function() {
layers: initialLayerState,
alerts: defaultAlertState,
date: getInitialDateState(fixtures.config()),
+ events: getInitialEventsState(fixtures.config()),
+ map: fixtures.map(),
animation: initialAnimationState,
+ proj: {
+ selected: {
+ id: 'geographic',
+ crs: 'EPSG:4326',
+ },
+ },
palettes: {
active: {},
activeB: {},
@@ -189,6 +198,16 @@ fixtures.getState = function() {
};
};
+fixtures.map = () => ({
+ ui: {
+ selected: {
+ getView: () => ({
+ calculateExtent: () => [-15.06, 27.16, 13.32, 56.06],
+ }),
+ },
+ },
+});
+
fixtures.config = function() {
return {
pageLoadTime: new Date(),
@@ -355,8 +374,32 @@ fixtures.config = function() {
period: 'daily',
},
},
+ naturalEvents: {
+ categories: [
+ {
+ id: 'dustHaze',
+ title: 'Dust and Haze',
+ description: 'Related to dust storms, air pollution and other non-volcanic aerosols. Volcano-related plumes shall be included with the originating eruption event.',
+ layers: 'https://eonet.sci.gsfc.nasa.gov/api/v3/layers/dustHaze',
+ },
+ {
+ id: 'manmade',
+ title: 'Manmade',
+ description: 'Events that have been human-induced and are extreme in their extent.',
+ layers: 'https://eonet.sci.gsfc.nasa.gov/api/v3/layers/manmade',
+ },
+ {
+ id: 'seaLakeIce',
+ title: 'Sea and Lake Ice',
+ description: 'Related to all ice that resides on oceans and lakes, including sea and lake ice (permanent and seasonal) and icebergs.',
+ layers: 'https://eonet.sci.gsfc.nasa.gov/api/v3/layers/seaLakeIce',
+ }],
+ },
features: {
compare: true,
+ naturalEvents: {
+ host: 'fake.eonet.url/api',
+ },
},
palettes: {
lookups: {
diff --git a/web/js/modules/natural-events/util.test.js b/web/js/modules/natural-events/util.test.js
new file mode 100644
index 000000000..a6c77eddd
--- /dev/null
+++ b/web/js/modules/natural-events/util.test.js
@@ -0,0 +1,83 @@
+import { config } from '@fortawesome/fontawesome-svg-core';
+import { getEventsRequestURL } from './util';
+import fixtures from '../../fixtures';
+
+let initialState = fixtures.getState();
+
+initialState = {
+ ...initialState,
+ events: {
+ ...initialState.events,
+ selectedDates: {
+ start: '2020-01-01',
+ end: '2021-01-01',
+ },
+ selectedCategories: [
+ { id: 'snow' },
+ { id: 'wildfires' },
+ { id: 'manmade' },
+ ],
+ },
+};
+
+const mockProj = {
+ geographic: { selected: { crs: 'EPSG:4326' } },
+ arctic: { selected: { crs: 'EPSG:3413' } },
+ antarctic: { selected: { crs: 'EPSG:3031' } },
+};
+
+const updateEventState = (newState, state) => ({
+ ...state,
+ events: {
+ ...state.events,
+ ...newState,
+ },
+});
+
+const updateProjState = (newState, state) => ({
+ ...state,
+ proj: {
+ ...newState,
+ },
+});
+
+test('Request URL with grographic proj and no bbox', () => {
+ const requestURL = getEventsRequestURL(initialState);
+ expect(requestURL).toBe('fake.eonet.url/api/events?status=all&limit=50&bbox=-180%2C90%2C180%2C-90&start=2020-01-01&end=2021-01-01&category=snow%2Cwildfires%2Cmanmade');
+});
+
+test('Request URL with grographic proj and bbox set', () => {
+ const state = updateEventState({ showAll: false }, initialState);
+ const requestURL = getEventsRequestURL(state);
+ expect(requestURL).toBe('fake.eonet.url/api/events?status=all&limit=50&bbox=-15.06%2C27.16%2C13.32%2C56.06&start=2020-01-01&end=2021-01-01&category=snow%2Cwildfires%2Cmanmade');
+});
+
+test('Request URL doesn\'t include categories param if none set', () => {
+ const state = updateEventState({ selectedCategories: [] }, initialState);
+ const requestURL = getEventsRequestURL(state);
+ expect(requestURL).toBe('fake.eonet.url/api/events?status=all&limit=50&bbox=-180%2C90%2C180%2C-90&start=2020-01-01&end=2021-01-01');
+});
+
+test('Uses mock events if mockEvents param is present', () => {
+ const state = {
+ ...initialState,
+ config: {
+ ...config,
+ parameters: {
+ mockEvents: 'true',
+ },
+ },
+ };
+ const requestURL = getEventsRequestURL(state);
+ expect(requestURL).toBe('mock/events_data.json');
+});
+
+test('Request URL with polar proj uses default bbox', () => {
+ let state = updateProjState(mockProj.arctic, initialState);
+ state = updateEventState({
+ showAll: false,
+ selectedCategories: [{ id: 'snow' }],
+ }, state);
+ const requestURL = getEventsRequestURL(state);
+ expect(requestURL).toBe('fake.eonet.url/api/events?status=all&limit=50&bbox=-180%2C40%2C180%2C90&start=2020-01-01&end=2021-01-01&category=snow');
+});