Skip to content

Conversation

jonatsm
Copy link
Member

@jonatsm jonatsm commented Oct 14, 2026

Component tests with mocked Apollo

Builds on #35. Must Merge #35 first! Until then, this PR also shows its commits.

All component tests now run without a backend.

  • Search page: loading, empty, and "new search while results are shown", with a fake backend that can be slow
  • Submit page: an invalid form sends no request, a double click sends one request, the error summary goes away once fields are fixed, and a submitted sighting shows up in the list
  • Bug fixed (Error summary on the submit form never disappears #63): the submit form's error summary never disappeared
  • Submitted sighting doesn't show up in the search list #64 confirmed fixed by Connect the detail page to the backend #35's cache eviction (the new submit test checks it from the user's side)
  • Tooling change: npm test now runs all tests once, like CI. Watch mode moved to npm run test:watch. Before, npm test hung in watch mode and only ran the backend tests after you pressed q.

How to test

npm test: 50 frontend and 10 backend tests should pass, with no backend running.

AI usage

Claude Code helped write the tests, find and fix #63, and change the test scripts.

Closes #43

asgeija and others added 10 commits October 12, 2026 13:05
The detail page now queries the sighting by id instead of reading
the mock data.  Part of #35
Nothing reads from the store now that the detail page uses GraphQL,
so SubmitSightingPage no longer adds sightings to it. The mock
sightings move to tests/ because the tests still use them as
fixtures.
Give the fake backend an optional latency so states that only exist
while waiting can be tested, and test the first load, a serach with
no matches and a new serach while old results are shown.

Refs #43
Clear the cached sighting lists after a submit so the new sighting
shows up in the search results. Show "Unknown" for a missing shape
and hide empty comments. Return "Unknown date" for invalid dates
instead of throwing. Return not found for ids that are not plain
numbers, since MySQL reads '1abc' as 1.

Part of #35
The detail page said "Check your connection" for every error. If
the backend answers with a GraphQL error, such as a database
failure, it now says the server could not load the sighting and
hides the retry button, since retrying won't help.

Network
failures keep the old message and the button.

Part of #35
…e-backen' into 43-update-component-tests-for-apollo
The summary counted keys in the errors object, but fixing a field
set its error to undefined without removing the key.
Now it checks for actual messages instead.

Fixes #63
Check that an invalid form sends no request and links each error to
its feild, that the error summary goes away once the fileds are fixed,
that a double click sends on requests, and that a sbmitted
sighting shows up in the search list. Uses a fake database
that stores the sighting and counts requests.

Refs #43, #64
npm test started Vitest in watch mode and only reached
the backend tests after quitting it. Run Vitest once by
default, like CI, and moved watch mode to npm run test:watch.
Documented in AGENTS.md.

Refs #43
@jonatsm jonatsm added bug Something isn't working configuration test labels Oct 14, 2026
@jonatsm jonatsm added this to the Partial submission 2 milestone Oct 14, 2026
@jonatsm jonatsm requested a review from a team as a code owner October 14, 2026 08:03
@jonatsm jonatsm linked an issue Oct 14, 2026 that may be closed by this pull request
3 tasks
Copy link
Member

@asgeija asgeija left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran npm test locally and got ERR_UNKNOWN_FILE_EXTENSION when Node tried to run the backend .ts test file. Could you update the backend test script to run through tsx so it works consistently across Node versions?

node --test only runs .ts files by itself from Node 22.18, so npm test
failed with ERR_UNKNOWN_FILE_EXTENSION on older Node 22 version. Now the
tests are ran through tsx instead, and Node 22 is set as the minimum
version in package.json.

Refs #43
@jonatsm
Copy link
Member Author

jonatsm commented Oct 15, 2026

I ran npm test locally and got ERR_UNKNOWN_FILE_EXTENSION when Node tried to run the backend .ts test file. Could you update the backend test script to run through tsx so it works consistently across Node versions?

Good catch! Could you run npm test again to confirm? It should work now.

@asgeija
Copy link
Member

asgeija commented Oct 15, 2026

I ran npm test locally and got ERR_UNKNOWN_FILE_EXTENSION when Node tried to run the backend .ts test file. Could you update the backend test script to run through tsx so it works consistently across Node versions?

Good catch! Could you run npm test again to confirm? It should work now.

It works now, good job.

@jonatsm jonatsm dismissed asgeija’s stale review October 15, 2026 08:33

The merge-base changed after approval.

asgeija
asgeija previously approved these changes Oct 15, 2026
asgeija
asgeija previously approved these changes Oct 15, 2026
Copy link
Member

@asgeija asgeija left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved

thortve
thortve previously approved these changes Oct 15, 2026
@jonatsm jonatsm dismissed stale reviews from thortve and asgeija October 15, 2026 08:39

The merge-base changed after approval.

thortve
thortve previously approved these changes Oct 15, 2026
@jonatsm jonatsm requested a review from asgeija October 15, 2026 08:41
@jonatsm jonatsm dismissed thortve’s stale review October 15, 2026 08:44

The merge-base changed after approval.

@asgeija asgeija closed this pull request by merging all changes into main in 6be0218 Oct 15, 2026
@asgeija asgeija deleted the 43-update-component-tests-for-apollo branch October 15, 2026 08:54
Sign in to join this conversation on GitHub.
Labels
bug Something isn't working configuration test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error summary on the submit form never disappears Update component tests for Apollo
3 participants