Repository navigation
feat(investment-form): make the token purchase form accessible and cover it with unit tests - #1309
Merged
nanaf6203-bit merged 1 commit intoOct 21, 2026
Conversation
…vered The token purchase form had no accessible name, did not mark the fields that have to be filled in, and left the user hunting for the reason a submission was refused. It also had no unit tests of its own. - name the form after its heading and describe it with its introduction, so a screen reader announces what the form is and which property it is for - mark the required fields with the `required` attribute and give the terms checkbox a hint of its own - collect the errors of a refused submission in an error summary that takes the focus, and link every entry to the field it belongs to - let the form primitives own the ids of the fields and their messages, so the help and the error message of a field are always referenced by the field itself - use the zod 4 API in `purchaseTokenSchema`, so the validation messages reach the user instead of "Invalid input: expected true" - cover the rendering, the validation rules and the submission with unit tests, and document the behaviour in docs/investment-form.md Closes MettaChain#1268 Closes MettaChain#1271
|
@rozemary2026-a11y Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This was referenced Oct 20, 2026
nanaf6203-bit
approved these changes
Oct 21, 2026
nanaf6203-bit
left a comment
Contributor
There was a problem hiding this comment.
Appreciate the accessibility focus on the token purchase form plus the unit tests to back it up. Approved ✅
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
The token purchase form (
PurchaseTokenForm) had no accessible name, did not mark the fields that have to be filled in, and left the user hunting for the reason a submission was refused. It also had no unit tests of its own — only a single accessibility assertion.This PR makes the form accessible and covers it with unit tests.
Closes #1268
Closes #1271
Changes
Accessibility (#1268)
aria-labelledbypoints at the heading, so the form is announced as "Purchase Tokens"aria-describedbypoints at the introductionrequiredattributeFormLabellinked to the control, with a hint of its ownThe error summary follows the pattern that is used for this kind of form elsewhere: a
role="alert"region named "There is a problem", which lists every refused value and links it to its field. The hiddenpropertyIdfield is listed without a link, because it has no control to focus.The redundant second validation pass (the schema was parsed a second time inside the submit handler, after the resolver had already validated the values) is gone — the resolver is the single source of truth.
Validation messages
purchaseTokenSchemawas written against the zod 3 API (invalid_type_erroranderrorMap), which zod 4 ignores. The form therefore showed "Invalid input: expected true" instead of "You must agree to the terms before purchasing.", and "Invalid input: expected number" instead of "Token amount must be a number.". The schema now uses the zod 4 API, so the messages reach the user. This also removes three type errors that the old API produced.Tests
src/components/forms/__tests__/PurchaseTokenForm.test.tsx(new): the rendering, the validation rules (empty form, a token amount that is not a whole number, a token amount above the maximum, a max price of zero, terms that were not accepted) and the submission (a market order, a bid order, the removal of the error summary).src/components/forms/__tests__/PurchaseTokenForm.a11y.test.tsx: extended with the name and the description of the form, the required fields, the error summary and the focus management. The existing assertion now reads the message the input points at witharia-describedbyinstead of matching any text in the document, which stays unambiguous now that the errors appear twice.Documentation
docs/investment-form.mddescribes the fields, the validation rules, the accessibility contract and the tests, and is linked from the README.How it was verified
The 20 tests of the two suites pass. The type check reports three findings less than the base commit, and the lint report is unchanged.