// Generated, do not edit. sha256:da1d7ac61eaec602c87625209323742726a3b8d623b0c8ecbe617aa82923969a import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { seedSticky, harvestSticky } from '../../client/ui/table-sticky.js'; const cols = [ { key: 'accountId', edit: { type: 'select', sticky: true } }, { key: 'assetId', edit: { type: 'select', sticky: true } }, { key: 'occurredAt', edit: { type: 'date', sticky: true } }, { key: 'amount', edit: { type: 'number' } }, { key: 'note', edit: { type: 'text' } }, ]; const options = new Map([ ['accountId', [{ value: 1, label: 'Bank' }, { value: 3, label: 'Raisin' }]], ['assetId', [{ value: 7, label: 'Goud' }]], ]); describe('seedSticky: what a new row starts with', () => { it('carries the remembered values over the page defaults', () => { const out = seedSticky({ columns: cols, seeded: { accountId: '', assetId: '', occurredAt: '2026-09-06', amount: '', note: '' }, remembered: { accountId: 3, assetId: 7, occurredAt: '2026-03-31' }, options, }); assert.equal(out.accountId, 3); assert.equal(out.occurredAt, '2026-03-31'); assert.equal(out.amount, ''); }); it('leaves the seeded values alone when nothing was remembered', () => { const seeded = { accountId: '', amount: '' }; assert.deepEqual(seedSticky({ columns: cols, seeded, remembered: null, options }), seeded); assert.deepEqual(seedSticky({ columns: cols, seeded, remembered: {}, options }), seeded); }); it('does not modify the object it was given', () => { const seeded = { accountId: '' }; seedSticky({ columns: cols, seeded, remembered: { accountId: 3 }, options }); assert.equal(seeded.accountId, ''); }); it('drops a remembered choice that is no longer in the option list', () => { const out = seedSticky({ columns: cols, seeded: { accountId: '' }, remembered: { accountId: 99 }, options }); assert.equal(out.accountId, '', 'a stale choice falls back to the default'); }); it('compares a number against a string option value, both ways', () => { assert.equal(seedSticky({ columns: cols, seeded: {}, remembered: { accountId: '3' }, options }).accountId, '3'); assert.equal(seedSticky({ columns: cols, seeded: {}, remembered: { accountId: 3 }, options }).accountId, 3); }); it('ignores a remembered key that has no column any more, and a column that is not sticky', () => { assert.equal(seedSticky({ columns: cols, seeded: { accountId: '' }, remembered: { accountId: 3, goneColumn: 'x' }, options }).goneColumn, undefined); assert.equal(seedSticky({ columns: cols, seeded: { amount: '' }, remembered: { amount: '250' }, options }).amount, ''); }); it('keeps a page marker that is not a column', () => { const out = seedSticky({ columns: cols, seeded: { _new: 1, accountId: '' }, remembered: { accountId: 3 }, options }); assert.equal(out._new, 1); }); it('keeps a value whose column has no option list, also when the lists failed to load', () => { assert.equal(seedSticky({ columns: cols, seeded: {}, remembered: { occurredAt: '2026-03-31' }, options }).occurredAt, '2026-03-31'); assert.equal(seedSticky({ columns: cols, seeded: {}, remembered: { accountId: 3 }, options: undefined }).accountId, 3); }); }); describe('harvestSticky: what gets remembered', () => { it('keeps the sticky columns and nothing else', () => { assert.deepEqual(harvestSticky(cols, { accountId: 3, assetId: 7, occurredAt: '2026-03-31', amount: '250', note: 'x' }), { accountId: 3, assetId: 7, occurredAt: '2026-03-31' }); }); it('keeps a deliberately empty value, skips a hidden field, never lets a non-column through', () => { assert.deepEqual(harvestSticky(cols, { accountId: '' }), { accountId: '' }); assert.deepEqual(harvestSticky(cols, { accountId: 3, assetId: undefined }), { accountId: 3 }); assert.deepEqual(harvestSticky(cols, { _new: 1, accountId: 3 }), { accountId: 3 }); }); it('survives being called without values', () => { assert.deepEqual(harvestSticky(cols, null), {}); }); });