Interactive interface for browsing global, full-resolution satellite imagery
Add notification request action unit test #1576
Benjamin Kingbaadefeb07d0
diff --git a/package-lock.json b/package-lock.jsonindex ce96ebd4d..37cd35319 100644--- a/package-lock.json+++ b/package-lock.json@@ -1331,16 +1331,6 @@"babel-template": "6.26.0"}},- "babel-jest": {- "version": "23.6.0",- "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-23.6.0.tgz",- "integrity": "sha512-lqKGG6LYXYu+DQh/slrQ8nxXQkEkhugdXsU6St7GmhVS7Ilc/22ArwqXNJrf0QaOBjZB0360qZMwXqDYQHXaew==",- "dev": true,- "requires": {- "babel-plugin-istanbul": "4.1.6",- "babel-preset-jest": "23.2.0"- }- },"babel-loader": {"version": "7.1.5","resolved": "https://registry.npmjs.org/babel-loader/-/babel-loader-7.1.5.tgz",@@ -1393,12 +1383,6 @@}}},- "babel-plugin-jest-hoist": {- "version": "23.2.0",- "resolved": "https://registry.npmjs.org/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-23.2.0.tgz",- "integrity": "sha1-5h+uBaHKiAGq3uV6bWa4zvr0QWc=",- "dev": true- },"babel-plugin-minify-builtins": {"version": "0.4.3","resolved": "https://registry.npmjs.org/babel-plugin-minify-builtins/-/babel-plugin-minify-builtins-0.4.3.tgz",@@ -2077,16 +2061,6 @@"babel-plugin-transform-flow-strip-types": "6.22.0"}},- "babel-preset-jest": {- "version": "23.2.0",- "resolved": "https://registry.npmjs.org/babel-preset-jest/-/babel-preset-jest-23.2.0.tgz",- "integrity": "sha1-jsegOhOPABoaj7HoETZSvxpV2kY=",- "dev": true,- "requires": {- "babel-plugin-jest-hoist": "23.2.0",- "babel-plugin-syntax-object-rest-spread": "6.13.0"- }- },"babel-preset-minify": {"version": "0.4.3","resolved": "https://registry.npmjs.org/babel-preset-minify/-/babel-preset-minify-0.4.3.tgz",@@ -6787,6 +6761,26 @@"ua-parser-js": "0.7.18"}},+ "fetch-mock": {+ "version": "7.3.0",+ "resolved": "https://registry.npmjs.org/fetch-mock/-/fetch-mock-7.3.0.tgz",+ "integrity": "sha512-KxBeS8vsADFbWPVomuwxYqOJ2obZo6CidgkypjDPeu6zl+tAJvh2GfLDmJ8u//xgBGM9iOGwOxafeqAclilH2A==",+ "dev": true,+ "requires": {+ "babel-polyfill": "6.26.0",+ "glob-to-regexp": "0.4.0",+ "path-to-regexp": "2.4.0",+ "whatwg-url": "6.5.0"+ },+ "dependencies": {+ "path-to-regexp": {+ "version": "2.4.0",+ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-2.4.0.tgz",+ "integrity": "sha512-G6zHoVqC6GGTQkZwF4lkuEyMbVOjoBKAEybQUypI1WTkqinCOrq2x6U2+phkJ1XsEMTy4LjtwPI7HW+NVrRR2w==",+ "dev": true+ }+ }+ },"ffi": {"version": "2.3.0","resolved": "https://registry.npmjs.org/ffi/-/ffi-2.3.0.tgz",@@ -7966,6 +7960,12 @@"is-glob": "2.0.1"}},+ "glob-to-regexp": {+ "version": "0.4.0",+ "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.0.tgz",+ "integrity": "sha512-fyPCII4vn9Gvjq2U/oDAfP433aiE64cyP/CJjRJcpVGjqqNdioUYn9+r0cSzT1XPwmGAHuTT7iv+rQT8u/YHKQ==",+ "dev": true+ },"global-dirs": {"version": "0.1.1","resolved": "https://registry.npmjs.org/global-dirs/-/global-dirs-0.1.1.tgz",@@ -9200,9 +9200,9 @@"dev": true},"ip-regex": {- "version": "3.0.0",- "resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-3.0.0.tgz",- "integrity": "sha512-T8wDtjy+Qf2TAPDQmBp0eGKJ8GavlWlUnamr3wRn6vvdZlKVuJXXMlSncYFRYgVHOM3If5NR1H4+OvVQU9Idvg==",+ "version": "2.1.0",+ "resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-2.1.0.tgz",+ "integrity": "sha1-+ni/XS5pE8kRzp+BnuUUa7bYROk=","dev": true},"ipaddr.js": {@@ -9978,6 +9978,32 @@"color-convert": "1.9.2"}},+ "babel-jest": {+ "version": "23.6.0",+ "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-23.6.0.tgz",+ "integrity": "sha512-lqKGG6LYXYu+DQh/slrQ8nxXQkEkhugdXsU6St7GmhVS7Ilc/22ArwqXNJrf0QaOBjZB0360qZMwXqDYQHXaew==",+ "dev": true,+ "requires": {+ "babel-plugin-istanbul": "4.1.6",+ "babel-preset-jest": "23.2.0"+ }+ },+ "babel-plugin-jest-hoist": {+ "version": "23.2.0",+ "resolved": "https://registry.npmjs.org/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-23.2.0.tgz",+ "integrity": "sha1-5h+uBaHKiAGq3uV6bWa4zvr0QWc=",+ "dev": true+ },+ "babel-preset-jest": {+ "version": "23.2.0",+ "resolved": "https://registry.npmjs.org/babel-preset-jest/-/babel-preset-jest-23.2.0.tgz",+ "integrity": "sha1-jsegOhOPABoaj7HoETZSvxpV2kY=",+ "dev": true,+ "requires": {+ "babel-plugin-jest-hoist": "23.2.0",+ "babel-plugin-syntax-object-rest-spread": "6.13.0"+ }+ },"chalk": {"version": "2.4.1","resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz",@@ -17723,7 +17749,7 @@"requires": {"csprng": "0.1.2","faye-websocket": "0.11.1",- "tough-cookie": "3.0.0",+ "tough-cookie": "3.0.1","tunnel-agent": "0.6.0"}},@@ -17734,12 +17760,12 @@"dev": true},"tough-cookie": {- "version": "3.0.0",- "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-3.0.0.tgz",- "integrity": "sha512-LHMvg+RBP/mAVNqVbOX8t+iJ+tqhBA/t49DuI7+IDAWHrASnesqSu1vWbKB7UrE2yk+HMFUBMadRGMkB4VCfog==",+ "version": "3.0.1",+ "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-3.0.1.tgz",+ "integrity": "sha512-yQyJ0u4pZsv9D4clxO69OEjLWYw+jbgspjTue4lTQZLfV0c5l1VmK2y1JK8E9ahdpltPOaAThPcp5nKPUgSnsg==","dev": true,"requires": {- "ip-regex": "3.0.0",+ "ip-regex": "2.1.0","psl": "1.1.28","punycode": "2.1.1"}@@ -18385,6 +18411,15 @@}}},+ "redux-mock-store": {+ "version": "1.5.3",+ "resolved": "https://registry.npmjs.org/redux-mock-store/-/redux-mock-store-1.5.3.tgz",+ "integrity": "sha512-ryhkkb/4D4CUGpAV2ln1GOY/uh51aczjcRz9k2L2bPx/Xja3c5pSGJJPyR25GNVRXtKIExScdAgFdiXp68GmJA==",+ "dev": true,+ "requires": {+ "lodash.isplainobject": "4.0.6"+ }+ },"redux-thunk": {"version": "2.3.0","resolved": "https://registry.npmjs.org/redux-thunk/-/redux-thunk-2.3.0.tgz",diff --git a/package.json b/package.jsonindex 3128770a7..d5bf88e39 100644--- a/package.json+++ b/package.json@@ -100,6 +100,7 @@"eslint-plugin-standard": "^3.0.1","expose-loader": "^0.7.5","express": "4.15.2",+ "fetch-mock": "^7.3.0","file-loader": "^1.1.11","geckodriver": "^1.12.0","glob": "^7.1.2",@@ -127,6 +128,7 @@"precss": "^3.1.2","rc-slider": "8.6.3","react-test-renderer": "^16.5.2",+ "redux-mock-store": "^1.5.3","run-script-os": "^1.0.3","sass-loader": "^7.1.0","selenium-server-standalone-jar": "^3.12.0",diff --git a/test-env.js b/test-env.jsindex b8b3275d7..dc06cfd1f 100644--- a/test-env.js+++ b/test-env.js@@ -1,2 +1,5 @@import $ from 'jquery';+import fetchMock from 'fetch-mock';+global.$ = global.jQuery = $;+global.fetch = fetchMock;diff --git a/web/js/app.js b/web/js/app.jsindex db0a37bcd..bf5f1df24 100644--- a/web/js/app.js+++ b/web/js/app.js@@ -1,5 +1,6 @@import React from 'react';import { connect } from 'react-redux';+import 'whatwg-fetch';import { debounce as lodashDebounce, each as lodashEach } from 'lodash';import googleTagManager from 'googleTagManager';diff --git a/web/js/link/model.test.js b/web/js/link/model.test.wip.jssimilarity index 100%rename from web/js/link/model.test.jsrename to web/js/link/model.test.wip.jsdiff --git a/web/js/modules/core/actions.js b/web/js/modules/core/actions.jsindex 52ad3636f..9c851623c 100644--- a/web/js/modules/core/actions.js+++ b/web/js/modules/core/actions.js@@ -1,5 +1,3 @@-import { fetch } from 'whatwg-fetch';-export function requestAction(dispatch, actionName, url, fileType, signal) {dispatch(startRequest(actionName));return new Promise(function(resolve, reject) {diff --git a/web/js/modules/notifications/actions.test.js b/web/js/modules/notifications/actions.test.jsnew file mode 100644index 000000000..cfe931874--- /dev/null+++ b/web/js/modules/notifications/actions.test.js@@ -0,0 +1,57 @@+import configureMockStore from 'redux-mock-store';+import thunk from 'redux-thunk';+import fetchMock from 'fetch-mock';+import * as actions from './actions';+import * as types from './constants';+const middlewares = [thunk];+const mockStore = configureMockStore(middlewares);++const RESPONSE_BODY = [+ {+ id: 537,+ notification_type: 'outage',+ message: 'This is a test Outage',+ updated_at: '2018-05-20T16:26:43.013-04:00',+ created_at: '2018-05-20T16:23:37.049-04:00',+ starttime: null,+ endtime: null,+ applications: ['Worldview (OPS)'],+ domains: ['https://worldview.earthdata.nasa.gov'],+ dismissible: true,+ path: ''+ }+];+const MOCK_RESPONSE = {+ success: true,+ notifications: RESPONSE_BODY+};++describe('Notification fetch action', () => {+ afterEach(() => {+ fetchMock.restore();+ });+ it('creates REQUEST_APP_NOTIFICATIONS_SUCCESS when fetching notifications is complete', () => {+ const loc = 'mock/notify-outage.json';+ fetchMock.getOnce(loc, {+ body: MOCK_RESPONSE,+ headers: {+ 'content-type': 'application/json',+ 'Access-Control-Allow-Origin': '*',+ 'Access-Control-Allow-Headers': 'Content-Type'+ }+ });+ const expectedActions = [+ { type: types.REQUEST_NOTIFICATIONS_START },+ {+ type: types.REQUEST_NOTIFICATIONS_SUCCESS,+ response: JSON.stringify(MOCK_RESPONSE)+ }+ ];+ const store = mockStore({ notifications: {} });+ return store+ .dispatch(actions.requestNotifications(loc, 'json'))+ .then(() => {+ expect(store.getActions()).toEqual(expectedActions);+ });+ });+});diff --git a/web/js/modules/notifications/constants.js b/web/js/modules/notifications/constants.jsindex 9ce8d0efa..83d2875d5 100644--- a/web/js/modules/notifications/constants.js+++ b/web/js/modules/notifications/constants.js@@ -1,4 +1,10 @@export const REQUEST_NOTIFICATIONS = 'REQUEST_APP_NOTIFICATIONS';+export const REQUEST_NOTIFICATIONS_START = 'REQUEST_APP_NOTIFICATIONS_START';+export const REQUEST_NOTIFICATIONS_SUCCESS =+ 'REQUEST_APP_NOTIFICATIONS_SUCCESS';+export const REQUEST_NOTIFICATIONS_FAILURE =+ 'REQUEST_APP_NOTIFICATIONS_FAILURE';+export const SET_NOTIFICATIONS = 'SET_NOTIFICATION_RESPONSE';export const NOTIFICATIONS_SEEN = 'NOTIFICATIONS_HAVE_BEEN_SEEN';export const STATUS_REQUEST_URL =