Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Jm2auWk6RP71CjaAb4FMoG
23 lines
1.1 KiB
TypeScript
23 lines
1.1 KiB
TypeScript
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<string, string>) => (o.length === 'short' ? 2 : 9);
|
|
expect(tableSize({ seatIds, options, seatsFor }, { length: 'short' })).toBe(2);
|
|
expect(tableSize({ seatIds, options, seatsFor }, { length: 'long' })).toBe(4);
|
|
});
|
|
});
|