Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[chore] Consolidate vis state tests (#2869)

Igor Dykhtab89b19c6a83d
diff --git a/src/layers/src/base-layer.ts b/src/layers/src/base-layer.ts
index 35a507e6b..b9c232cf4 100644
--- a/src/layers/src/base-layer.ts
+++ b/src/layers/src/base-layer.ts
@@ -44,6 +44,7 @@ import {
import {generateHashId, toArray, notNullorUndefined} from '@kepler.gl/common-utils';
import {Datasets, GpuFilter, KeplerTable} from '@kepler.gl/table';
import {
+ AggregatedBin,
ColorRange,
ColorUI,
Field,
@@ -80,13 +81,7 @@ import {
getThresholdsFromQuantiles
} from '@kepler.gl/utils';
-export type {
- LayerBaseConfig,
- VisualChannel,
- VisualChannels,
- VisualChannelDomain,
- AggregatedBin
-} from '@kepler.gl/types';
+export type {LayerBaseConfig, VisualChannel, VisualChannels, VisualChannelDomain, AggregatedBin};
export type VisualChannelField = Field | null;
export type VisualChannelScale = keyof typeof SCALE_TYPES;
diff --git a/test/helpers/mock-state.js b/test/helpers/mock-state.js
index 1d5e752dd..5b3feef4b 100644
--- a/test/helpers/mock-state.js
+++ b/test/helpers/mock-state.js
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
-import test from 'tape-catch';
+// @ts-nocheck
+
import cloneDeep from 'lodash.clonedeep';
import {colorPaletteToColorRange} from '@kepler.gl/constants';
import {
@@ -86,6 +87,18 @@ export const geojsonInfo = {
params: {file: null}
};
+export const mockColorRange = {
+ colors: ['#FF000', '#00FF00', '#0000FF'],
+ colorMap: [
+ [1, '#FF0000'],
+ [3, '#00FF00'],
+ [5, '#0000FF']
+ ],
+ colorLegends: {
+ '#FF0000': 'hello'
+ }
+};
+
// TODO: need to be deleted and imported from raw-states
export const InitialState = keplerGlReducer(undefined, {});
@@ -126,27 +139,12 @@ export function mockStateWithFileUpload() {
);
});
- test(t => {
- t.equal(updatedState.visState.layers.length, 2, 'should auto create 2 layers');
- t.end();
- });
-
return updatedState;
}
function mockStateWithLayerCustomColorBreaksLegends() {
const initialState = cloneDeep(InitialState);
- const mockColorRange = {
- colors: ['#FF000', '#00FF00', '#0000FF'],
- colorMap: [
- [1, '#FF0000'],
- [3, '#00FF00'],
- [5, '#0000FF']
- ],
- colorLegends: {
- '#FF0000': 'hello'
- }
- };
+
// load csv and geojson
const updatedState = applyActions(keplerGlReducer, initialState, [
{
@@ -201,28 +199,6 @@ function mockStateWithLayerCustomColorBreaksLegends() {
}
]);
- test(t => {
- t.equal(updatedState.visState.layers.length, 1, 'should load 1 layer');
- t.deepEqual(
- updatedState.visState.layers[0].config.visConfig.colorRange,
- mockColorRange,
- 'should load layer colorRange correctly'
- );
- t.deepEqual(
- updatedState.visState.layers[0].config.colorScale,
- 'custom',
- 'should load layer color Scale correctly'
- );
-
- t.deepEqual(
- updatedState.visState.layers[0].config.colorField.name,
- 'uid',
- 'should load colorField correctly'
- );
-
- t.end();
- });
-
return updatedState;
}
@@ -337,12 +313,6 @@ export function mockStateWithTripTable(state) {
}
]);
- test(t => {
- t.equal(updatedState.visState.layers.length, 1, 'should create 1 trip layer');
- t.equal(updatedState.visState.layers[0].type, 'trip', 'should create trip layer');
- t.end();
- });
-
return updatedState;
}
@@ -360,14 +330,6 @@ export function mockStateWithArcNeighbors(state) {
}
]);
- test(t => {
- t.equal(updatedState.visState.layers.length, 3, 'should create 3 layers');
- t.equal(updatedState.visState.layers[0].type, 'point', 'should create point layer');
- t.equal(updatedState.visState.layers[1].type, 'arc', 'should create arc layer');
- t.equal(updatedState.visState.layers[2].type, 'arc', 'should create arc layer');
- t.end();
- });
-
return updatedState;
}
diff --git a/test/node/schemas/vis-state-schema-test.js b/test/node/schemas/vis-state-schema-test.js
index f3434f716..fcb6e051b 100644
--- a/test/node/schemas/vis-state-schema-test.js
+++ b/test/node/schemas/vis-state-schema-test.js
@@ -7,18 +7,22 @@ import {cmpFilters, cmpSavedLayers} from 'test/helpers/comparison-utils';
import SchemaManager, {CURRENT_VERSION, visStateSchema} from '@kepler.gl/schemas';
import {
+ StateWArcNeighbors,
+ StateWEffects,
StateWFiles,
StateWFilesFiltersLayerColor,
- StateWEffects,
+ StateWLayerCustomColorBreaks,
StateWTooltipFormat,
+ StateWTripGeojson,
+ StateWTripTable,
expectedSavedLayer0,
expectedLoadedLayer0,
expectedSavedLayer1,
expectedLoadedLayer1,
expectedSavedLayer2,
expectedLoadedLayer2,
- StateWTripGeojson,
expectedSavedTripLayer,
+ mockColorRange,
testCsvDataId,
testGeoJsonDataId
} from 'test/helpers/mock-state';
@@ -441,3 +445,48 @@ test('#visStateSchema -> v1 -> save load effects (deprecated beta config)', t =>
t.end();
});
+
+test('#visStateSchema -> auto create layers', t => {
+ const state = cloneDeep(StateWFiles);
+ t.equal(state.visState.layers.length, 2, 'should auto create 2 layers');
+ t.end();
+});
+
+test('#visStateSchema -> color properties', t => {
+ const state = cloneDeep(StateWLayerCustomColorBreaks);
+ t.equal(state.visState.layers.length, 1, 'should load 1 layer');
+ t.deepEqual(
+ state.visState.layers[0].config.visConfig.colorRange,
+ mockColorRange,
+ 'should load layer colorRange correctly'
+ );
+ t.deepEqual(
+ state.visState.layers[0].config.colorScale,
+ 'custom',
+ 'should load layer color Scale correctly'
+ );
+
+ t.deepEqual(
+ state.visState.layers[0].config.colorField.name,
+ 'uid',
+ 'should load colorField correctly'
+ );
+
+ t.end();
+});
+
+test('#visStateSchema -> create trip layers', t => {
+ const state = cloneDeep(StateWTripTable);
+ t.equal(state.visState.layers.length, 1, 'should create 1 trip layer');
+ t.equal(state.visState.layers[0].type, 'trip', 'should create trip layer');
+ t.end();
+});
+
+test('#visStateSchema -> create point and arc layers', t => {
+ const state = cloneDeep(StateWArcNeighbors);
+ t.equal(state.visState.layers.length, 3, 'should create 3 layers');
+ t.equal(state.visState.layers[0].type, 'point', 'should create point layer');
+ t.equal(state.visState.layers[1].type, 'arc', 'should create arc layer');
+ t.equal(state.visState.layers[2].type, 'arc', 'should create arc layer');
+ t.end();
+});