Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

add palette tests

Benjamin Kingb8fbc595face
diff --git a/web/js/fixtures.js b/web/js/fixtures.js
index 99bdaab25..fd61d821c 100644
--- a/web/js/fixtures.js
+++ b/web/js/fixtures.js
@@ -1,6 +1,7 @@
import proj4 from 'proj4';
import { register } from 'ol/proj/proj4';
-
+import { initialState as initialLayerState } from './modules/layers/reducers';
+import { initialCompareState } from './modules/compare/reducers';
var fixtures = {
red: 'ff0000ff',
light_red: 'fff0f0ff',
@@ -11,6 +12,61 @@ var fixtures = {
light_blue: 'f0f0ffff',
dark_blue: '000040'
};
+fixtures.getState = function() {
+ return {
+ compare: initialCompareState,
+ config: fixtures.config(),
+ layers: initialLayerState,
+ palettes: {
+ active: {},
+ activeB: {},
+ 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.config = function() {
return {
diff --git a/web/js/modules/palettes/util.test.js b/web/js/modules/palettes/util.test.js
new file mode 100644
index 000000000..54ff15516
--- /dev/null
+++ b/web/js/modules/palettes/util.test.js
@@ -0,0 +1,37 @@
+import update from 'immutability-helper';
+import { layersParse12 } from '../layers/util';
+import { hasCustomTypePalette, loadPalettes } from './util';
+import util from '../../util/util';
+import fixtures from '../../fixtures';
+const state = fixtures.getState();
+const config = fixtures.config();
+const LAYER_STRING =
+ 'terra-aod(hidden,opacity=0.54,palette=red-1,min=1,max=2,squash=true),mask';
+const layerArrayFromPermalinkString = layersParse12(LAYER_STRING, config);
+const PERMALINK_STATE = { l: LAYER_STRING };
+
+test('hasCustomTypePalette func determines if custom palette is in string', () => {
+ const bool = hasCustomTypePalette(
+ 'terra-aod(hidden,opacity=0.54,palette=red-1,min=1,max=2,squash=true)'
+ );
+ expect(bool).toBeTruthy();
+});
+test('loadPalettes func updates state with correct palette attributes', () => {
+ util.browser = jest.fn(() => {
+ return {
+ webWorkers: true,
+ ie: false,
+ cors: true
+ };
+ })();
+ const updatedState = update(state, {
+ layers: { active: { $set: layerArrayFromPermalinkString } }
+ });
+
+ const loadedState = loadPalettes(PERMALINK_STATE, updatedState);
+
+ const colorMap = loadedState.palettes.active['terra-aod'].maps[0];
+ expect(colorMap.min).toEqual(1);
+ expect(colorMap.custom).toEqual('red-1');
+ expect(colorMap.squash).toEqual(true);
+});