diff --git a/src/test/suite/dataViewer.test.ts b/src/test/suite/dataViewer.test.ts index 11512dc2f..751a47164 100644 --- a/src/test/suite/dataViewer.test.ts +++ b/src/test/suite/dataViewer.test.ts @@ -1,6 +1,13 @@ import * as assert from 'assert'; import * as vm from 'vm'; -import type { ColDef, ColumnState, GridOptions, GridState, IFilterOptionDef, ITextFilterParams } from 'ag-grid-community'; +import type { + ColDef, + ColumnState, + GridOptions, + GridState, + IFilterOptionDef, + ITextFilterParams, +} from 'ag-grid-community'; import { getDataViewerScript } from '../../dataViewer'; interface SavedViewer { @@ -270,34 +277,49 @@ suite('Data viewer', () => { script.prepareViewerColumns(defs); const params = defs[0].filterParams as ITextFilterParams; assert.deepStrictEqual(Array.from(params.buttons ?? []), ['reset', 'apply']); - assert.deepStrictEqual(Array.from(params.filterOptions ?? [], option => - typeof option === 'string' ? option : option.displayKey - ), ['empty', 'true', 'false', 'blank']); - assert.deepStrictEqual(Array.from(params.filterOptions ?? [], option => - typeof option === 'string' ? option : option.displayName - ), ['empty', 'True', 'False', 'blank']); + assert.deepStrictEqual( + Array.from(params.filterOptions ?? [], (option) => + typeof option === 'string' ? option : option.displayKey, + ), + ['empty', 'true', 'false', 'blank'], + ); + assert.deepStrictEqual( + Array.from(params.filterOptions ?? [], (option) => + typeof option === 'string' ? option : option.displayName, + ), + ['empty', 'True', 'False', 'blank'], + ); // Preserve AG Grid's "Choose one" and "Blank" labels. assert.strictEqual(script.getViewerGridOptions(500).localeText?.empty, undefined); assert.strictEqual(script.getViewerGridOptions(500).localeText?.blank, undefined); }); - for (const [key, expected] of [['true', true], ['false', false]] as const) { + for (const [key, expected] of [ + ['true', true], + ['false', false], + ] as const) { test(`logical ${key} filter matches only its value, excluding NA`, () => { const script = viewerScript().script; const defs: ColDef[] = [{ field: '1', type: 'booleanColumn' }]; script.prepareViewerColumns(defs); const params = defs[0].filterParams as ITextFilterParams; - const option = params.filterOptions?.find((candidate): candidate is IFilterOptionDef => - typeof candidate !== 'string' && candidate.displayKey === key + const option = params.filterOptions?.find( + (candidate): candidate is IFilterOptionDef => + typeof candidate !== 'string' && candidate.displayKey === key, ); assert.ok(option?.predicate); assert.strictEqual(option.numberOfInputs, 0); const predicate = option.predicate; const rows = script.prepareViewerRows( - [true, false, null, undefined].map(value => ({ '1': value })), [] + [true, false, null, undefined].map((value) => ({ '1': value })), + [], + ); + assert.deepStrictEqual( + rows + .filter((row) => Reflect.apply(predicate, undefined, [[], row['1']])) + .map((row) => row['1']), + [expected], ); - assert.deepStrictEqual(rows.filter(row => Reflect.apply(predicate, undefined, [[], row['1']])) - .map(row => row['1']), [expected]); }); }