feat: add Primary message to the 3 wizard machines (RD-07)
Each wizard component re-derives the step-boundary decision the reducer already owns: advance on a middle step, submit on the last step. This ticket moves that decision into the machine, so RD-08 can replace the component's guard with one dispatch. Add a `Primary` message to each Msg union, and export a `primary(s)` function next to the existing `next`/`submit` pair. `primary` is a three-line branch that delegates to `next`/`submit` and writes no new validation. Each machine tests "last step" in its own vocabulary, per the ticket's Decisions block: `herregistratie` checks `step === 3`, `intake` checks `currentStep(s) === 'review'`, `registratie` checks `currentStep(s) === 'controle'`. `Next` and `Submit` stay in every union and every reducer — `Primary` is purely additive. Add 3 spec cases per machine (9 total): Primary advances from a non-final step, Primary submits from the final step, and Primary is a no-op outside the editing state. Each case also asserts the equivalence the ticket requires for RD-08's migration: `reduce(s, Primary)` equals `reduce(s, Next)` at a non-final step, and equals `reduce(s, Submit)` at the final step. Regenerate `behaviour-spec.mdx` for the 9 new `it()` titles. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
back,
|
||||
gaNaarStap,
|
||||
submit,
|
||||
primary,
|
||||
resolve,
|
||||
reduce,
|
||||
IntakeState,
|
||||
@@ -207,6 +208,33 @@ describe('submit', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('primary', () => {
|
||||
// Same fixture as the 'submit' describe block above: buitenland answered 'nee',
|
||||
// uren high enough to skip the scholing question.
|
||||
const highUren = givenIntake(
|
||||
{ tag: 'SetAnswer', key: 'buitenlandGewerkt', value: 'nee' },
|
||||
{ tag: 'SetAnswer', key: 'uren', value: '4160' },
|
||||
);
|
||||
|
||||
it('Primary advances to the next step from a non-final step', () => {
|
||||
expect(currentStep(expectTag(highUren, 'Answering'))).toBe('buitenland'); // not the final step
|
||||
expect(reduce(highUren, { tag: 'Primary' })).toEqual(reduce(highUren, { tag: 'Next' }));
|
||||
expect(expectTag(primary(highUren), 'Answering').cursor).toBe(1);
|
||||
});
|
||||
|
||||
it('Primary submits from the final step', () => {
|
||||
const atReview = reduce(reduce(highUren, { tag: 'Next' }), { tag: 'Next' });
|
||||
expect(currentStep(expectTag(atReview, 'Answering'))).toBe('review'); // the final step
|
||||
expect(reduce(atReview, { tag: 'Primary' })).toEqual(reduce(atReview, { tag: 'Submit' }));
|
||||
expect(primary(atReview).tag).toBe('Submitting');
|
||||
});
|
||||
|
||||
it('Primary is a no-op from a non-editing state', () => {
|
||||
const submitting = submit(reduce(reduce(highUren, { tag: 'Next' }), { tag: 'Next' }));
|
||||
expect(primary(submitting)).toBe(submitting);
|
||||
});
|
||||
});
|
||||
|
||||
describe('reduce (message-driven happy path)', () => {
|
||||
it('drives abroad branch end to end', () => {
|
||||
let s: IntakeState = initial;
|
||||
|
||||
Reference in New Issue
Block a user