Skip to content

[good first issue] Add File Upload example page + tests #218

@kevinccbsg

Description

@kevinccbsg

Real-world pattern not currently covered (<input type="file">).

Scope

  • New page examples/twd-test-app/src/pages/FileUpload.tsx:
    • A single file input.
    • Display the selected filename.
    • Reject non-image files with a visible error message.
  • Register the route in examples/twd-test-app/src/routes.tsx and add a link from the App menu.
  • New test file examples/twd-test-app/src/twd-tests/file-upload.twd.test.ts:
    • Query the input with screenDom.getByLabelText(...).
    • Happy path: userEvent.upload(input, file) → filename appears (screenDom.getByText(...) + twd.should(el, "be.visible")).
    • Invalid file type: error appears (screenDom.getByRole("alert") or screenDom.getByTestId("upload-error")).

Reference

  • Page structure: examples/twd-test-app/src/pages/ComboboxSelect.tsx.
  • Test structure: examples/twd-test-app/src/twd-tests/combobox-select.twd.test.ts.
  • Query pattern: examples/twd-test-app/src/twd-tests/screen-queries.twd.test.ts.

Acceptance criteria

  • New page renders and is reachable from the App menu.
  • Two test cases run green in the TWD sidebar.
  • PR includes a sidebar screenshot and a screenshot of the new page.

How to contribute

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

  1. Fork, clone, create a feature branch: git checkout -b feat/file-upload-example.
  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