Skip to content

Commit

Permalink
[chore] Consolidate vis state tests (#2869)
Browse files Browse the repository at this point in the history
- fix for jest test ran into an issue where warnings were showing up about logging after a test was finished

Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
  • Loading branch information
igorDykhta authored Dec 28, 2024
1 parent 77e7857 commit b89b19c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 62 deletions.
9 changes: 2 additions & 7 deletions src/layers/src/base-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
68 changes: 15 additions & 53 deletions test/helpers/mock-state.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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, {});

Expand Down Expand Up @@ -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, [
{
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
53 changes: 51 additions & 2 deletions test/node/schemas/vis-state-schema-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
});

0 comments on commit b89b19c

Please sign in to comment.