Repository navigation
test(frontend): establish workspace baseline - #93
Conversation
📝 WalkthroughWalkthroughThe frontend adds a Vitest and Testing Library baseline, expands API and authentication tests, refines session and error handling, adds shared content states, and updates workspace and dashboard loading, validation, routing, and case-interaction behavior. ChangesFrontend baseline
Estimated code review effort: 4 (Complex) | ~45 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
frontend/src/api/cases.test.ts (1)
60-89: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winAssert mutation request bodies.
This test only verifies URLs and methods, so renamed or omitted
role, clue fields, or status fields would still pass.Proposed test coverage
expect(fetchMock.mock.calls.map(requestOptions).map((options) => options.method)).toEqual([ 'POST', 'POST', 'PATCH', 'PATCH', ]) + expect( + fetchMock.mock.calls.map((call) => JSON.parse(String(requestOptions(call).body))), + ).toEqual([ + { email: 'volunteer@demo.invalid', role: 'volunteer' }, + { source: 'volunteer', content: '模拟线索', occurred_at: null, location_text: null }, + { status: 'confirmed' }, + { status: 'resolved' }, + ])🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@frontend/src/api/cases.test.ts` around lines 60 - 89, The mutation endpoint test should also validate each request body, not only paths and methods. Extend the assertions for addCaseMember, createClue, reviewClue, and updateCaseStatus to verify their expected email/role, clue fields, review status, and case status payloads, preserving the existing endpoint and method checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@frontend/src/App.test.tsx`:
- Around line 51-70: Extend the “shows only the %s workspace navigation” test in
the role/workspace table to assert that every other workspace link is absent,
not just that the expected link exists. Use the existing workspace labels and
preserve the current positive assertion for the authorized workspace.
In `@frontend/src/pages/CaseWorkspacePage.tsx`:
- Around line 99-103: Guard the asynchronous detail-loading flow around getCase
so only the latest request may update detail or its associated error state.
Track a request version or equivalent in the component, invalidate the prior
request when caseId changes, and verify it is still current before applying
results from the try/catch in the detail-loading effect. Preserve the existing
messageFrom handling for the current request.
In `@frontend/src/pages/DashboardPage.tsx`:
- Around line 29-40: Update the partial-data condition after loading details in
the dashboard to also flag truncation when items.length exceeds 20, even if all
first-20 requests succeed. Preserve the existing failed-request check and error
message, ensuring clue statistics warn whenever details do not cover all cases.
---
Nitpick comments:
In `@frontend/src/api/cases.test.ts`:
- Around line 60-89: The mutation endpoint test should also validate each
request body, not only paths and methods. Extend the assertions for
addCaseMember, createClue, reviewClue, and updateCaseStatus to verify their
expected email/role, clue fields, review status, and case status payloads,
preserving the existing endpoint and method checks.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: c4c496a1-f80b-4d34-b6e4-12df429633f3
⛔ Files ignored due to path filters (1)
frontend/package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (14)
frontend/README.mdfrontend/package.jsonfrontend/src/App.test.tsxfrontend/src/api/cases.test.tsfrontend/src/api/cases.tsfrontend/src/api/client.test.tsfrontend/src/api/client.tsfrontend/src/auth/AuthContext.test.tsxfrontend/src/auth/AuthContext.tsxfrontend/src/components/ContentState.tsxfrontend/src/pages/CaseWorkspacePage.tsxfrontend/src/pages/DashboardPage.tsxfrontend/src/test/setup.tsfrontend/vite.config.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
frontend/src/pages/DashboardPage.test.tsx (1)
23-42: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAssert which cases are fetched, not only the count.
toHaveBeenCalledTimes(20)would still pass if the page fetched the same case repeatedly, skipped an early case, or passed incorrect arguments. Assert thatgetCase.mock.callscontains the first 20 case IDs (and the expected auth argument, if applicable) in order.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@frontend/src/pages/DashboardPage.test.tsx` around lines 23 - 42, Update the test around DashboardPage to verify mocked.getCase calls, not just their count: assert the first 20 case IDs are requested in order and include the expected authentication argument if the API requires one, while preserving the existing truncation warning assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@frontend/src/pages/DashboardPage.test.tsx`:
- Around line 23-42: Update the test around DashboardPage to verify
mocked.getCase calls, not just their count: assert the first 20 case IDs are
requested in order and include the expected authentication argument if the API
requires one, while preserving the existing truncation warning assertion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: b9460400-5f83-4d33-9fc1-907f63044b6f
📒 Files selected for processing (6)
frontend/src/App.test.tsxfrontend/src/api/cases.test.tsfrontend/src/pages/CaseWorkspacePage.test.tsxfrontend/src/pages/CaseWorkspacePage.tsxfrontend/src/pages/DashboardPage.test.tsxfrontend/src/pages/DashboardPage.tsx
🚧 Files skipped from review as they are similar to previous changes (4)
- frontend/src/api/cases.test.ts
- frontend/src/App.test.tsx
- frontend/src/pages/DashboardPage.tsx
- frontend/src/pages/CaseWorkspacePage.tsx
Closes #68\n\n## Summary\n- add a Vitest and Testing Library baseline for authentication, role routing, API error behavior, and the implemented case API surface\n- align front-end case types and workspace controls with the current Actix/OpenAPI contract\n- clear stale client session state after authenticated 401 responses and provide safe user-facing API errors\n- document the endpoint-to-test mapping and front-end test command\n\n## Verification\n- npm --prefix frontend run test\n- npm --prefix frontend run build\n- npm --prefix frontend run lint\n- cargo test --workspace --all-features --locked
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Chores