Skip to content

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

[chore] test valueAccessor in field (#1906)

Igor Dykhta40ac306847ca
diff --git a/src/actions/actions.ts b/src/actions/actions.ts
index 7dbdb87ba..434ee8f9e 100644
--- a/src/actions/actions.ts
+++ b/src/actions/actions.ts
@@ -36,6 +36,7 @@ export type ProtoDataset = {
label?: string;
format?: string;
color?: RGBColor;
+ type?: string;
};
data: {
fields: {
diff --git a/src/reducers/vis-state-updaters.ts b/src/reducers/vis-state-updaters.ts
index 1894a3f46..76fdfe848 100644
--- a/src/reducers/vis-state-updaters.ts
+++ b/src/reducers/vis-state-updaters.ts
@@ -104,6 +104,7 @@ import {LoaderObject} from '@loaders.gl/loader-utils';
import {KeplerTable} from '../utils';
export {KeplerTable};
+
export type HistogramBin = {
x0: number | undefined;
x1: number | undefined;
diff --git a/src/utils/table-utils/kepler-table.ts b/src/utils/table-utils/kepler-table.ts
index 973a20f7e..4453076ed 100644
--- a/src/utils/table-utils/kepler-table.ts
+++ b/src/utils/table-utils/kepler-table.ts
@@ -140,7 +140,7 @@ class KeplerTable {
metadata: object;
constructor({
- info = {},
+ info,
data,
color,
metadata,
diff --git a/test/helpers/comparison-utils.js b/test/helpers/comparison-utils.js
index 3865c3686..5d4c98a45 100644
--- a/test/helpers/comparison-utils.js
+++ b/test/helpers/comparison-utils.js
@@ -20,6 +20,7 @@
import {FILTER_TYPES} from '@kepler.gl/constants';
import {toArray} from '../../src/utils/utils';
+import {getFieldValueAccessor} from '../../src/utils';
import KeplerTable from '../../src/utils/table-utils/kepler-table';
export function cmpObjectKeys(t, expectedObj, actualObj, name) {
@@ -355,14 +356,14 @@ export function cmpParsedAppConfigs(t, expectedConfig, actualConfig, {name = ''}
});
}
-export function cmpFields(t, expected, actual, name) {
+export function cmpFields(t, expected, actual, name, opt = {}) {
t.equal(expected.length, actual.length, `dataset.${name} should have same number of fields`);
actual.forEach((actualField, i) => {
- cmpField(t, expected[i], actualField, `dataset.${name} fields ${actualField.name}`);
+ cmpField(t, expected[i], actualField, `dataset.${name} fields ${actualField.name}`, opt);
});
}
-export function cmpField(t, expected, actual, name) {
+export function cmpField(t, expected, actual, name, opt = {}) {
if (expected && actual) {
cmpObjectKeys(t, expected, actual, name);
@@ -387,7 +388,22 @@ export function cmpField(t, expected, actual, name) {
});
}
} else if (k === 'valueAccessor') {
- t.ok(typeof actual[k] === 'function', `${name}.valueAccessor should be a function`);
+ // compare value accessor
+ if (opt.dataset) {
+ // test valueAccessor with first value
+
+ t.equal(
+ actual.valueAccessor(opt.dataset.dataContainer.rowAsArray(0)),
+ getFieldValueAccessor(
+ expected,
+ expected.fieldIdx
+ )(opt.dataset.dataContainer.rowAsArray(0)),
+ `${name} have correct valueAccessor function`
+ );
+ } else {
+ // assert it is a
+ t.ok(typeof actual[k] === 'function', `${name}.valueAccessor should be a function`);
+ }
} else {
t.deepEqual(actual[k], expected[k], `${name}.${k} should be the same`);
}