fix: export colmn

This commit is contained in:
nathnael
2026-09-02 13:47:23 +00:00
parent 75bbdbf84c
commit a06faa4254
4 changed files with 98 additions and 18 deletions

View File

@@ -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);
});
});