test(medication): filter-strip coverage for the prescribing workspace (TCD-01) - #1060
Conversation
… (TCD-01) The prescribing results view lenses a medication catalogue through a best/indication/safety/monitoring filter strip and had no render coverage. Add @testing-library/react tests over a fixed catalogue chosen to land results in different filter buckets (Clozapine → best/indication/safety; Lithium → all four; Sertraline → best only): - each lens button shows the count of matching results (Best 3 / Indication 2 / Safety 2 / Monitor 1); - the Best lens is active by default with every result shown; - selecting Indication drops "Related match" results; selecting Monitor narrows to results carrying a monitoring signal. The catalogue hook (fetches /api/medications + reads the auth session) and the cross-mode "also matches" strip are mocked so the test isolates the filter strip; only usePatientProfile uses a real provider (empty profile → no alert badges). Verified: 4/4 pass; typecheck, lint, format:check clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
📝 WalkthroughWalkthroughAdds Vitest/React Testing Library coverage for medication result filter counts, the default Best lens, and filtering behavior for the Indication and Monitor lenses using deterministic mocked results. ChangesMedication filter tests
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@tests/medication-prescribing-workspace.dom.test.tsx`:
- Around line 121-124: Update the assertions using filterButton for “Best”,
“Indication”, “Safety”, and “Monitor” to compare each button’s complete
textContent against the expected label/count pair, rather than using toContain,
so incorrect counts such as 13 or 30 cannot pass.
- Around line 69-85: Update the useMedicationCatalog mock factory to define or
obtain clozapine, lithium, and sertraline within vi.hoisted or directly inside
the factory before constructing matches. Ensure the hoisted vi.mock callback no
longer reads those module-scoped fixtures during their temporal dead zone.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 50969506-612b-4b1a-b26a-d34b6eb7cb8b
📒 Files selected for processing (1)
tests/medication-prescribing-workspace.dom.test.tsx
| vi.mock("@/components/clinical-dashboard/use-medication-catalog", () => ({ | ||
| useMedicationCatalog: () => ({ | ||
| data: { | ||
| records: [], | ||
| matches: [clozapine, lithium, sertraline].map((result) => ({ | ||
| medication: undefined, | ||
| result, | ||
| score: 1, | ||
| reasons: [], | ||
| })), | ||
| total: 3, | ||
| governance: {}, | ||
| }, | ||
| loading: false, | ||
| error: null, | ||
| }), | ||
| })); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Move the catalog fixtures into vi.hoisted or the mock factory. vi.mock is hoisted, so this factory can hit a TDZ when it reads clozapine, lithium, and sertraline before those module-scoped fixtures are initialized.
🤖 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 `@tests/medication-prescribing-workspace.dom.test.tsx` around lines 69 - 85,
Update the useMedicationCatalog mock factory to define or obtain clozapine,
lithium, and sertraline within vi.hoisted or directly inside the factory before
constructing matches. Ensure the hoisted vi.mock callback no longer reads those
module-scoped fixtures during their temporal dead zone.
| expect(filterButton("Best").textContent).toContain("3"); | ||
| expect(filterButton("Indication").textContent).toContain("2"); | ||
| expect(filterButton("Safety").textContent).toContain("2"); | ||
| expect(filterButton("Monitor").textContent).toContain("1"); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert the exact label/count pair.
toContain also passes for incorrect counts such as 13 or 30; match the full button text instead.
Proposed fix
- expect(filterButton("Best").textContent).toContain("3");
- expect(filterButton("Indication").textContent).toContain("2");
- expect(filterButton("Safety").textContent).toContain("2");
- expect(filterButton("Monitor").textContent).toContain("1");
+ expect(filterButton("Best")).toHaveTextContent(/^Best\s*3$/);
+ expect(filterButton("Indication")).toHaveTextContent(/^Indication\s*2$/);
+ expect(filterButton("Safety")).toHaveTextContent(/^Safety\s*2$/);
+ expect(filterButton("Monitor")).toHaveTextContent(/^Monitor\s*1$/);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| expect(filterButton("Best").textContent).toContain("3"); | |
| expect(filterButton("Indication").textContent).toContain("2"); | |
| expect(filterButton("Safety").textContent).toContain("2"); | |
| expect(filterButton("Monitor").textContent).toContain("1"); | |
| expect(filterButton("Best")).toHaveTextContent(/^Best\s*3$/); | |
| expect(filterButton("Indication")).toHaveTextContent(/^Indication\s*2$/); | |
| expect(filterButton("Safety")).toHaveTextContent(/^Safety\s*2$/); | |
| expect(filterButton("Monitor")).toHaveTextContent(/^Monitor\s*1$/); |
🤖 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 `@tests/medication-prescribing-workspace.dom.test.tsx` around lines 121 - 124,
Update the assertions using filterButton for “Best”, “Indication”, “Safety”, and
“Monitor” to compare each button’s complete textContent against the expected
label/count pair, rather than using toContain, so incorrect counts such as 13 or
30 cannot pass.
Summary
Adds render coverage for the prescribing results filter strip (finding TCD-01) — the best/indication/safety/monitoring lens strip in
MedicationPrescribingWorkspacehad no test. Test-only, no product code changes.The tests render over a fixed catalogue chosen so results land in different filter buckets — Clozapine (danger/exact-fit → best, indication, safety), Lithium (warning/monitor → all four), Sertraline (neutral/related → best only) — and pin:
aria-pressed) with every result shown;The catalogue hook (
useMedicationCatalog— fetches/api/medicationsand reads the auth session) and the cross-mode "also matches" strip (UniversalSearchAlsoMatches,AuthProvider-backed) are mocked so the test isolates the filter strip from data-fetch and auth concerns. OnlyusePatientProfileuses a real provider, with an empty profile so no per-patient alert badges are computed.Verification
tests/medication-prescribing-workspace.dom.test.tsx— 4/4 pass (jsdom)npm run typecheck,npm run lint,npm run format:checkcleanRisk and rollout
🤖 Generated with Claude Code
Summary by CodeRabbit