Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

add final tests

Mike McGann45775c4e9119
diff --git a/test/brand-spec.js b/test/brand-spec.js
deleted file mode 100644
index 1f2f31364..000000000
--- a/test/brand-spec.js
+++ /dev/null
@@ -1,21 +0,0 @@
-buster.testCase('wv.brand', {
-
- 'Is development build': function () {
- buster.refute(wv.brand.release());
- },
-
- 'Is release build': function () {
- this.stub(wv.brand, 'VERSION', '0.0.0');
- buster.assert(wv.brand.release());
- },
-
- 'URL with build nonce': function () {
- buster.assert.equals(wv.brand.url('foo'), 'foo?v=@BUILD_NONCE@');
- },
-
- 'URL build build nonce, existing query string': function () {
- buster.assert.equals(wv.brand.url('foo?bar=1'),
- 'foo?bar=1&v=@BUILD_NONCE@');
- }
-
-});
diff --git a/test/fixtures.js b/test/fixtures.js
deleted file mode 100644
index 803b492ed..000000000
--- a/test/fixtures.js
+++ /dev/null
@@ -1,170 +0,0 @@
-import { dateModel } from '../web/js/date/model';
-import { layersModel } from '../web/js/layers/model';
-import { mapModel } from '../web/js/map/model';
-import { palettesModel } from '../web/js/palettes/model';
-import { projectionModel } from '../web/js/projection/model';
-import { compareModel } from '../web/js/compare/model';
-
-var fixtures = {
- red: 'ff0000ff',
- light_red: 'fff0f0ff',
- dark_red: '400000ff',
- green: '00ff00ff',
- yellow: 'ffff00ff',
- blue: '0000ffff',
- light_blue: 'f0f0ffff',
- dark_blue: '000040'
-};
-
-fixtures.config = function() {
- return {
- defaults: {
- projection: 'geographic'
- },
- projections: {
- geographic: {
- id: 'geographic',
- epsg: 4326,
- crs: 'EPSG:4326',
- maxExtent: [-180, -90, 180, 90]
- },
- arctic: {
- id: 'arctic',
- epsg: 3413,
- crs: 'EPSG:3413'
- },
- antarctic: {
- id: 'antarctic',
- epsg: 3031,
- crs: 'EPSG:3031'
- }
- },
- layers: {
- 'terra-cr': {
- id: 'terra-cr',
- group: 'baselayers',
- period: 'daily',
- startDate: '2000-01-01',
- projections: {
- geographic: {},
- arctic: {},
- antarctic: {}
- }
- },
- 'aqua-cr': {
- id: 'aqua-cr',
- group: 'baselayers',
- period: 'daily',
- startDate: '2002-01-01',
- projections: {
- geographic: {},
- arctic: {},
- antarctic: {}
- }
- },
- mask: {
- id: 'mask',
- group: 'baselayers',
- projections: {
- geographic: {},
- arctic: {},
- antarctic: {}
- }
- },
- 'terra-aod': {
- id: 'terra-aod',
- group: 'overlays',
- period: 'daily',
- startDate: '2000-01-01',
- projections: {
- geographic: {}
- },
- palette: {
- id: 'terra-aod'
- }
- },
- 'aqua-aod': {
- id: 'aqua-aod',
- group: 'overlays',
- period: 'daily',
- startDate: '2002-01-01',
- projections: {
- geographic: {}
- },
- palette: {
- id: 'aqua-aod'
- }
- },
- 'combo-aod': {
- id: 'combo-aod',
- group: 'overlays',
- projections: {
- geographic: {}
- }
- }
- },
- features: {
- compare: true
- },
- palettes: {
- rendered: {
- 'terra-aod': {
- id: 'terra-aod',
- maps: [
- {
- entries: {
- type: 'scale',
- colors: [fixtures.green, fixtures.yellow, fixtures.red],
- values: [0, 1, 2]
- },
- legend: {
- tooltips: ['0', '1', '2'],
- minLabel: '0',
- maxLabel: '2'
- }
- }
- ]
- },
- 'aqua-aod': {
- id: 'aqua-aod',
- maps: [
- {
- entries: {
- type: 'scale',
- colors: [fixtures.green, fixtures.yellow, fixtures.red],
- values: [0, 1, 2]
- },
- legend: {
- tooltips: ['0', '1', '2'],
- minLabel: '0',
- maxLabel: '2'
- }
- }
- ]
- }
- },
- custom: {
- 'blue-1': {
- colors: [fixtures.light_blue, fixtures.blue, fixtures.dark_blue]
- },
- 'red-1': {
- colors: [fixtures.light_red, fixtures.red, fixtures.dark_red]
- }
- }
- }
- };
-};
-
-fixtures.models = function(config) {
- var models = {};
-
- models.proj = projectionModel(config);
- models.layers = layersModel(models, config);
- models.palettes = palettesModel(models, config);
- models.map = mapModel(models, config);
- models.compare = compareModel(models, config);
- models.date = dateModel(models, config);
- return models;
-};
-
-export default fixtures;
diff --git a/test/main.js b/test/main.js
deleted file mode 100644
index 9dee87da6..000000000
--- a/test/main.js
+++ /dev/null
@@ -1,64 +0,0 @@
-// This file is an entry point used to build a testable bundle of the WV core
-// It exposes some internal methods on a global `wv` var for testing purposes
-import underscore from 'underscore';
-import 'babel-polyfill'; // Polyfill fixes a bug in Phantom 2.1.x
-import brand from '../web/js/brand';
-import { parse as dateParser } from '../web/js/date/date';
-import { dateModel } from '../web/js/date/model';
-import { dataParser } from '../web/js/data/data';
-import { dataModel } from '../web/js/data/model';
-import { parse as layerParser } from '../web/js/layers/layers';
-import { layersModel } from '../web/js/layers/model';
-import { linkModel } from '../web/js/link/model';
-import { mapParser } from '../web/js/map/map';
-import { mapModel } from '../web/js/map/model';
-import { MapRunningData } from '../web/js/map/runningdata';
-import palettes from '../web/js/palettes/palettes';
-import { palettesModel } from '../web/js/palettes/model';
-import { parse as projectionParser } from '../web/js/projection/projection';
-import { projectionModel } from '../web/js/projection/model';
-import { projectionChange } from '../web/js/projection/change';
-import ui from '../web/js/ui/ui';
-import uiIndicator from '../web/js/ui/indicator';
-import uiMouse from '../web/js/ui/mouse';
-import util from '../web/js/util/util';
-import fixtures from './fixtures.js';
-
-palettes.model = palettesModel;
-ui.indicator = uiIndicator;
-ui.mouse = uiMouse;
-
-window.wv = {
- brand: brand,
- data: {
- parse: dataParser,
- model: dataModel
- },
- layers: {
- parse: layerParser,
- model: layersModel
- },
- date: {
- parse: dateParser,
- model: dateModel
- },
- link: {
- model: linkModel
- },
- map: {
- parse: mapParser,
- model: mapModel,
- runningdata: MapRunningData
- },
- palettes: palettes,
- proj: {
- parse: projectionParser,
- model: projectionModel,
- change: projectionChange
- },
- ui: ui,
- util: util
-};
-
-window.fixtures = fixtures;
-window._ = underscore;
diff --git a/test/ui/indicator-spec.js b/test/ui/indicator-spec.js
deleted file mode 100644
index 138cab839..000000000
--- a/test/ui/indicator-spec.js
+++ /dev/null
@@ -1,71 +0,0 @@
-buster.testCase('wv.ui.indicator', (function () {
- var self = {};
- self.setUp = function () {
- wv.ui.indicator.active = [];
- };
-
- self['Delayed indicator shown'] = function (done) {
- this.stub(wv.ui.indicator, '_show');
- this.stub(wv.ui.indicator, 'hide');
- var promise = $.Deferred();
- wv.ui.indicator.delayed(promise, 10);
- setTimeout(function () {
- promise.resolve();
- buster.assert.called(wv.ui.indicator._show);
- buster.assert.called(wv.ui.indicator.hide);
- done();
- }, 50);
- };
-
- self['Delayed indicator not shown'] = function (done) {
- this.stub(wv.ui.indicator, '_show');
- this.stub(wv.ui.indicator, 'hide');
- var promise = $.Deferred();
- wv.ui.indicator.delayed(promise, 1000);
- setTimeout(function () {
- promise.resolve();
- buster.refute.called(wv.ui.indicator._show);
- buster.refute.called(wv.ui.indicator.hide);
- done();
- }, 20);
- };
-
- self['Pop message'] = function () {
- this.stub(wv.ui.indicator, '_show');
- this.stub(wv.ui.indicator, '_hide');
-
- wv.ui.indicator.show('Bottom');
- var id = wv.ui.indicator.show('Top');
- wv.ui.indicator.hide(id);
- buster.assert.equals(1, wv.ui.indicator.active.length);
- buster.assert.equals('Bottom', wv.ui.indicator.active[0].message);
- };
-
- self['Remove bottom message'] = function () {
- this.stub(wv.ui.indicator, '_show');
- this.stub(wv.ui.indicator, '_hide');
-
- var id = wv.ui.indicator.show('Bottom');
- wv.ui.indicator.show('Top');
- wv.ui.indicator.hide(id);
- buster.assert.equals(1, wv.ui.indicator.active.length);
- buster.assert.equals('Top', wv.ui.indicator.active[0].message);
- };
-
- self['Hide group'] = function () {
- this.stub(wv.ui.indicator, '_show');
- this.stub(wv.ui.indicator, '_hide');
- var indicators = {
- two: null,
- three: null
- };
- wv.ui.indicator.show('One');
- indicators.two = wv.ui.indicator.show('Two');
- indicators.three = wv.ui.indicator.show('Three');
- wv.ui.indicator.hide(indicators);
- buster.assert.equals(1, wv.ui.indicator.active.length);
- buster.assert.equals('One', wv.ui.indicator.active[0].message);
- };
-
- return self;
-}()));
diff --git a/test/ui/mouse-spec.js b/test/ui/mouse-spec.js
deleted file mode 100644
index edc863629..000000000
--- a/test/ui/mouse-spec.js
+++ /dev/null
@@ -1,45 +0,0 @@
-buster.testCase('wv.ui.mouse.click', (function () {
- var self = {};
- var element, down, up;
-
- self.setUp = function () {
- element = {
- mousedown: function (handler) {
- down = handler;
- },
- mouseup: function (handler) {
- up = handler;
- }
- };
- };
-
- self['Within click limit'] = function () {
- var callback = this.stub();
- wv.ui.mouse.click(element, callback);
- down({
- clientX: 0,
- clientY: 0
- });
- up({
- clientX: 2,
- clientY: 2
- });
- buster.assert.called(callback);
- };
-
- self['Outside click limit'] = function () {
- var callback = this.stub();
- wv.ui.mouse.click(element, callback);
- down({
- clientX: 0,
- clientY: 0
- });
- up({
- clientX: 12,
- clientY: 12
- });
- buster.refute.called(callback);
- };
-
- return self;
-}()));
diff --git a/web/js/brand.test.js b/web/js/brand.test.js
new file mode 100644
index 000000000..da6568500
--- /dev/null
+++ b/web/js/brand.test.js
@@ -0,0 +1,28 @@
+import brand from './brand';
+
+let unmocked = {};
+
+beforeAll(() => {
+ unmocked.VERSION = brand.VERSION;
+});
+
+afterEach(() => {
+ brand.VERSION = unmocked.VERSION;
+});
+
+test('is development build', () => {
+ expect(brand.release()).toBeFalsy();
+});
+
+test('is release build', () => {
+ brand.VERSION = '0.0.0';
+ expect(brand.release()).toBeTruthy();
+});
+
+test('URL with build nonce', () => {
+ expect(brand.url('foo')).toBe('foo?v=@BUILD_NONCE@');
+});
+
+test('URL build build nonce, existing query string', () => {
+ expect(brand.url('foo?bar=1')).toBe('foo?bar=1&v=@BUILD_NONCE@');
+});
diff --git a/web/js/ui/indicator.test.js b/web/js/ui/indicator.test.js
new file mode 100644
index 000000000..c01ba2d5c
--- /dev/null
+++ b/web/js/ui/indicator.test.js
@@ -0,0 +1,85 @@
+import jQuery from 'jquery';
+import indicator from './indicator';
+
+let unmocked = {};
+
+beforeAll(() => {
+ unmocked._show = indicator._show;
+ unmocked._hide = indicator._hide;
+ unmocked.hide = indicator.hide;
+});
+
+beforeEach(() => { indicator.active = []; });
+
+afterEach(() => {
+ indicator._show = unmocked._show;
+ indicator._hide = unmocked._hide;
+ indicator.hide = unmocked.hide;
+});
+
+test('delayed indicator shown', (done) => {
+ indicator._show = jest.fn();
+ indicator.hide = jest.fn();
+ let promise = jQuery.Deferred();
+ indicator.delayed(promise, 10);
+ setTimeout(function () {
+ promise.resolve();
+ expect(indicator._show).toBeCalled();
+ expect(indicator.hide).toBeCalled();
+ done();
+ }, 50);
+});
+
+test('delayed indicator not shown', (done) => {
+ indicator._show = jest.fn();
+ indicator.hide = jest.fn();
+ let promise = jQuery.Deferred();
+ indicator.delayed(promise, 1000);
+ setTimeout(function () {
+ promise.resolve();
+ expect(indicator._show).not.toBeCalled();
+ expect(indicator.hide).not.toBeCalled();
+ done();
+ }, 50);
+});
+
+test('pop message', () => {
+ indicator._show = jest.fn();
+ indicator._hide = jest.fn();
+
+ indicator.show('Bottom');
+ let id = indicator.show('Top');
+ indicator.hide(id);
+
+ expect(indicator.active).toHaveLength(1);
+ expect(indicator.active[0].message).toBe('Bottom');
+});
+
+test('remove bottom message', () => {
+ indicator._show = jest.fn();
+ indicator._hide = jest.fn();
+
+ let id = indicator.show('Bottom');
+ indicator.show('Top');
+ indicator.hide(id);
+
+ expect(indicator.active).toHaveLength(1);
+ expect(indicator.active[0].message).toBe('Top');
+});
+
+test('hide group', () => {
+ indicator._show = jest.fn();
+ indicator._hide = jest.fn();
+
+ let indicators = {
+ two: null,
+ three: null
+ };
+ indicator.show('One');
+ indicators.two = indicator.show('Two');
+ indicators.three = indicator.show('Three');
+ indicator.hide(indicators);
+
+ expect(indicator.active).toHaveLength(1);
+ expect(indicator.active[0].message).toBe('One');
+});
diff --git a/web/js/ui/mouse.js b/web/js/ui/mouse.js
index 3a66f4f2c..026061f9b 100644
--- a/web/js/ui/mouse.js
+++ b/web/js/ui/mouse.js
@@ -2,39 +2,6 @@ import util from '../util/util';
import d3 from 'd3';
export default {
- click: function ($element, callback) {
- var self = {};
- self.sensitivity = 5; // pixels
-
- var startX, startY;
-
- var init = function () {
- $element.mousedown(mousedown);
- $element.mouseup(mouseup);
- };
-
- var mousedown = function (event) {
- startX = event.clientX;
- startY = event.clientY;
- };
-
- var mouseup = function (event) {
- if (withinClickDistance(event)) {
- callback.call(this);
- }
- };
-
- var withinClickDistance = function (event) {
- var targetX = event.clientX;
- var targetY = event.clientY;
- var distance = Math.sqrt(Math.pow(startX - targetX, 2) +
- Math.pow(startY - targetY, 2));
- return distance <= self.sensitivity;
- };
-
- init();
- return self;
- },
wheel: function (element, ui, options) {
options = options || {};