|
1 | 1 | import * as assert from 'assert'; |
2 | 2 | import * as vm from 'vm'; |
3 | | -import type { ColDef, ColumnState, GridOptions, GridState, IFilterOptionDef, ITextFilterParams } from 'ag-grid-community'; |
| 3 | +import type { |
| 4 | + ColDef, |
| 5 | + ColumnState, |
| 6 | + GridOptions, |
| 7 | + GridState, |
| 8 | + IFilterOptionDef, |
| 9 | + ITextFilterParams, |
| 10 | +} from 'ag-grid-community'; |
4 | 11 | import { getDataViewerScript } from '../../dataViewer'; |
5 | 12 |
|
6 | 13 | interface SavedViewer { |
@@ -270,34 +277,49 @@ suite('Data viewer', () => { |
270 | 277 | script.prepareViewerColumns(defs); |
271 | 278 | const params = defs[0].filterParams as ITextFilterParams; |
272 | 279 | assert.deepStrictEqual(Array.from(params.buttons ?? []), ['reset', 'apply']); |
273 | | - assert.deepStrictEqual(Array.from(params.filterOptions ?? [], option => |
274 | | - typeof option === 'string' ? option : option.displayKey |
275 | | - ), ['empty', 'true', 'false', 'blank']); |
276 | | - assert.deepStrictEqual(Array.from(params.filterOptions ?? [], option => |
277 | | - typeof option === 'string' ? option : option.displayName |
278 | | - ), ['empty', 'True', 'False', 'blank']); |
| 280 | + assert.deepStrictEqual( |
| 281 | + Array.from(params.filterOptions ?? [], (option) => |
| 282 | + typeof option === 'string' ? option : option.displayKey, |
| 283 | + ), |
| 284 | + ['empty', 'true', 'false', 'blank'], |
| 285 | + ); |
| 286 | + assert.deepStrictEqual( |
| 287 | + Array.from(params.filterOptions ?? [], (option) => |
| 288 | + typeof option === 'string' ? option : option.displayName, |
| 289 | + ), |
| 290 | + ['empty', 'True', 'False', 'blank'], |
| 291 | + ); |
279 | 292 | // Preserve AG Grid's "Choose one" and "Blank" labels. |
280 | 293 | assert.strictEqual(script.getViewerGridOptions(500).localeText?.empty, undefined); |
281 | 294 | assert.strictEqual(script.getViewerGridOptions(500).localeText?.blank, undefined); |
282 | 295 | }); |
283 | 296 |
|
284 | | - for (const [key, expected] of [['true', true], ['false', false]] as const) { |
| 297 | + for (const [key, expected] of [ |
| 298 | + ['true', true], |
| 299 | + ['false', false], |
| 300 | + ] as const) { |
285 | 301 | test(`logical ${key} filter matches only its value, excluding NA`, () => { |
286 | 302 | const script = viewerScript().script; |
287 | 303 | const defs: ColDef[] = [{ field: '1', type: 'booleanColumn' }]; |
288 | 304 | script.prepareViewerColumns(defs); |
289 | 305 | const params = defs[0].filterParams as ITextFilterParams; |
290 | | - const option = params.filterOptions?.find((candidate): candidate is IFilterOptionDef => |
291 | | - typeof candidate !== 'string' && candidate.displayKey === key |
| 306 | + const option = params.filterOptions?.find( |
| 307 | + (candidate): candidate is IFilterOptionDef => |
| 308 | + typeof candidate !== 'string' && candidate.displayKey === key, |
292 | 309 | ); |
293 | 310 | assert.ok(option?.predicate); |
294 | 311 | assert.strictEqual(option.numberOfInputs, 0); |
295 | 312 | const predicate = option.predicate; |
296 | 313 | const rows = script.prepareViewerRows( |
297 | | - [true, false, null, undefined].map(value => ({ '1': value })), [] |
| 314 | + [true, false, null, undefined].map((value) => ({ '1': value })), |
| 315 | + [], |
| 316 | + ); |
| 317 | + assert.deepStrictEqual( |
| 318 | + rows |
| 319 | + .filter((row) => Reflect.apply(predicate, undefined, [[], row['1']])) |
| 320 | + .map((row) => row['1']), |
| 321 | + [expected], |
298 | 322 | ); |
299 | | - assert.deepStrictEqual(rows.filter(row => Reflect.apply(predicate, undefined, [[], row['1']])) |
300 | | - .map(row => row['1']), [expected]); |
301 | 323 | }); |
302 | 324 | } |
303 | 325 |
|
|
0 commit comments