Skip to content

Commit

Permalink
[chore] test valueAccessor in field (#1906)
Browse files Browse the repository at this point in the history
  • Loading branch information
igorDykhta committed Aug 9, 2022
1 parent f82494d commit 40ac306
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/actions/actions.ts
Expand Up @@ -36,6 +36,7 @@ export type ProtoDataset = {
label?: string;
format?: string;
color?: RGBColor;
type?: string;
};
data: {
fields: {
Expand Down
1 change: 1 addition & 0 deletions src/reducers/vis-state-updaters.ts
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/table-utils/kepler-table.ts
Expand Up @@ -140,7 +140,7 @@ class KeplerTable {
metadata: object;

constructor({
info = {},
info,
data,
color,
metadata,
Expand Down
24 changes: 20 additions & 4 deletions test/helpers/comparison-utils.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

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

0 comments on commit 40ac306

Please sign in to comment.