Skip to content
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

[chore] test valueAccessor in field #1906

Merged
merged 3 commits into from
Aug 9, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
3 changes: 2 additions & 1 deletion src/utils/table-utils/kepler-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class KeplerTable {
metadata: object;

constructor({
info = {},
info,
data,
color,
metadata,
Expand Down Expand Up @@ -195,6 +195,7 @@ class KeplerTable {
};

this.id = datasetInfo.id;
this.type = datasetInfo.type;
this.label = datasetInfo.label;
this.color = color;
this.metadata = {
Expand Down
24 changes: 20 additions & 4 deletions test/helpers/comparison-utils.js
Original file line number Diff line number Diff line change
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 @@ -353,14 +354,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 @@ -385,7 +386,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