Skip to content

[chore] Consolidate vis state tests #2869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
Loading