import { describe, it, expect } from 'vitest'; import { {{pascalCase name}}State, reduce, initial } from './{{kebabCase name}}.machine'; type Editing = Extract<{{pascalCase name}}State, { tag: 'Editing' }>; describe('{{camelCase name}} reduce', () => { it('SetField updates the draft while editing', () => { const s = reduce(initial, { tag: 'SetField', key: 'veld', value: 'x' }); expect((s as Editing).draft.veld).toBe('x'); }); it('Submit with an invalid draft stays Editing and reports field errors', () => { const s = reduce(initial, { tag: 'Submit' }); expect(s.tag).toBe('Editing'); expect((s as Editing).errors.veld).toBeTruthy(); }); it('Submit with a valid draft moves to Submitting', () => { const editing = reduce(initial, { tag: 'SetField', key: 'veld', value: 'x' }); expect(reduce(editing, { tag: 'Submit' }).tag).toBe('Submitting'); }); it('Reset returns to the initial editing state', () => { const editing = reduce(initial, { tag: 'SetField', key: 'veld', value: 'x' }); expect(reduce(editing, { tag: 'Reset' })).toEqual(initial); }); });