DEV Community

Cover image for Keep postcode format validation at the boundary of a drainage brief
The Doctor
The Doctor

Posted on

Keep postcode format validation at the boundary of a drainage brief

The drainage planner collects a problem, location, access and timing. It then asks for a postcode. Each is a short input for scoping. Neither a pooling answer nor a valid-looking postcode establishes the route stormwater takes or whether a service provider covers the lot.

What the browser actually checks

The client trims the input and applies a pattern for four digits beginning with 6. On failure it sets an inline alert, marks the input invalid and focuses it. On success it clears the error and builds the summary. There is no suburb lookup in this step, so the postcode remains a user-supplied location hint.

const postcode = page.getByLabel('WA postcode');
await postcode.fill('2000');
await postcode.press('Enter');
await expect(postcode).toHaveAttribute('aria-invalid', 'true');
await expect(postcode).toBeFocused();
await expect(page.getByRole('alert')).toContainText('four-digit WA postcode');
await postcode.fill('6062');
await postcode.press('Enter');
await expect(postcode).not.toHaveAttribute('aria-invalid', 'true');
await expect(page.locator('[data-answer-summary]')).toContainText('6062');
Enter fullscreen mode Exit fullscreen mode

Treat format, existence and coverage as separate checks

After answering the four questions, run the excerpt on the postcode panel. It exercises Enter on both paths. The existing service suite also covers Continue on invalid input. If a directory or coverage API is later introduced, test what the interface does when the code has the right format but the lookup is unavailable. Preserve observations already entered and label the unresolved location state. This keeps the error connected to the field the user can fix and leaves any drainage assessment outside the form.

Check the failed attempt also leaves the postcode panel visible. A UI can display the right alert and still accidentally advance. Test the current panel along with focus and validity rather than depending on one signal.

Perth Quotes drainage planner is the live preview. Online enquiries are closed.

Top comments (0)