Skip to content

[good first issue] Add keyboard navigation test for the Contact form #220

@kevinccbsg

Description

@kevinccbsg

Real-world a11y expectation. Exercises userEvent.tab() together with the existing be.focused assertion.

Scope

  • New test file examples/twd-test-app/src/twd-tests/contact-keyboard.twd.test.ts:
    • Visit /contact.
    • Query every field with screenDom.getByLabelText(...).
    • Call userEvent.tab() repeatedly; after each Tab, assert the expected field with twd.should(el, "be.focused").
    • Confirm Shift+Tab reverses the focus order.
    • Confirm that pressing Enter on the last field submits the form (or moves focus to the submit button).
  • If the Contact page is missing proper labels for getByLabelText, add them — avoid relying on CSS selectors.

Reference

  • examples/twd-test-app/src/twd-tests/screen-queries.twd.test.ts for screenDom usage.
  • examples/twd-test-app/src/twd-tests/assertion-examples.twd.test.ts for be.focused.

Acceptance criteria

  • All test cases run green in the TWD sidebar.
  • PR includes a sidebar screenshot.
  • Optional: one-line recipe in docs/writing-tests.md.

How to contribute

Read CONTRIBUTING.md first. Quick steps for this issue:

  1. Fork, clone, create a feature branch: git checkout -b feat/contact-keyboard-test.
  2. From the repo root, build the library and sync it to the example apps:
    npm install
    npm run build
    npm run copy:mock-sw
  3. Install and run the test app:
    cd examples/twd-test-app
    npm install
    npm run dev
  4. Open the app in the browser — the TWD sidebar appears on the right. Run your new tests from the sidebar and confirm they pass.
  5. Run the library's unit tests from the repo root: npm run test:ci.
  6. Open the PR with screenshots of the sidebar showing green tests.

Always prefer screenDom (Testing Library) for element queries. Avoid twd.get() in new code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions