import assert from 'node:assert/strict'; import test from 'node:test'; import { SVOD2_TABLE_CONTAINER_SX, createColumnBandMap, createColumnClassMap, createColumnGroupEndSet, getEstimateTypeClassName, getSvod2CellClassName, } from './svod2Styles.js'; const columns = [ { id: 'a' }, { id: 'g1', columns: [{ id: 'g1.x' }, { id: 'g1.sub', columns: [{ id: 'g1.sub.y' }, { id: 'g1.sub.z' }] }] }, { id: 'b' }, { id: 'g2', columns: [{ id: 'g2.x' }, { id: 'g2.y' }] }, ]; test('bands alternate by top-level column and are inherited by children', () => { const bands = createColumnBandMap(columns); assert.equal(bands.get('a'), 0); assert.equal(bands.get('g1'), 1); assert.equal(bands.get('g1.sub.z'), 1); assert.equal(bands.get('b'), 0); assert.equal(bands.get('g2.y'), 1); }); test('group ends contain the group id and its last leaf only', () => { const ends = createColumnGroupEndSet(columns); assert.deepEqual([...ends].sort(), ['g1', 'g1.sub.z', 'g2', 'g2.y']); }); test('cell class name combines band and group-end', () => { const bands = createColumnBandMap(columns); const ends = createColumnGroupEndSet(columns); assert.equal(getSvod2CellClassName('a', bands, ends), undefined); assert.equal(getSvod2CellClassName('g1.x', bands, ends), 'svod2-band-1'); assert.equal(getSvod2CellClassName('g1.sub.z', bands, ends), 'svod2-band-1 svod2-group-end'); assert.equal(getSvod2CellClassName('unknown', bands, ends), undefined); }); test('class map is precomputed for every column id', () => { const map = createColumnClassMap(columns); assert.equal(map.size, 10); assert.equal(map.get('g2.y'), 'svod2-band-1 svod2-group-end'); assert.equal(map.get('a'), undefined); }); test('estimate type class falls back to default', () => { assert.equal(getEstimateTypeClassName('АХР'), 'svod2-badge svod2-badge-ahr'); assert.equal(getEstimateTypeClassName('Прочее'), 'svod2-badge svod2-badge-default'); }); test('container styles define cell, band, group-end and pinned rules', () => { for (const key of [ '& td', '& th', '& td.svod2-band-1', '& th.svod2-band-1', '& td.svod2-group-end', '& th.svod2-group-end', '& td[data-pinned="true"]', '& th[data-pinned="true"]', ]) { assert.ok(SVOD2_TABLE_CONTAINER_SX[key], key); } });