Skip to content

test(frontend): establish workspace baseline - #93

Merged
cg8-5712 merged 2 commits into
mainfrom
feat/issue-68-frontend-baseline
Jul 23, 2026
Merged

cg8-5712 merged 2 commits into
mainfrom
feat/issue-68-frontend-baseline

Conversation

@cg8-5712

@cg8-5712 cg8-5712 commented Jul 23, 2026 •

Copy link
Copy Markdown
Collaborator

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

    • Added reusable loading/empty/error UI components across the dashboard and case workspace.
    • Introduced manual refresh and clearer partial-data handling on the dashboard.
    • Improved case creation and editing flows (validation, trimmed inputs, clue timing, status transition behavior).
  • Bug Fixes

    • Enhanced user-friendly API/network error messaging, including dedicated session-expired handling.
    • Sessions now clear reliably after expiration, logout failures, or invalid authentication.
  • Tests

    • Added/extended automated coverage for authentication, role-based routing, case API contracts, workspace concurrency, and client error/session behavior.
  • Chores

    • Added frontend test scripts and Vitest test baseline documentation.

Copilot AI review requested due to automatic review settings July 23, 2026 16:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Frontend baseline

Layer / File(s) Summary
Vitest baseline setup
frontend/README.md, frontend/package.json, frontend/vite.config.ts, frontend/src/test/setup.ts
Adds Vitest scripts, jsdom configuration, Testing Library cleanup, mock resets, and baseline test documentation.
API contracts and error handling
frontend/src/api/cases.ts, frontend/src/api/client.ts, frontend/src/api/*.test.ts
Refines case and clue types, returns case members from member creation, maps API/network failures to user-safe messages, and signals expired sessions.
Authentication session lifecycle
frontend/src/auth/AuthContext.tsx, frontend/src/auth/AuthContext.test.tsx
Centralizes session cleanup and covers login, restoration, logout, invalid credentials, and expired sessions.
Role-based routing coverage
frontend/src/App.test.tsx
Tests anonymous routing, role-specific navigation, incompatible-route redirects, and case-access messaging.
Workspace states and case actions
frontend/src/components/ContentState.tsx, frontend/src/pages/CaseWorkspacePage.tsx, frontend/src/pages/CaseWorkspacePage.test.tsx
Adds reusable loading, empty, and error states and updates case creation, status transitions, member actions, clue submission, list/detail errors, and stale-request handling.
Dashboard loading and partial data
frontend/src/pages/DashboardPage.tsx, frontend/src/pages/DashboardPage.test.tsx
Adds refreshable loading and error handling, partial detail loading, shared empty states, status labels, and coverage for the 20-detail limit.

Estimated code review effort: 4 (Complex) | ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: establishing a frontend test baseline.
Linked Issues check ✅ Passed The PR adds auth, routing, API-error, and case-workspace tests plus docs, matching the linked baseline validation goals.
Out of Scope Changes check ✅ Passed The changes stay focused on the frontend baseline, API contract alignment, and related test/documentation support.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/issue-68-frontend-baseline

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
frontend/src/api/cases.test.ts (1)

60-89: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Assert mutation request bodies.

This test only verifies URLs and methods, so renamed or omitted email, 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

📥 Commits

Reviewing files that changed from the base of the PR and between 72916b8 and f093c8c.

⛔ Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (14)
  • frontend/README.md
  • frontend/package.json
  • frontend/src/App.test.tsx
  • frontend/src/api/cases.test.ts
  • frontend/src/api/cases.ts
  • frontend/src/api/client.test.ts
  • frontend/src/api/client.ts
  • frontend/src/auth/AuthContext.test.tsx
  • frontend/src/auth/AuthContext.tsx
  • frontend/src/components/ContentState.tsx
  • frontend/src/pages/CaseWorkspacePage.tsx
  • frontend/src/pages/DashboardPage.tsx
  • frontend/src/test/setup.ts
  • frontend/vite.config.ts

Comment thread frontend/src/App.test.tsx
Comment thread frontend/src/pages/CaseWorkspacePage.tsx
Comment thread frontend/src/pages/DashboardPage.tsx

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
frontend/src/pages/DashboardPage.test.tsx (1)

23-42: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert 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 that getCase.mock.calls contains 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

📥 Commits

Reviewing files that changed from the base of the PR and between f093c8c and 3ef6fdf.

📒 Files selected for processing (6)
  • frontend/src/App.test.tsx
  • frontend/src/api/cases.test.ts
  • frontend/src/pages/CaseWorkspacePage.test.tsx
  • frontend/src/pages/CaseWorkspacePage.tsx
  • frontend/src/pages/DashboardPage.test.tsx
  • frontend/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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Quality] 前端现有工作台基线验收与可定位测试

2 participants