Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Fix/add unit tests, fix lint errors #2144

Benjamin King02265b8673c7
diff --git a/package-lock.json b/package-lock.json
index 1e0a2277a..8f4600828 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -5404,6 +5404,12 @@
"integrity": "sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==",
"dev": true
},
+ "cssfontparser": {
+ "version": "1.2.1",
+ "resolved": "https://registry.npmjs.org/cssfontparser/-/cssfontparser-1.2.1.tgz",
+ "integrity": "sha1-9AIvyPlwDGgCnVQghK+69CWj8+M=",
+ "dev": true
+ },
"cssnano": {
"version": "4.1.10",
"resolved": "https://registry.npmjs.org/cssnano/-/cssnano-4.1.10.tgz",
@@ -9966,6 +9972,16 @@
}
}
},
+ "jest-canvas-mock": {
+ "version": "2.2.0",
+ "resolved": "https://registry.npmjs.org/jest-canvas-mock/-/jest-canvas-mock-2.2.0.tgz",
+ "integrity": "sha512-DcJdchb7eWFZkt6pvyceWWnu3lsp5QWbUeXiKgEMhwB3sMm5qHM1GQhDajvJgBeiYpgKcojbzZ53d/nz6tXvJw==",
+ "dev": true,
+ "requires": {
+ "cssfontparser": "^1.2.1",
+ "parse-color": "^1.0.0"
+ }
+ },
"jest-changed-files": {
"version": "24.9.0",
"resolved": "https://registry.npmjs.org/jest-changed-files/-/jest-changed-files-24.9.0.tgz",
@@ -12743,6 +12759,23 @@
"safe-buffer": "^5.1.1"
}
},
+ "parse-color": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/parse-color/-/parse-color-1.0.0.tgz",
+ "integrity": "sha1-e3SLlag/A/FqlPU15S1/PZRlhhk=",
+ "dev": true,
+ "requires": {
+ "color-convert": "~0.5.0"
+ },
+ "dependencies": {
+ "color-convert": {
+ "version": "0.5.3",
+ "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-0.5.3.tgz",
+ "integrity": "sha1-vbbGnOZg+t/+CwAHzER+G59ygr0=",
+ "dev": true
+ }
+ }
+ },
"parse-entities": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/parse-entities/-/parse-entities-1.2.2.tgz",
diff --git a/package.json b/package.json
index b5cdc0b71..fc85f2202 100644
--- a/package.json
+++ b/package.json
@@ -110,6 +110,7 @@
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"jest": "^24.9.0",
+ "jest-canvas-mock": "^2.2.0",
"mini-css-extract-plugin": "^0.8.0",
"moment": "^2.19.3",
"moment-locales-webpack-plugin": "^1.0.7",
@@ -216,7 +217,7 @@
"^googleTagManager$": "<rootDir>/web/js/components/util/google-tag-manager.js"
},
"transformIgnorePatterns": [
- "node_modules/(?!(ol)/)"
+ "node_modules/(?!(ol|ol-mapbox-style|@mapbox)/)"
],
"modulePathIgnorePatterns": [
"<rootDir>/build/"
@@ -225,4 +226,4 @@
"prettier": {
"singleQuote": true
}
-}
+}
\ No newline at end of file
diff --git a/test-env.js b/test-env.js
index dc06cfd1f..85b58e763 100644
--- a/test-env.js
+++ b/test-env.js
@@ -1,5 +1,6 @@
import $ from 'jquery';
import fetchMock from 'fetch-mock';
+import 'jest-canvas-mock';
global.$ = global.jQuery = $;
global.fetch = fetchMock;
diff --git a/web/css/modal.css b/web/css/modal.css
index bfba8ebfa..036abb8b8 100644
--- a/web/css/modal.css
+++ b/web/css/modal.css
@@ -46,9 +46,9 @@
/* light modal styling */
.modal-dialog.light .modal-content {
background-color: #dcdcdc;
- color: #000
+ color: #000;
}
-.modal-dialog.light .modal-header{
+.modal-dialog.light .modal-header {
color: #343a40;
}
.modal-dialog.light .modal-header .close {
@@ -57,6 +57,6 @@
.modal-dialog.light .modal-header .close:hover {
color: #000;
}
-.modal-dialog.light .modal-body{
-background: #eee;
-}
\ No newline at end of file
+.modal-dialog.light .modal-body {
+ background: #eee;
+}
diff --git a/web/css/util.css b/web/css/util.css
index 54e57a24a..ae10d1fab 100644
--- a/web/css/util.css
+++ b/web/css/util.css
@@ -210,4 +210,4 @@ button[data-tooltip] {
}
.cursor-pointer {
cursor: pointer;
-}
\ No newline at end of file
+}
diff --git a/web/css/vectorMeta.css b/web/css/vectorMeta.css
index 7ced077a2..d669faabe 100644
--- a/web/css/vectorMeta.css
+++ b/web/css/vectorMeta.css
@@ -57,15 +57,15 @@
.vector-modal .vector-info-icon {
position: absolute;
font-size: 8px;
- border: 1px solid #666666;
+ border: 1px solid #666;
width: 13px;
height: 13px;
text-align: center;
border-radius: 50%;
padding-top: 1px;
margin-right: 10px;
- display:inline-block;
- color: #666666;
+ display: inline-block;
+ color: #666;
}
.vector-modal .vector-info-icon:hover {
diff --git a/web/js/app.js b/web/js/app.js
index ee562e781..cf77ca458 100644
--- a/web/js/app.js
+++ b/web/js/app.js
@@ -5,7 +5,7 @@ import { each as lodashEach } from 'lodash';
import googleTagManager from 'googleTagManager';
// Utils
import util from './util/util';
-import OlCoordinates from './components/map/ol-coordinates';
+import OlCoordinates from './containers/map-interactions';
// Toolbar
import Toolbar from './containers/toolbar';
import Sidebar from './containers/sidebar/sidebar';
diff --git a/web/js/components/map/ol-coordinates.test.js b/web/js/components/map/ol-coordinates.test.js
deleted file mode 100644
index 7a45189c1..000000000
--- a/web/js/components/map/ol-coordinates.test.js
+++ /dev/null
@@ -1,49 +0,0 @@
-import React from 'react';
-import renderer from 'react-test-renderer';
-import util from '../../util/util';
-import OlCoordinates from './ol-coordinates';
-import { registerProjections } from '../../fixtures';
-
-let events;
-let component;
-let map;
-
-beforeEach(() => {
- registerProjections();
- events = util.events();
- component = renderer.create(<OlCoordinates mouseEvents={events}/>);
- map = {
- getEventPixel: jest.fn(),
- getCoordinateFromPixel: () => [0, 0]
- };
-});
-
-afterEach(() => {
- util.setCoordinateFormat('latlon-dd');
-});
-
-test('shows coordinates of (10, 20) when moving the mouse', () => {
- map.getCoordinateFromPixel = () => [10, 20];
- events.trigger('mousemove', {}, map, 'EPSG:4326');
- expect(component.toJSON()).toMatchSnapshot();
-});
-
-test('shows 10°00.000\'N, 20°00.000\'E when set to degrees and minutes format', () => {
- util.setCoordinateFormat('latlon-dm');
- map.getCoordinateFromPixel = () => [10, 20];
- events.trigger('mousemove', {}, map, 'EPSG:4326');
- expect(component.toJSON()).toMatchSnapshot();
-});
-
-test('clears coordinates when mouse moves off the map', () => {
- map.getCoordinateFromPixel = () => [10, 20];
- events.trigger('mousemove', {}, map, 'EPSG:4326');
- events.trigger('mouseout', {}, map, 'EPSG:4326');
- expect(component.toJSON()).toMatchSnapshot();
-});
-
-test('reprojects (0,0) to (-45, 90) for EPSG:3413', () => {
- map.getCoordinateFromPixel = () => [0, 0];
- events.trigger('mousemove', {}, map, 'EPSG:3413');
- expect(component.toJSON()).toMatchSnapshot();
-});
diff --git a/web/js/components/map/__snapshots__/ol-coordinates.test.js.snap b/web/js/containers/__snapshots__/map-interactions.test.js.snap
similarity index 73%
rename from web/js/components/map/__snapshots__/ol-coordinates.test.js.snap
rename to web/js/containers/__snapshots__/map-interactions.test.js.snap
index ee95968c1..063671c57 100644
--- a/web/js/components/map/__snapshots__/ol-coordinates.test.js.snap
+++ b/web/js/containers/__snapshots__/map-interactions.test.js.snap
@@ -2,6 +2,32 @@
exports[`clears coordinates when mouse moves off the map 1`] = `<div />`;
+exports[`if there is a feature at pixel dispatch changeCursor action 1`] = `
+<div>
+ <div
+ className="wv-coords-map wv-coords-map-btn"
+ onClick={[Function]}
+ >
+ <span
+ className="map-coord"
+ >
+ 90.0000°, -45.0000°
+
+ EPSG:3413
+ </span>
+ <div
+ className="coord-btn"
+ >
+ <i
+ className="coord-switch"
+ />
+ </div>
+ </div>
+</div>
+`;
+
+exports[`if there is a feature at pixel on click get dialod 1`] = `null`;
+
exports[`reprojects (0,0) to (-45, 90) for EPSG:3413 1`] = `
<div>
<div
diff --git a/web/js/components/map/ol-coordinates.js b/web/js/containers/map-interactions.js
similarity index 91%
rename from web/js/components/map/ol-coordinates.js
rename to web/js/containers/map-interactions.js
index 3f89521a8..82b731ac8 100644
--- a/web/js/components/map/ol-coordinates.js
+++ b/web/js/containers/map-interactions.js
@@ -1,17 +1,17 @@
import React from 'react';
+import { connect } from 'react-redux';
import PropTypes from 'prop-types';
-import Coordinates from './coordinates';
-import util from '../../util/util';
+import Coordinates from '../components/map/coordinates';
+import util from '../util/util';
import { transform } from 'ol/proj';
-import vectorDialog from '../../containers/vector-dialog';
-import { onMapClickGetVectorFeatures } from '../../modules/vector-styles/util';
-import { openCustomContent } from '../../modules/modal/actions';
-import { selectVectorFeatures } from '../../modules/vector-styles/actions';
-import { connect } from 'react-redux';
+import vectorDialog from './vector-dialog';
+import { onMapClickGetVectorFeatures } from '../modules/vector-styles/util';
+import { openCustomContent } from '../modules/modal/actions';
+import { selectVectorFeatures } from '../modules/vector-styles/actions';
import { groupBy as lodashGroupBy } from 'lodash';
-import { changeCursor } from '../../modules/map/actions';
+import { changeCursor } from '../modules/map/actions';
-class OlCoordinates extends React.Component {
+export class OlCoordinates extends React.Component {
constructor(props) {
super(props);
this.state = {
diff --git a/web/js/containers/map-interactions.test.js b/web/js/containers/map-interactions.test.js
new file mode 100644
index 000000000..7a34411e9
--- /dev/null
+++ b/web/js/containers/map-interactions.test.js
@@ -0,0 +1,84 @@
+import React from 'react';
+import renderer from 'react-test-renderer';
+import util from '../util/util';
+import { OlCoordinates } from './map-interactions';
+import { registerProjections } from '../fixtures';
+
+let events;
+let component;
+let map;
+let changeCursor;
+let selectVectorFeatures;
+let getDialogObject;
+let openVectorDiaglog;
+beforeEach(() => {
+ registerProjections();
+ events = util.events();
+ changeCursor = jest.fn();
+ openVectorDiaglog = jest.fn();
+ selectVectorFeatures = jest.fn();
+ getDialogObject = () => { return { metaArray: [0], selected: [1], offsetLeft: 100, offsetTop: 100 }; };
+ component = renderer.create(
+ <OlCoordinates
+ mouseEvents={events}
+ isShowingClick={false}
+ changeCursor={changeCursor}
+ getDialogObject={getDialogObject}
+ openVectorDiaglog={openVectorDiaglog}
+ selectVectorFeatures={selectVectorFeatures}
+ lastSelected={{}}
+ modalState={{ id: [], isOpen: false }}
+ />
+ );
+ map = {
+ getEventPixel: jest.fn(),
+ getCoordinateFromPixel: () => [0, 0],
+ hasFeatureAtPixel: () => false
+ };
+});
+
+afterEach(() => {
+ util.setCoordinateFormat('latlon-dd');
+});
+
+test('shows coordinates of (10, 20) when moving the mouse', () => {
+ map.getCoordinateFromPixel = () => [10, 20];
+ events.trigger('mousemove', {}, map, 'EPSG:4326');
+ expect(component.toJSON()).toMatchSnapshot();
+ expect(changeCursor.mock.calls.length).toBe(0);
+});
+test('shows 10°00.000\'N, 20°00.000\'E when set to degrees and minutes format', () => {
+ util.setCoordinateFormat('latlon-dm');
+ map.getCoordinateFromPixel = () => [10, 20];
+ events.trigger('mousemove', {}, map, 'EPSG:4326');
+ expect(component.toJSON()).toMatchSnapshot();
+ expect(changeCursor.mock.calls.length).toBe(0);
+});
+
+test('clears coordinates when mouse moves off the map', () => {
+ map.getCoordinateFromPixel = () => [10, 20];
+ events.trigger('mousemove', {}, map, 'EPSG:4326');
+ events.trigger('mouseout', {}, map, 'EPSG:4326');
+ expect(component.toJSON()).toMatchSnapshot();
+ expect(changeCursor.mock.calls.length).toBe(0);
+});
+
+test('reprojects (0,0) to (-45, 90) for EPSG:3413', () => {
+ map.getCoordinateFromPixel = () => [0, 0];
+ events.trigger('mousemove', {}, map, 'EPSG:3413');
+ expect(component.toJSON()).toMatchSnapshot();
+ expect(changeCursor.mock.calls.length).toBe(0);
+});
+test('if there is a feature at pixel dispatch changeCursor action', () => {
+ map.hasFeatureAtPixel = () => true;
+ events.trigger('mousemove', {}, map, 'EPSG:3413');
+ expect(component.toJSON()).toMatchSnapshot();
+ expect(changeCursor.mock.calls.length).toBe(1);
+});
+test('if there is a feature at pixel on click get dialod', () => {
+ events.trigger('singleclick', { pixel: [0, 0] }, map, 'EPSG:4326');
+ expect(component.toJSON()).toMatchSnapshot();
+ expect(changeCursor.mock.calls.length).toBe(0);
+ expect(selectVectorFeatures.mock.calls.length).toBe(1);
+ expect(openVectorDiaglog.mock.calls.length).toBe(1);
+});
diff --git a/web/js/modules/vector-styles/selectors.js b/web/js/modules/vector-styles/selectors.js
index 45101337c..80c8b10e3 100644
--- a/web/js/modules/vector-styles/selectors.js
+++ b/web/js/modules/vector-styles/selectors.js
@@ -10,7 +10,6 @@ import {
import { getMinValue, getMaxValue, selectedStyleFunction } from './util';
import update from 'immutability-helper';
import stylefunction from 'ol-mapbox-style/stylefunction';
-
/**
* Gets a single colormap (entries / legend combo)
*