// Generated, do not edit. sha256:f8c363b3e2be566adaeb7e774a99be7727789e6454a0a1b4badaa78e72fc6bcd import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { groupSections } from '../../client/ui/table-groups.js'; const rows = [ { id: 1, kind: 'a', place: 'x', year: 2024 }, { id: 2, kind: 'b', place: 'x', year: 2025 }, { id: 3, kind: 'a', place: 'y', year: 2025 }, { id: 4, kind: 'a', place: 'x', year: 2025 }, ]; const columns = [ { key: 'kind', group: { value: r => r.kind, label: v => `Kind ${v}` } }, { key: 'place', group: { value: r => r.place } }, { key: 'year', group: { value: r => r.year, order: 'desc' } }, ]; const shape = sections => sections.map(s => [s.label, s.items.map(r => r.id), s.collapsed]); describe('groupSections', () => { it('one level: a section per value in ascending order, rows in the order given', () => { assert.deepEqual(shape(groupSections(rows, { columns, groupKey: 'kind' })), [ ['Kind a', [1, 3, 4], false], ['Kind b', [2], false], ]); }); it('the token is the string of the first-level value, the value itself stays', () => { const [s] = groupSections(rows, { columns, groupKey: 'year' }); assert.equal(s.token, '2025'); assert.equal(s.value, 2025); }); it('group.order desc turns the order, and a sort on the group column overrules it', () => { assert.deepEqual(groupSections(rows, { columns, groupKey: 'year' }).map(s => s.token), ['2025', '2024']); assert.deepEqual(groupSections(rows, { columns, groupKey: 'year', sort: { key: 'year', dir: 'asc' } }).map(s => s.token), ['2024', '2025']); assert.deepEqual(groupSections(rows, { columns, groupKey: 'year', sort: { key: 'kind', dir: 'asc' } }).map(s => s.token), ['2025', '2024']); }); it('two and three levels: combined labels, the outer level decides first', () => { assert.deepEqual(shape(groupSections(rows, { columns, groupKey: 'kind', groupKey2: 'place' })), [ ['Kind a - x', [1, 4], false], ['Kind a - y', [3], false], ['Kind b - x', [2], false], ]); assert.deepEqual(shape(groupSections(rows, { columns, groupKey: 'kind', groupKey2: 'place', groupKey3: 'year' })), [ ['Kind a - x - 2025', [4], false], ['Kind a - x - 2024', [1], false], ['Kind a - y - 2025', [3], false], ['Kind b - x - 2025', [2], false], ]); }); it('a collapsed group stands ONCE, with the first-level label and all its items across deeper levels', () => { const s = groupSections(rows, { columns, groupKey: 'kind', groupKey2: 'place', collapsed: new Set(['a']) }); assert.deepEqual(shape(s), [ ['Kind a', [1, 4, 3], true], ['Kind b - x', [2], false], ]); }); it('collapsed tokens are ignored without the set (a table that cannot collapse)', () => { assert.ok(groupSections(rows, { columns, groupKey: 'kind', collapsed: null }).every(s => !s.collapsed)); }); it('a value without a label function is used as it is, also on a deeper level', () => { const cols = [{ key: 'kind', group: { value: r => r.kind } }, columns[2]]; assert.deepEqual(groupSections(rows, { columns: cols, groupKey: 'kind', groupKey2: 'year' }).map(s => s.label), ['a - 2025', 'a - 2024', 'b - 2025']); }); it('a null group value is its own section, last, with token "null"', () => { const r = [...rows, { id: 5, kind: null, place: 'x', year: 2025 }]; const s = groupSections(r, { columns, groupKey: 'kind' }); assert.deepEqual(s.map(x => x.token), ['a', 'b', 'null']); }); it('no rows: no sections', () => { assert.deepEqual(groupSections([], { columns, groupKey: 'kind' }), []); }); });