mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-09 00:08:18 +00:00
feat(WIP): filtering, exporting and more reports
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import { EXPORT_MIME, pickByKey, resolveExportCap, resolveExportFormat } from './export-request.util';
|
||||
import { CSV_ROW_CAP, PDF_ROW_CAP, XLSX_ROW_CAP } from './tabular-export.service';
|
||||
|
||||
describe('resolveExportFormat', () => {
|
||||
it('only \'pdf\' exports as pdf', () => {
|
||||
expect(resolveExportFormat('pdf')).toBe('pdf');
|
||||
});
|
||||
|
||||
it('\'csv\' exports as csv', () => {
|
||||
expect(resolveExportFormat('csv')).toBe('csv');
|
||||
});
|
||||
|
||||
it.each([undefined, 'xlsx', 'doc', ''])('%p falls back to xlsx', (raw) => {
|
||||
expect(resolveExportFormat(raw)).toBe('xlsx');
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveExportCap', () => {
|
||||
it('missing limit uses the full format cap', () => {
|
||||
expect(resolveExportCap('xlsx', undefined)).toBe(XLSX_ROW_CAP);
|
||||
expect(resolveExportCap('csv', undefined)).toBe(CSV_ROW_CAP);
|
||||
expect(resolveExportCap('pdf', undefined)).toBe(PDF_ROW_CAP);
|
||||
});
|
||||
|
||||
it('a limit under the cap is used as-is', () => {
|
||||
expect(resolveExportCap('pdf', '100')).toBe(100);
|
||||
});
|
||||
|
||||
it('a limit over the cap is clamped down', () => {
|
||||
expect(resolveExportCap('pdf', String(PDF_ROW_CAP + 1000))).toBe(PDF_ROW_CAP);
|
||||
expect(resolveExportCap('xlsx', String(XLSX_ROW_CAP + 1))).toBe(XLSX_ROW_CAP);
|
||||
expect(resolveExportCap('csv', String(CSV_ROW_CAP + 1))).toBe(CSV_ROW_CAP);
|
||||
});
|
||||
|
||||
it.each(['0', '-5', 'not-a-number', ''])('non-positive/invalid limit %p falls back to the cap', (raw) => {
|
||||
expect(resolveExportCap('xlsx', raw)).toBe(XLSX_ROW_CAP);
|
||||
});
|
||||
});
|
||||
|
||||
describe('EXPORT_MIME', () => {
|
||||
it('every format has a content type and a matching extension', () => {
|
||||
expect(EXPORT_MIME.csv.ext).toBe('csv');
|
||||
expect(EXPORT_MIME.xlsx.ext).toBe('xlsx');
|
||||
expect(EXPORT_MIME.pdf.type).toBe('application/pdf');
|
||||
});
|
||||
});
|
||||
|
||||
describe('pickByKey', () => {
|
||||
const columns = [
|
||||
{ key: 'a', label: 'A', type: 'string' as const },
|
||||
{ key: 'b', label: 'B', type: 'number' as const },
|
||||
{ key: 'c', label: 'C', type: 'money' as const },
|
||||
];
|
||||
|
||||
it('missing fields returns every column', () => {
|
||||
expect(pickByKey(columns, undefined)).toEqual(columns);
|
||||
});
|
||||
|
||||
it('empty fields string returns every column', () => {
|
||||
expect(pickByKey(columns, '')).toEqual(columns);
|
||||
});
|
||||
|
||||
it('a known subset filters to just those, in the source\'s own order', () => {
|
||||
expect(pickByKey(columns, 'c,a')).toEqual([columns[0], columns[2]]);
|
||||
});
|
||||
|
||||
it('unknown keys are dropped, not passed through', () => {
|
||||
expect(pickByKey(columns, 'a,ghost')).toEqual([columns[0]]);
|
||||
});
|
||||
|
||||
it('all-unknown keys falls back to everything instead of a blank sheet', () => {
|
||||
expect(pickByKey(columns, 'ghost,also-ghost')).toEqual(columns);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user