Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

add tests for coordinate display

Mike McGann470f5154c04e
diff --git a/web/js/components/map/__snapshots__/coordinates.test.js.snap b/web/js/components/map/__snapshots__/coordinates.test.js.snap
index ad719c1c2..635f7cae4 100644
--- a/web/js/components/map/__snapshots__/coordinates.test.js.snap
+++ b/web/js/components/map/__snapshots__/coordinates.test.js.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`formats latlon-dd 1`] = `
+exports[`formats coordinate in latlon-dd format 1`] = `
<div
className="wv-coords-map wv-coords-map-btn"
onClick={[Function]}
@@ -22,7 +22,7 @@ exports[`formats latlon-dd 1`] = `
</div>
`;
-exports[`formats latlon-dm 1`] = `
+exports[`formats coordinate in latlon-dm format 1`] = `
<div
className="wv-coords-map wv-coords-map-btn"
onClick={[Function]}
@@ -44,7 +44,7 @@ exports[`formats latlon-dm 1`] = `
</div>
`;
-exports[`formats latlon-dms 1`] = `
+exports[`formats coordinate in latlon-dms format 1`] = `
<div
className="wv-coords-map wv-coords-map-btn"
onClick={[Function]}
diff --git a/web/js/components/map/__snapshots__/ol-coordinates.test.js.snap b/web/js/components/map/__snapshots__/ol-coordinates.test.js.snap
index acc8c4110..80abe5bd8 100644
--- a/web/js/components/map/__snapshots__/ol-coordinates.test.js.snap
+++ b/web/js/components/map/__snapshots__/ol-coordinates.test.js.snap
@@ -1,6 +1,58 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`mouse move 1`] = `
+exports[`clears coordinates when mouse moves off the map 1`] = `<div />`;
+
+exports[`does not display on small devices 1`] = `null`;
+
+exports[`reprojects (0,0) to (-45, 90) for EPSG:3413 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[`shows 10°00.000'N, 20°00.000'E when set to degrees and minutes format 1`] = `
+<div>
+ <div
+ className="wv-coords-map wv-coords-map-btn"
+ onClick={[Function]}
+ >
+ <span
+ className="map-coord"
+ >
+ 20°00.000'N, 10°00.000'E
+
+ EPSG:4326
+ </span>
+ <div
+ className="coord-btn"
+ >
+ <i
+ className="coord-switch"
+ />
+ </div>
+ </div>
+</div>
+`;
+
+exports[`shows coordinates of (10, 20) when moving the mouse 1`] = `
<div>
<div
className="wv-coords-map wv-coords-map-btn"
@@ -9,7 +61,7 @@ exports[`mouse move 1`] = `
<span
className="map-coord"
>
- 10.0000°, 20.0000°
+ 20.0000°, 10.0000°
EPSG:4326
</span>
diff --git a/web/js/components/map/coordinates.test.js b/web/js/components/map/coordinates.test.js
index 0608a0978..1c8988fd0 100644
--- a/web/js/components/map/coordinates.test.js
+++ b/web/js/components/map/coordinates.test.js
@@ -5,7 +5,7 @@ import Coordinates from './coordinates';
describe('formats', () => {
let formats = ['latlon-dd', 'latlon-dm', 'latlon-dms'];
for (let format of formats) {
- test(format, () => {
+ test(`coordinate in ${format} format`, () => {
let component = renderer.create(<Coordinates
format={format}
latitude={0}
@@ -18,7 +18,7 @@ describe('formats', () => {
}
});
-test('change format', () => {
+test('change format from latlon-dd to latlon-dm', () => {
let callback = jest.fn();
let component = renderer.create(<Coordinates
format='latlon-dd'
diff --git a/web/js/components/map/ol-coordinates.js b/web/js/components/map/ol-coordinates.js
index 08e46a9c0..b96bf3122 100644
--- a/web/js/components/map/ol-coordinates.js
+++ b/web/js/components/map/ol-coordinates.js
@@ -42,8 +42,8 @@ class OlCoordinates extends React.Component {
this.setState({
format: util.getCoordinateFormat(),
- latitude: pcoord[0],
- longitude: pcoord[1],
+ latitude: pcoord[1],
+ longitude: pcoord[0],
crs
});
}
diff --git a/web/js/components/map/ol-coordinates.test.js b/web/js/components/map/ol-coordinates.test.js
index 17b290693..3f2536dbb 100644
--- a/web/js/components/map/ol-coordinates.test.js
+++ b/web/js/components/map/ol-coordinates.test.js
@@ -2,16 +2,55 @@ import React from 'react';
import renderer from 'react-test-renderer';
import util from '../../util/util';
import OlCoordinates from './ol-coordinates';
+import { registerProjections } from '../../fixtures';
-test('mouse move', () => {
- util.browser.small = false;
- let events = util.events();
- let component = renderer.create(<OlCoordinates mouseEvents={events}/>);
- let map = {
+let events;
+let component;
+let map;
+
+beforeEach(() => {
+ registerProjections();
+ events = util.events();
+ component = renderer.create(<OlCoordinates mouseEvents={events}/>);
+ map = {
getEventPixel: jest.fn(),
- getCoordinateFromPixel: () => [10, 20]
+ getCoordinateFromPixel: () => [0, 0]
};
+});
+
+afterEach(() => {
+ util.setCoordinateFormat('latlon-dd');
+ util.browser.small = false;
+});
+
+test('shows coordinates of (10, 20) when moving the mouse', () => {
+ map.getCoordinateFromPixel = () => [10, 20];
events.trigger('mousemove', {}, map, 'EPSG:4326');
- let tree = component.toJSON();
- expect(tree).toMatchSnapshot();
+ 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();
+});
+
+test('does not display on small devices', () => {
+ util.browser.small = true;
+ events.trigger('mousemove', {}, map, 'EPSG:3413');
+ expect(component.toJSON()).toMatchSnapshot();
});
diff --git a/web/js/fixtures.js b/web/js/fixtures.js
index 83b1a3741..2300b9b65 100644
--- a/web/js/fixtures.js
+++ b/web/js/fixtures.js
@@ -1,3 +1,6 @@
+import proj4 from 'proj4';
+import { register } from 'ol/proj/proj4';
+
import { dateModel } from './date/model';
import { layersModel } from './layers/model';
import { mapModel } from './map/model';
@@ -167,4 +170,10 @@ fixtures.models = function(config) {
return models;
};
+export function registerProjections() {
+ proj4.defs('EPSG:3413', '+title=WGS 84 / NSIDC Sea Ice Polar Stereographic North +proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs');
+ proj4.defs('EPSG:3031', '+title=WGS 84 / Antarctic Polar Stereographic +proj=stere +lat_0=-90 +lat_ts=-71 +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs');
+ register(proj4);
+}
+
export default fixtures;
diff --git a/web/js/util/browser.js b/web/js/util/browser.js
index e77bd9a89..3b6a8917e 100644
--- a/web/js/util/browser.js
+++ b/web/js/util/browser.js
@@ -198,6 +198,12 @@ export default (function() {
};
self.tests.small = function() {
+ let dim = self.tests.getWindowDimensions();
+ // If the dimensions are (0,0), this is not being run in a real browser
+ // so assume desktop mode unless otherwise changed.
+ if (dim[0] === 0 && dim[1] === 0) {
+ return false;
+ }
return self.tests.getWindowDimensions()[0] < self.mobileWidth;
};