Skip to content

Implement story and testing for reset button - #120

Merged
joshunrau merged 2 commits into
DouglasNeuroInformatics:mainfrom
david-roper:reset-btn
Sep 23, 2026
Merged

joshunrau merged 2 commits into
DouglasNeuroInformatics:mainfrom
david-roper:reset-btn

Conversation

@david-roper

Copy link
Copy Markdown
Contributor

Summary

Adds a Storybook story and test coverage for the Form component's resetBtn prop. No source changes — this is story and test coverage only, so runtime behaviour is unchanged.

Motivation

resetBtn had no test coverage anywhere in the suite, and the reset() handler behind it is more subtle than it looks:

  • The same reset() runs after every successful submit, whether or not the button is rendered.
  • preventResetValuesOnReset changes what it clears — errors are always cleared, values only conditionally.
  • The button is type="button", so a regression to a submit button would be silent.

The one existing story touching this path, WithPreventReset, does not set resetBtn, so it renders no reset button and its behaviour can only be observed by submitting the form.

Changes

Form.stories.tsx

New WithResetButton story with resetBtn: true and three fields — a text input, a radio group, and a textarea — so that clicking Reset visibly clears more than one field type. A cleared radio group in particular reads more clearly than an emptied text input, since the selected option disappears rather than just the text.

Form.test.tsx

New reset button describe block with 8 tests:

  • Button is not rendered by default, and is rendered when resetBtn is set
  • Clicking it clears the field values
  • Clicking it does not submit the form (guards type="button")
  • Clicking it clears validation errors
  • With preventResetValuesOnReset: values survive, errors are still cleared
  • Post-submit reset() fires without the button present — values cleared on success, and kept when preventResetValuesOnReset is set

The button is queried by role: 'button', name: 'Reset', which resolves through its aria-label, so the tests do not depend on i18n resolving the form.reset key (the test setup initialises i18n with empty translations).

Verification

The new tests were mutation-tested against Form.tsx rather than just confirmed green:

Mutation to reset() Result
Never clear values 2 tests fail
Ignore preventResetValuesOnReset A different 2 tests fail
Never clear errors A third pair fails

Each asserted behaviour is pinned by a test that actually observes it.

Suite is 197/197 passing (up from 189). tsc, ESLint, and Prettier are clean.

@david-roper
david-roper requested a review from joshunrau as a code owner August 27, 2026 20:41
@joshunrau
joshunrau merged commit 71466c6 into DouglasNeuroInformatics:main Sep 23, 2026
1 check passed
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 6.17.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants