import { describe, it, expect } from 'vitest' import { createRef } from 'react' import { tableConfig, tableDownloadConfig } from './config' describe('tableConfig', () => { it('returns config with the provided columns', () => { const columns = [ { id: 'name', label: 'Name' }, { id: 'age', label: 'Age' }, ] satisfies Parameters[0] const cfg = tableConfig(columns) expect(cfg.columns).toBe(columns) expect(cfg.mode).toBe('local') expect(cfg.selectable).toBe(false) }) it('defaults to empty columns when no argument passed', () => { const cfg = tableConfig() expect(cfg.columns).toEqual([]) }) }) describe('tableDownloadConfig', () => { const refUI = createRef() it('returns a two-item download config (PNG + CSV)', () => { const cfg = tableDownloadConfig({ refUI }) expect(cfg).toHaveLength(2) }) it('CSV modifier handles populated row data with mixed value types', async () => { const cfg = tableDownloadConfig({ refUI }) const csvItem = cfg[1]! const rows = [ { id: '1', name: 'A', value: 10, meta: { tag: 'x' } }, { id: '2', name: 'B', value: null, meta: { tag: 'y' } }, { id: '3', name: 'C', value: undefined, meta: undefined }, ] as unknown as Parameters>[0] await expect(csvItem.modifier(rows)).resolves.not.toThrow() }) it('CSV modifier short-circuits when data is empty', async () => { const cfg = tableDownloadConfig({ refUI }) const csvItem = cfg[1]! await expect(csvItem.modifier([])).resolves.not.toThrow() await expect( csvItem.modifier( undefined as unknown as Parameters< NonNullable >[0], ), ).resolves.not.toThrow() }) it('CSV modifier handles first-row being undefined (edge case)', async () => { const cfg = tableDownloadConfig({ refUI }) const csvItem = cfg[1]! // Pass an array containing a falsy first item — should not throw. await expect( csvItem.modifier([undefined] as unknown as Parameters< NonNullable >[0]), ).resolves.not.toThrow() }) })