65d98cf674
SP21 Task 2.5 — the Dashboard's 'Recent activity' card now routes clicks
to the matching entity drawer / page by event kind:
- claim_* → /claims?claim=<id> (drawer in Phase 5)
- provider_added → /providers?provider=<npi> (ProviderDrawer)
- remit_received → toast 'coming in a later phase' (RemitDrawer in Phase 4)
- anything else → toast (manual_match, unknown kinds)
Implementation:
- New src/lib/event-routing.ts with the eventKindToUrl() helper,
plus a unit test covering all 6 + default branches.
- src/components/ActivityFeed.tsx gains an optional onItemClick
prop; when set, each row gets role='button', tabIndex=0, the
drillable hover affordance (chevron + tint), and an Enter/Space
keybinding. e.stopPropagation() is called before the handler so a
parent row click can't double-fire (same fix as Task 2.4).
- src/pages/Dashboard.tsx wires the handler on the 'Recent activity'
card via eventKindToUrl + sonner toast for unhandled kinds.
- Backend: CycloneStore.recent_activity() now exposes claimId and
remittanceId on each row (read from ActivityEvent.claim_id /
remittance_id) so the routing helper has the entity ids it needs.
- The frontend Activity interface gains optional claimId /
remittanceId fields; the in-memory sample data and the
addClaim store action populate them so the dashboard works in
both API-configured and sample-data modes.
152 lines
5.1 KiB
TypeScript
152 lines
5.1 KiB
TypeScript
// @vitest-environment happy-dom
|
|
// SP21 Task 2.5: Dashboard "Recent activity" card routes clicks by event
|
|
// kind. This test verifies the wiring end-to-end: a `claim_paid` event
|
|
// in the activity slice becomes a clickable row that navigates to
|
|
// `/claims?claim=<id>`, while a `remit_received` event surfaces a
|
|
// "coming in a later phase" toast (since the RemitDrawer lands in
|
|
// Phase 4).
|
|
//
|
|
// `Dashboard` reads `claims`, `providers`, `activity` from the
|
|
// `useAppStore` slice, so we override the slice directly via
|
|
// `useAppStore.setState` instead of mocking `useActivity` — the
|
|
// sample-data mode is exactly what the dashboard sees when no API is
|
|
// configured, so the test stays faithful to production behavior.
|
|
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { cleanup, fireEvent, render } from "@testing-library/react";
|
|
import { MemoryRouter } from "react-router-dom";
|
|
import { Dashboard } from "./Dashboard";
|
|
import { useAppStore } from "@/store";
|
|
import type { Activity } from "@/types";
|
|
|
|
// sonner renders toasts through a portal; jsdom has no layout so the
|
|
// `position` style is a no-op. We just verify that `toast.info` is
|
|
// called with the expected message — sonner itself has its own tests.
|
|
vi.mock("sonner", () => ({
|
|
toast: {
|
|
info: vi.fn(),
|
|
success: vi.fn(),
|
|
error: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
// Capture navigation side effects so we can assert on the URL the
|
|
// Dashboard would push. We use a `MemoryRouter` (initialEntries=["/"])
|
|
// and observe the rendered route via a tiny listener component that
|
|
// reads the current `<MemoryRouter>` entry — no real `window.history`
|
|
// or `BrowserRouter` required.
|
|
import { useLocation } from "react-router-dom";
|
|
|
|
function LocationProbe() {
|
|
const loc = useLocation();
|
|
return (
|
|
<div
|
|
data-testid="location"
|
|
data-pathname={loc.pathname}
|
|
data-search={loc.search}
|
|
/>
|
|
);
|
|
}
|
|
|
|
afterEach(() => {
|
|
cleanup();
|
|
vi.clearAllMocks();
|
|
// Reset the activity slice so tests don't bleed into each other.
|
|
useAppStore.setState({ activity: [] });
|
|
});
|
|
|
|
describe("Dashboard · Recent activity event routing (SP21 Task 2.5)", () => {
|
|
it("navigates to /claims?claim=ID when a claim_paid event is clicked", () => {
|
|
const activity: Activity[] = [
|
|
{
|
|
id: "ae-1",
|
|
kind: "claim_paid",
|
|
message: "Paid CLM-42 · Jordan Smith",
|
|
timestamp: "2026-06-20T12:00:00Z",
|
|
claimId: "CLM-42",
|
|
remittanceId: null,
|
|
},
|
|
];
|
|
useAppStore.setState({ activity });
|
|
|
|
const { getByTestId, getByRole } = render(
|
|
<MemoryRouter initialEntries={["/"]}>
|
|
<Dashboard />
|
|
<LocationProbe />
|
|
</MemoryRouter>,
|
|
);
|
|
|
|
// The row becomes a button-like <li> with role="button" and a
|
|
// descriptive aria-label derived from the kind.
|
|
const row = getByRole("button", { name: /View claim paid/ });
|
|
fireEvent.click(row);
|
|
|
|
const probe = getByTestId("location");
|
|
expect(probe.getAttribute("data-pathname")).toBe("/claims");
|
|
expect(probe.getAttribute("data-search")).toBe("?claim=CLM-42");
|
|
});
|
|
|
|
it("navigates to /providers?provider=NPI when a provider_added event is clicked", () => {
|
|
const activity: Activity[] = [
|
|
{
|
|
id: "ae-2",
|
|
kind: "provider_added",
|
|
message: "Added Cedar Park Family Medicine",
|
|
timestamp: "2026-06-20T12:00:00Z",
|
|
npi: "1730187395",
|
|
claimId: null,
|
|
remittanceId: null,
|
|
},
|
|
];
|
|
useAppStore.setState({ activity });
|
|
|
|
const { getByTestId, getByRole } = render(
|
|
<MemoryRouter initialEntries={["/"]}>
|
|
<Dashboard />
|
|
<LocationProbe />
|
|
</MemoryRouter>,
|
|
);
|
|
|
|
fireEvent.click(getByRole("button", { name: /View provider added/ }));
|
|
|
|
const probe = getByTestId("location");
|
|
expect(probe.getAttribute("data-pathname")).toBe("/providers");
|
|
expect(probe.getAttribute("data-search")).toBe("?provider=1730187395");
|
|
});
|
|
|
|
it("fires the toast (no navigation) for remit_received — Phase 4 drawer", async () => {
|
|
const { toast } = await import("sonner");
|
|
const activity: Activity[] = [
|
|
{
|
|
id: "ae-3",
|
|
kind: "remit_received",
|
|
message: "Remit REM-7 received",
|
|
timestamp: "2026-06-20T12:00:00Z",
|
|
claimId: null,
|
|
remittanceId: "REM-7",
|
|
},
|
|
];
|
|
useAppStore.setState({ activity });
|
|
|
|
const { getByTestId, getByRole } = render(
|
|
<MemoryRouter initialEntries={["/"]}>
|
|
<Dashboard />
|
|
<LocationProbe />
|
|
</MemoryRouter>,
|
|
);
|
|
|
|
fireEvent.click(getByRole("button", { name: /View remit received/ }));
|
|
|
|
expect(toast.info).toHaveBeenCalledTimes(1);
|
|
const msg = (toast.info as ReturnType<typeof vi.fn>).mock.calls[0]?.[0] as string;
|
|
expect(msg).toMatch(/remit received/i);
|
|
expect(msg).toMatch(/coming in a later phase/i);
|
|
|
|
// URL must not have changed — the toast path is non-navigating.
|
|
const probe = getByTestId("location");
|
|
expect(probe.getAttribute("data-pathname")).toBe("/");
|
|
expect(probe.getAttribute("data-search")).toBe("");
|
|
});
|
|
});
|