import { describe, expect, it } from 'vitest'; import { cleanOptions, tableSize, type TableOption } from './spec'; const options: TableOption[] = [ { key: 'length', label: 'Length', choices: [{ value: 'short', label: 'Short' }, { value: 'long', label: 'Long' }], default: 'short' } ]; describe('table options', () => { it('keeps only declared options and offered choices, the rest at their defaults', () => { expect(cleanOptions({ options }, { length: 'long', colour: 'red' })).toEqual({ length: 'long' }); expect(cleanOptions({ options }, { length: 'endless' })).toEqual({ length: 'short' }); expect(cleanOptions({ options }, null)).toEqual({ length: 'short' }); }); it('seats as many as the options allow, never more than the seats there are', () => { const seatIds = ['A', 'B', 'C', 'D']; expect(tableSize({ seatIds, options })).toBe(4); const seatsFor = (o: Record) => (o.length === 'short' ? 2 : 9); expect(tableSize({ seatIds, options, seatsFor }, { length: 'short' })).toBe(2); expect(tableSize({ seatIds, options, seatsFor }, { length: 'long' })).toBe(4); }); });