mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-06 19:25:02 +00:00
fix: export colmn
This commit is contained in:
@@ -2,6 +2,7 @@ import {
|
||||
EXPORT_MIME,
|
||||
formatRowCap,
|
||||
pickByKey,
|
||||
pickDatasetFields,
|
||||
resolveExportFormat,
|
||||
resolveRowLimit,
|
||||
} from './export-request.util';
|
||||
@@ -85,3 +86,48 @@ describe('pickByKey', () => {
|
||||
expect(pickByKey(columns, 'ghost,also-ghost')).toEqual(columns);
|
||||
});
|
||||
});
|
||||
|
||||
describe('pickDatasetFields', () => {
|
||||
const fields = [
|
||||
{ key: 'name', label: 'Company', default: true },
|
||||
{ key: 'tin', label: 'TIN', default: true },
|
||||
{ key: 'website', label: 'Website' },
|
||||
{ key: 'kebele', label: 'Kebele' },
|
||||
];
|
||||
const defaults = [fields[0], fields[1]];
|
||||
|
||||
it.each([undefined, '', ' ', ','])('%p means the default fields', (raw) => {
|
||||
expect(pickDatasetFields(fields, raw)).toEqual(defaults);
|
||||
});
|
||||
|
||||
it('a subset is honoured, in the dataset\'s own order', () => {
|
||||
expect(pickDatasetFields(fields, 'kebele,name')).toEqual([fields[0], fields[3]]);
|
||||
});
|
||||
|
||||
it('asking for EVERY field exports every field', () => {
|
||||
// The dialog's "All columns" chip sends exactly this. Falling back to the
|
||||
// defaults here was the bug: 37 ticked customer columns exported as 9.
|
||||
expect(pickDatasetFields(fields, 'name,tin,website,kebele')).toEqual(fields);
|
||||
});
|
||||
|
||||
it('a non-default field alone is not widened back to the defaults', () => {
|
||||
expect(pickDatasetFields(fields, 'website')).toEqual([fields[2]]);
|
||||
});
|
||||
|
||||
it('unknown keys are dropped, the recognised ones still stand', () => {
|
||||
expect(pickDatasetFields(fields, 'ghost,website')).toEqual([fields[2]]);
|
||||
});
|
||||
|
||||
it('all-unknown keys fall back to the defaults, not to everything', () => {
|
||||
expect(pickDatasetFields(fields, 'ghost,also-ghost')).toEqual(defaults);
|
||||
});
|
||||
|
||||
it('surrounding whitespace in a hand-built fields list is tolerated', () => {
|
||||
expect(pickDatasetFields(fields, ' name , website ')).toEqual([fields[0], fields[2]]);
|
||||
});
|
||||
|
||||
it('a dataset with no default flags falls back to every field', () => {
|
||||
const flat = [{ key: 'a', label: 'A' }, { key: 'b', label: 'B' }];
|
||||
expect(pickDatasetFields(flat, undefined)).toEqual(flat);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user