mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-13 22:32:04 +00:00
test(01-10): add red assessment and records contracts
- pin honest assessment fallback, exhaustion, foreground, and state envelopes - require consistent save and empty-state add action grammar
This commit is contained in:
1 parent
d8e52b831d
commit
18d0facdfe
7 files changed
+362
-7
No files matched your search
@@ -0,0 +1,80 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
rows: [] as Array<Record<string, unknown>>,
|
||||
}));
|
||||
|
||||
vi.mock("@tanstack/react-query", () => ({
|
||||
useQuery: () => ({
|
||||
data: mocks.rows,
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
refetch: vi.fn(),
|
||||
}),
|
||||
useQueryClient: () => ({ invalidateQueries: vi.fn() }),
|
||||
useMutation: () => ({ mutate: vi.fn(), isPending: false }),
|
||||
}));
|
||||
vi.mock("@/lib/api/api-fetch", () => ({
|
||||
apiDelete: vi.fn(),
|
||||
apiGet: vi.fn(),
|
||||
}));
|
||||
vi.mock("sonner", () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
|
||||
vi.mock("@/components/ui/responsive-sheet", () => ({
|
||||
ResponsiveSheet: () => null,
|
||||
}));
|
||||
vi.mock("@/components/data-list", () => ({
|
||||
DeleteButton: (props: { title: string }) => (
|
||||
<button aria-label={props.title}>Delete</button>
|
||||
),
|
||||
}));
|
||||
|
||||
import { I18nProvider } from "@/lib/i18n/context";
|
||||
import { AllergyManager } from "../allergy-manager";
|
||||
|
||||
function render() {
|
||||
return renderToStaticMarkup(
|
||||
<I18nProvider initialLocale="en">
|
||||
<AllergyManager />
|
||||
</I18nProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.rows = [];
|
||||
});
|
||||
|
||||
describe("<AllergyManager> action grammar", () => {
|
||||
it("shows exactly one first-entry action and no duplicate top add action when empty", () => {
|
||||
const html = render();
|
||||
|
||||
expect(html.match(/Add your first allergy/g)).toHaveLength(1);
|
||||
expect(html).not.toMatch(/>Add allergy<\/button>/);
|
||||
});
|
||||
|
||||
it("shows one normal top add action plus edit/delete controls when populated", () => {
|
||||
mocks.rows = [
|
||||
{
|
||||
id: "allergy-1",
|
||||
substance: "Penicillin",
|
||||
category: "MEDICATION",
|
||||
type: "ALLERGY",
|
||||
severity: "SEVERE",
|
||||
status: "ACTIVE",
|
||||
onsetAt: null,
|
||||
reaction: "Hives",
|
||||
note: null,
|
||||
createdAt: "2026-07-28T10:00:00.000Z",
|
||||
updatedAt: "2026-07-28T10:00:00.000Z",
|
||||
},
|
||||
];
|
||||
|
||||
const html = render();
|
||||
|
||||
expect(html.match(/>Add allergy<\/button>/g)).toHaveLength(1);
|
||||
expect(html).not.toContain("Add your first allergy");
|
||||
expect(html).toContain('aria-label="Edit"');
|
||||
expect(html).toContain('aria-label="Delete this allergy?"');
|
||||
expect(html).toContain("Penicillin");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,77 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
rows: [] as Array<Record<string, unknown>>,
|
||||
}));
|
||||
|
||||
vi.mock("@tanstack/react-query", () => ({
|
||||
useQuery: () => ({
|
||||
data: mocks.rows,
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
refetch: vi.fn(),
|
||||
}),
|
||||
useQueryClient: () => ({ invalidateQueries: vi.fn() }),
|
||||
useMutation: () => ({ mutate: vi.fn(), isPending: false }),
|
||||
}));
|
||||
vi.mock("@/lib/api/api-fetch", () => ({
|
||||
apiDelete: vi.fn(),
|
||||
apiGet: vi.fn(),
|
||||
}));
|
||||
vi.mock("sonner", () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
|
||||
vi.mock("@/components/ui/responsive-sheet", () => ({
|
||||
ResponsiveSheet: () => null,
|
||||
}));
|
||||
vi.mock("@/components/data-list", () => ({
|
||||
DeleteButton: (props: { title: string }) => (
|
||||
<button aria-label={props.title}>Delete</button>
|
||||
),
|
||||
}));
|
||||
|
||||
import { I18nProvider } from "@/lib/i18n/context";
|
||||
import { FamilyHistoryManager } from "../family-history-manager";
|
||||
|
||||
function render() {
|
||||
return renderToStaticMarkup(
|
||||
<I18nProvider initialLocale="en">
|
||||
<FamilyHistoryManager />
|
||||
</I18nProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.rows = [];
|
||||
});
|
||||
|
||||
describe("<FamilyHistoryManager> action grammar", () => {
|
||||
it("shows exactly one first-entry action and no duplicate top add action when empty", () => {
|
||||
const html = render();
|
||||
|
||||
expect(html.match(/Add your first entry/g)).toHaveLength(1);
|
||||
expect(html).not.toMatch(/>Add entry<\/button>/);
|
||||
});
|
||||
|
||||
it("shows one normal top add action plus edit/delete controls when populated", () => {
|
||||
mocks.rows = [
|
||||
{
|
||||
id: "family-1",
|
||||
relationship: "MOTHER",
|
||||
condition: "Type 2 diabetes",
|
||||
ageAtOnset: 55,
|
||||
note: null,
|
||||
createdAt: "2026-07-28T10:00:00.000Z",
|
||||
updatedAt: "2026-07-28T10:00:00.000Z",
|
||||
},
|
||||
];
|
||||
|
||||
const html = render();
|
||||
|
||||
expect(html.match(/>Add entry<\/button>/g)).toHaveLength(1);
|
||||
expect(html).not.toContain("Add your first entry");
|
||||
expect(html).toContain('aria-label="Edit"');
|
||||
expect(html).toContain('aria-label="Delete this entry?"');
|
||||
expect(html).toContain("Type 2 diabetes");
|
||||
expect(html).toContain("Mother");
|
||||
});
|
||||
});
|
||||
@@ -107,6 +107,27 @@ beforeEach(() => {
|
||||
});
|
||||
|
||||
describe("health-profile fact removal control", () => {
|
||||
it("uses one Save label for new and existing lifestyle facts", () => {
|
||||
render();
|
||||
|
||||
const actionLabels = renderedButtons
|
||||
.filter(
|
||||
(props) =>
|
||||
props.type === "button" &&
|
||||
props.variant === "outline" &&
|
||||
typeof props.onClick === "function",
|
||||
)
|
||||
.map((props) => {
|
||||
const children = Array.isArray(props.children)
|
||||
? props.children
|
||||
: [props.children];
|
||||
return children.filter((child) => typeof child === "string").join("");
|
||||
});
|
||||
|
||||
expect(actionLabels).toEqual(["Save", "Save", "Save"]);
|
||||
expect(actionLabels).not.toContain("Correct");
|
||||
});
|
||||
|
||||
it("renders a confirmed removal action only for each recorded current fact", () => {
|
||||
const { html } = render();
|
||||
|
||||
|
||||
Reference in new issue
Block a user