CI / frontend (push) Successful in 3m11s
CI / backend (push) Successful in 2m27s
CI / storybook-a11y (push) Successful in 9m28s
CI / e2e (push) Successful in 4m38s
CI / semgrep (push) Successful in 1m20s
CI / api-client-drift (push) Successful in 2m13s
Runnable `npm run gen:value-object` / `gen:form-machine` (plop) that scaffold the two
pure-TS house patterns with a co-located spec: a branded value object + parseX (mirrors
postcode/bsn), and an Elm-style form/wizard machine (Draft/Valid/Errors + Editing/
Submitting/Submitted/Failed union + initial/pure reduce/assertNever). Prompts take
context + PascalCase name (positional-arg bypass); a post-action reminds to add the
English target for the generated $localize id. Templates in plop-templates/ (prettier-
ignored). Skills (value-object, form-machine) point at the generators. ui-component +
bff-endpoint stay skill-driven (Angular {{}} / backend + gen:api).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
28 lines
1.1 KiB
Handlebars
28 lines
1.1 KiB
Handlebars
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);
|
|
});
|
|
});
|