Implement story and testing for reset button - #120
Open
david-roper wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a Storybook story and test coverage for the
Formcomponent'sresetBtnprop. No source changes — this is story and test coverage only, so runtime behaviour is unchanged.Motivation
resetBtnhad no test coverage anywhere in the suite, and thereset()handler behind it is more subtle than it looks:reset()runs after every successful submit, whether or not the button is rendered.preventResetValuesOnResetchanges what it clears — errors are always cleared, values only conditionally.type="button", so a regression to a submit button would be silent.The one existing story touching this path,
WithPreventReset, does not setresetBtn, so it renders no reset button and its behaviour can only be observed by submitting the form.Changes
Form.stories.tsxNew
WithResetButtonstory withresetBtn: trueand 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.tsxNew
reset buttondescribe block with 8 tests:resetBtnis settype="button")preventResetValuesOnReset: values survive, errors are still clearedreset()fires without the button present — values cleared on success, and kept whenpreventResetValuesOnResetis setThe button is queried by
role: 'button', name: 'Reset', which resolves through itsaria-label, so the tests do not depend on i18n resolving theform.resetkey (the test setup initialises i18n with empty translations).Verification
The new tests were mutation-tested against
Form.tsxrather than just confirmed green:reset()preventResetValuesOnResetEach 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.