Skip to content

Test the error text of the translated validation messages - #503

Open
alexluckett wants to merge 4 commits into
docs/v5-migration-guide-fixesfrom
fix/v5-validation-message-tests
Open

alexluckett wants to merge 4 commits into
docs/v5-migration-guide-fixesfrom
fix/v5-validation-message-tests

Conversation

@alexluckett

Copy link
Copy Markdown
Contributor

Proposed change

This adds tests for the error text of each validation error that a user can get from a component.

Errors that now have tests:

Component Input Error
Autocomplete a value that is not in the list Enter your example text
Date a day that is not a number Example date parts field must include a day
Date a day that is too large to be a number Example date parts field must be a real date
Month and year a month that is not a number Example month/year field must include a month
Month and year a month that is too large to be a number Example month/year field must be a real date
Easting and northing an easting that is not a number Enter easting
Easting and northing an easting that is too large to be a number Easting for example location must be between 1 and 6 digits
Easting and northing easting only, required and optional Example location must include a northing
Lat and long a latitude that is too large to be a number Latitude must be a valid number
Lat and long latitude only, required and optional Example location must include a longitude

Location fields now must set their own required message. Both location fields already did this, so the fallback to the generic message ran only in the test subclass. The fallback is removed, and the test subclass sets a required message.

Jira ticket:

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Misc. (documentation, build updates, etc)

Checklist

  • You have executed this code locally and it performs as expected.
  • You have added tests to verify your code works.
  • You have added code comments and JSDoc, where appropriate.
  • There is no commented-out code.
  • You have added developer docs in README.md and docs/* (where appropriate, e.g. new features).
  • The tests are passing (npm run test).
  • The linting checks are passing (npm run lint).
  • The code has been formatted (npm run format).

Both location fields set their own required message, so the fallback to
the generic required message never ran outside the test subclass. The
config now requires the message, and the fallback is removed.
validate() now always applies the translated message overrides. Some of
those messages had no test that checked their text, because the tests for
invalid values only checked that an error was present.

These tests check the text for:

- a value that is not in the autocomplete list
- a date day or month that is not a number, or is too large to be one
- an easting that is not a number, or is too large to be one
- a latitude that is too large to be a number
Each component test file has a Validation table of inputs and the exact
output of validate(). The error text tests now sit in those tables, so
that each file has one place for its validation errors.

The Autocomplete Validation table had no test function, so its case did
not run. It now runs for both lists, with the component of each list.
A user who fills in only one part of the field gets an error for the
missing part. No test checked the text of that error, for a required or
an optional field.
@alexluckett
alexluckett added this pull request to stack #502 November 19, 2026 22:18
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant