Skip to content

test(medication): filter-strip coverage for the prescribing workspace (TCD-01) - #1060

Merged
BigSimmo merged 2 commits into
mainfrom
claude/medication-workspace-tests-123366
Jul 22, 2026
Merged

test(medication): filter-strip coverage for the prescribing workspace (TCD-01)#1060
BigSimmo merged 2 commits into
mainfrom
claude/medication-workspace-tests-123366

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Summary

Adds render coverage for the prescribing results filter strip (finding TCD-01) — the best/indication/safety/monitoring lens strip in MedicationPrescribingWorkspace had 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:

  • each lens button shows the count of matching results (Best 3 / Indication 2 / Safety 2 / Monitor 1);
  • the Best lens is active by default (aria-pressed) with every result shown;
  • selecting Indication drops "Related match" results; selecting Monitor narrows to results carrying a monitoring signal.

The catalogue hook (useMedicationCatalog — fetches /api/medications and 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. Only usePatientProfile uses a real provider, with an empty profile so no per-patient alert badges are computed.

Verification

  • tests/medication-prescribing-workspace.dom.test.tsx4/4 pass (jsdom)
  • npm run typecheck, npm run lint, npm run format:check clean
  • UI verification not run: no product code or rendered output changes (test-only); the full unit + jsdom suite runs in CI.

Risk and rollout

  • Risk: none. Test-only; adds one jsdom render test file, no product code touched.
  • Rollback: revert this commit.
  • Provider or production effects: None. Verification was fully offline; no provider calls.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added coverage for medication result filtering.
    • Verified filter counts, default “Best” view, and filtering by indication and monitoring criteria.
    • Confirmed the correct medication results appear or are hidden for each filter.

… (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>
@supabase

supabase Bot commented Jul 22, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project sjrfecxgysukkwxsowpy because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

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

Changes

Medication filter tests

Layer / File(s) Summary
Deterministic test harness
tests/medication-prescribing-workspace.dom.test.tsx
Mocks medication catalog data and related components, provides rendering and accessibility-query helpers, and restores mocks between tests.
Filter strip behavior assertions
tests/medication-prescribing-workspace.dom.test.tsx
Verifies lens counts, Best-lens initialization, pressed states, and visible medication results for Indication and Monitor selections.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • BigSimmo/Database#477: Introduces or redesigns the filter-count and lens-filtering logic covered by these tests.
  • BigSimmo/Database#688: Updates the same medication workspace filter-strip and medication-results UI area.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, specific, and accurately summarizes the new test coverage for the prescribing workspace filter strip.
Description check ✅ Passed The description covers summary, verification, and risk/rollback details and is mostly complete for this test-only change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 claude/medication-workspace-tests-123366

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

@BigSimmo
BigSimmo enabled auto-merge (squash) July 22, 2026 03:23
@BigSimmo
BigSimmo merged commit 9273fbe into main Jul 22, 2026
18 checks passed
@BigSimmo
BigSimmo deleted the claude/medication-workspace-tests-123366 branch July 22, 2026 03:25

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 737c2e8 and 4327537.

📒 Files selected for processing (1)
  • tests/medication-prescribing-workspace.dom.test.tsx

Comment on lines +69 to +85
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,
}),
}));

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.

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

Comment on lines +121 to +124
expect(filterButton("Best").textContent).toContain("3");
expect(filterButton("Indication").textContent).toContain("2");
expect(filterButton("Safety").textContent).toContain("2");
expect(filterButton("Monitor").textContent).toContain("1");

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.

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

Suggested change
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.

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.

1 participant