mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 15:42:24 +00:00
Three controls carry most of the app's mutation surface between them. The row delete is spelled once for measurements, lab results, biomarkers, allergies, family history, custom metrics and medication supply; the selection bar is the only bulk delete; the capture picker is the fastest path to four entry forms on a phone and bypasses every page header. Deleting belongs to the owner at every grant level, so the first two are absent inside somebody else's record rather than greyed out: a disabled bin still claims the row is the delegate's to remove. The picker keeps the two kinds a delegation admits and drops a mood entry and a glass of water, which the server refuses under a switch; when nothing survives, the bar's plus button goes with them instead of opening an empty sheet.
84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
|
|
import { I18nProvider } from "@/lib/i18n/context";
|
|
|
|
const moduleGate = vi.hoisted(() => ({ nutrientsEnabled: true }));
|
|
|
|
vi.mock("@/hooks/use-module-enabled", () => ({
|
|
useModuleEnabled: (moduleKey: string) =>
|
|
moduleKey === "nutrients" ? moduleGate.nutrientsEnabled : true,
|
|
}));
|
|
|
|
// v1.36.x — the picker asks what the record allows before it offers a kind.
|
|
// These fixtures are the caller's own record, which is every kind; the
|
|
// delegation cases are covered in
|
|
// `src/components/__tests__/delegated-write-affordances.test.tsx`.
|
|
vi.mock("@/hooks/use-record-capabilities", () => ({
|
|
useRecordCapabilities: () => ({
|
|
inSharedRecord: false,
|
|
canWrite: false,
|
|
canAdd: true,
|
|
canManage: true,
|
|
}),
|
|
}));
|
|
|
|
vi.mock("@/components/ui/responsive-sheet", () => ({
|
|
ResponsiveSheet: ({
|
|
open,
|
|
children,
|
|
}: {
|
|
open: boolean;
|
|
children: React.ReactNode;
|
|
}) => (open ? <section>{children}</section> : null),
|
|
}));
|
|
|
|
vi.mock("@/components/measurements/measurement-form", () => ({
|
|
MeasurementForm: () => <div data-testid="measurement-form" />,
|
|
}));
|
|
|
|
vi.mock("@/components/mood/mood-form", () => ({
|
|
MoodForm: () => <div data-testid="mood-form" />,
|
|
}));
|
|
|
|
vi.mock("@/components/dashboard/medication-intake-quick-add", () => ({
|
|
MedicationIntakeQuickAdd: () => <div data-testid="medication-form" />,
|
|
}));
|
|
|
|
vi.mock("@/components/insights/nutrients/water-quick-add-sheet", () => ({
|
|
WaterQuickAddSheet: () => <div data-testid="water-quick-add-sheet" />,
|
|
}));
|
|
|
|
import { CapturePicker } from "../capture-picker";
|
|
|
|
function render() {
|
|
return renderToStaticMarkup(
|
|
<I18nProvider initialLocale="en">
|
|
<CapturePicker open onOpenChange={() => undefined} />
|
|
</I18nProvider>,
|
|
);
|
|
}
|
|
|
|
describe("<CapturePicker> — nutrients module gate", () => {
|
|
it("hides and unmounts only water capture when nutrients are disabled", () => {
|
|
moduleGate.nutrientsEnabled = false;
|
|
|
|
const html = render();
|
|
|
|
expect(html).not.toContain('data-testid="capture-picker-water"');
|
|
expect(html).not.toContain('data-testid="water-quick-add-sheet"');
|
|
expect(html).toContain('data-testid="capture-picker-measurement"');
|
|
expect(html).toContain('data-testid="capture-picker-medication"');
|
|
expect(html).toContain('data-testid="capture-picker-mood"');
|
|
});
|
|
|
|
it("keeps water capture available when nutrients are enabled", () => {
|
|
moduleGate.nutrientsEnabled = true;
|
|
|
|
const html = render();
|
|
|
|
expect(html).toContain('data-testid="capture-picker-water"');
|
|
expect(html).not.toContain('data-testid="water-quick-add-sheet"');
|
|
});
|
|
});
|