release: v1.32.0 — hardening and scalability (#580)

* release: prepare v1.32.0

* test: stabilize water capture re-entry
This commit is contained in:
Marc-André Bombeck authored and GitHub committed 2026-07-22 04:14:15 +02:00
1 parent b01822be48
commit 62eb431d66
372 files changed
+25178 -8561

No files matched your search

@@ -0,0 +1,183 @@
import type * as ReactModule from "react";
import { isValidElement, type ReactElement, type ReactNode } from "react";
import { beforeEach, describe, expect, it, vi } from "vitest";
const hookState = vi.hoisted(() => ({
cursor: 0,
values: [] as unknown[],
}));
const captureState = vi.hoisted(() => ({
dirty: true,
nutrientsEnabled: true,
}));
vi.mock("react", async (importOriginal) => {
const actual = await importOriginal<typeof ReactModule>();
return {
...actual,
useState<T>(initialValue: T | (() => T)) {
const index = hookState.cursor++;
if (!(index in hookState.values)) {
hookState.values[index] =
typeof initialValue === "function"
? (initialValue as () => T)()
: initialValue;
}
const setValue = (nextValue: T | ((current: T) => T)) => {
const current = hookState.values[index] as T;
hookState.values[index] =
typeof nextValue === "function"
? (nextValue as (value: T) => T)(current)
: nextValue;
};
return [hookState.values[index] as T, setValue] as const;
},
};
});
vi.mock("@/lib/i18n/context", () => ({
useTranslations: () => ({ t: (key: string) => key }),
}));
vi.mock("@/hooks/use-module-enabled", () => ({
useModuleEnabled: () => captureState.nutrientsEnabled,
}));
vi.mock("@/components/dashboard/quick-entry-sheets", () => ({
sheetBodyHasUnsavedInput: () => captureState.dirty,
}));
function markedComponent(displayName: string) {
const Component = ({ children }: { children?: ReactNode }) => children;
Component.displayName = displayName;
return Component;
}
vi.mock("@/components/ui/responsive-sheet", () => ({
ResponsiveSheet: markedComponent("ResponsiveSheet"),
}));
vi.mock("@/components/ui/alert-dialog", () => ({
AlertDialog: markedComponent("AlertDialog"),
AlertDialogAction: markedComponent("AlertDialogAction"),
AlertDialogCancel: markedComponent("AlertDialogCancel"),
AlertDialogContent: markedComponent("AlertDialogContent"),
AlertDialogDescription: markedComponent("AlertDialogDescription"),
AlertDialogFooter: markedComponent("AlertDialogFooter"),
AlertDialogHeader: markedComponent("AlertDialogHeader"),
AlertDialogTitle: markedComponent("AlertDialogTitle"),
}));
vi.mock("@/components/measurements/measurement-form", () => ({
MeasurementForm: markedComponent("MeasurementForm"),
}));
vi.mock("@/components/mood/mood-form", () => ({
MoodForm: markedComponent("MoodForm"),
}));
vi.mock("@/components/dashboard/medication-intake-quick-add", () => ({
MedicationIntakeQuickAdd: markedComponent("MedicationIntakeQuickAdd"),
}));
vi.mock("@/components/insights/nutrients/water-quick-add-sheet", () => ({
WaterQuickAddSheet: markedComponent("WaterQuickAddSheet"),
}));
import { CapturePicker } from "../capture-picker";
type ElementProps = Record<string, unknown> & { children?: ReactNode };
type TestElement = ReactElement<ElementProps>;
function elementsIn(node: ReactNode): TestElement[] {
if (Array.isArray(node)) return node.flatMap(elementsIn);
if (!isValidElement<ElementProps>(node)) return [];
return [node, ...elementsIn(node.props.children)];
}
function renderPicker(): ReactNode {
hookState.cursor = 0;
return CapturePicker({ open: true, onOpenChange: vi.fn() });
}
function findByTestId(tree: ReactNode, testId: string): TestElement {
const element = elementsIn(tree).find(
(candidate) => candidate.props["data-testid"] === testId,
);
expect(element, `missing data-testid=${testId}`).toBeDefined();
return element!;
}
function findMarked(tree: ReactNode, displayName: string): TestElement | null {
return (
elementsIn(tree).find(
(element) =>
typeof element.type === "function" &&
"displayName" in element.type &&
element.type.displayName === displayName,
) ?? null
);
}
class WaterDraftHarness {
private mounted = false;
private amount = "";
observe(tree: ReactNode): TestElement | null {
const sheet = findMarked(tree, "WaterQuickAddSheet");
if (!sheet) {
this.mounted = false;
this.amount = "";
} else if (!this.mounted) {
this.mounted = true;
this.amount = "";
}
return sheet;
}
fill(value: string) {
expect(this.mounted).toBe(true);
this.amount = value;
}
value() {
return this.amount;
}
}
describe("<CapturePicker> — confirmed water discard", () => {
beforeEach(() => {
hookState.cursor = 0;
hookState.values.length = 0;
captureState.dirty = true;
captureState.nutrientsEnabled = true;
});
it("reopens with a fresh custom amount after confirmed discard", () => {
const draft = new WaterDraftHarness();
let tree = renderPicker();
draft.observe(tree);
const waterOption = findByTestId(tree, "capture-picker-water");
(waterOption.props.onClick as () => void)();
tree = renderPicker();
const waterSheet = draft.observe(tree);
expect(waterSheet?.props.open).toBe(true);
draft.fill("375");
(waterSheet?.props.onOpenChange as (open: boolean) => void)(false);
tree = renderPicker();
const confirmDiscard = findMarked(tree, "AlertDialogAction");
expect(confirmDiscard).not.toBeNull();
expect(draft.observe(tree)?.props.open).toBe(true);
expect(draft.value()).toBe("375");
(confirmDiscard?.props.onClick as () => void)();
tree = renderPicker();
expect(draft.observe(tree)).toBeNull();
const reopenedWaterOption = findByTestId(tree, "capture-picker-water");
(reopenedWaterOption.props.onClick as () => void)();
tree = renderPicker();
expect(draft.observe(tree)?.props.open).toBe(true);
expect(draft.value()).toBe("");
});
});
@@ -0,0 +1,70 @@
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,
}));
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"');
});
});
+8 -6
View File
@@ -278,12 +278,14 @@ export function AuthShell({
it). Focus restores both — the element jumps back into the
viewport and becomes clickable.
*/}
<a
href="#main-content"
className="bg-primary text-primary-foreground pointer-events-none fixed top-2 left-2 z-[100] -translate-y-full rounded-md px-4 py-2 text-sm font-medium opacity-0 transition-transform focus:pointer-events-auto focus:translate-y-0 focus:opacity-100"
>
{t("nav.skipToContent")}
</a>
<nav aria-label={t("nav.skipToContent")}>
<a
href="#main-content"
className="bg-primary text-primary-foreground pointer-events-none fixed top-2 left-2 z-[100] -translate-y-full rounded-md px-4 py-2 text-sm font-medium opacity-0 transition-transform focus:pointer-events-auto focus:translate-y-0 focus:opacity-100"
>
{t("nav.skipToContent")}
</a>
</nav>
<div className="flex h-dvh flex-col md:flex-row">
<SidebarNav />
{/* `min-w-0` lets the content column shrink below its children's
+47 -27
View File
@@ -1,11 +1,12 @@
"use client";
import { useState } from "react";
import { Activity, Pill, Waves } from "lucide-react";
import { Activity, GlassWater, Pill, Waves } from "lucide-react";
import { MeasurementForm } from "@/components/measurements/measurement-form";
import { MoodForm } from "@/components/mood/mood-form";
import { MedicationIntakeQuickAdd } from "@/components/dashboard/medication-intake-quick-add";
import { WaterQuickAddSheet } from "@/components/insights/nutrients/water-quick-add-sheet";
import { ResponsiveSheet } from "@/components/ui/responsive-sheet";
import {
AlertDialog,
@@ -19,20 +20,20 @@ import {
} from "@/components/ui/alert-dialog";
import { sheetBodyHasUnsavedInput } from "@/components/dashboard/quick-entry-sheets";
import { useTranslations } from "@/lib/i18n/context";
import { useModuleEnabled } from "@/hooks/use-module-enabled";
/**
* The center "Log" capture action (iOS parity — the bottom bar's
* middle slot is a capture CTA, not a destination). It opens a small
* picker that routes to one of three existing quick-entry surfaces:
* picker that routes to four existing quick-entry surfaces:
*
* - Measurement → `<MeasurementForm>` (the `/measurements` add form)
* - Medication → `<MedicationIntakeQuickAdd>` (the dashboard intake
* quick-add)
* - Medication → `<MedicationIntakeQuickAdd>` (dashboard quick-add)
* - Mood → `<MoodForm>` (the `/mood` add form, 5-face flow)
* - Water → `<WaterQuickAddSheet>` (the hydration quick-add)
*
* All three forms share the `{ onSuccess, onCancel, footerSlot }`
* contract and are designed to mount inside `<ResponsiveSheet>`, so the
* picker reuses them verbatim rather than rebuilding any capture UI.
* The picker reuses each existing capture component rather than
* rebuilding parallel forms.
*
* Nothing here orphans a route: the same surfaces remain reachable
* from their own pages (`/measurements`, `/mood`, dashboard) and from
@@ -45,7 +46,7 @@ import { useTranslations } from "@/lib/i18n/context";
* instead of closing unconditionally.
*/
type CaptureKind = "measurement" | "medication" | "mood";
type CaptureKind = "measurement" | "medication" | "mood" | "water";
interface CapturePickerProps {
/** Whether the picker chooser sheet is open. */
@@ -56,6 +57,7 @@ interface CapturePickerProps {
export function CapturePicker({ open, onOpenChange }: CapturePickerProps) {
const { t } = useTranslations();
const nutrientsEnabled = useModuleEnabled("nutrients");
const [kind, setKind] = useState<CaptureKind | null>(null);
const [footerEl, setFooterEl] = useState<HTMLDivElement | null>(null);
// v1.30.1 — mirrors `QuickEntrySheets`' `confirmDiscardOpen`: hold a
@@ -64,6 +66,7 @@ export function CapturePicker({ open, onOpenChange }: CapturePickerProps) {
const [confirmDiscardOpen, setConfirmDiscardOpen] = useState(false);
function chooseKind(next: CaptureKind) {
if (next === "water" && !nutrientsEnabled) return;
// Close the chooser first, then open the form sheet so only one
// bottom-sheet is mounted at a time (no stacked backdrops).
onOpenChange(false);
@@ -110,12 +113,19 @@ export function CapturePicker({ open, onOpenChange }: CapturePickerProps) {
description: t("nav.capture.moodDescription"),
icon: Waves,
},
{
kind: "water",
label: t("nav.capture.water"),
description: t("nav.capture.waterDescription"),
icon: GlassWater,
},
];
const formTitleByKind: Record<CaptureKind, string> = {
measurement: t("measurements.addMeasurement"),
medication: t("nav.capture.medication"),
mood: t("mood.addEntry"),
water: t("nutrients.hydration.quickAddTitle"),
};
// `kind === null` keeps the form sheet closed (the title is unread then);
// the mood label is the harmless default, matching the prior ternary's
@@ -135,31 +145,33 @@ export function CapturePicker({ open, onOpenChange }: CapturePickerProps) {
className="grid grid-cols-1 gap-2"
data-testid="capture-picker-options"
>
{options.map((opt) => (
<button
key={opt.kind}
type="button"
data-testid={`capture-picker-${opt.kind}`}
onClick={() => chooseKind(opt.kind)}
className="border-border hover:bg-accent/40 focus-visible:ring-ring/50 flex min-h-14 items-center gap-3 rounded-lg border px-4 py-3 text-left transition-colors focus-visible:ring-2 focus-visible:outline-none"
>
<span className="bg-primary/10 text-primary flex h-9 w-9 shrink-0 items-center justify-center rounded-full">
<opt.icon className="h-5 w-5" aria-hidden="true" />
</span>
<span className="min-w-0">
<span className="block text-sm font-medium">{opt.label}</span>
<span className="text-muted-foreground block text-xs">
{opt.description}
{options.map((opt) =>
opt.kind !== "water" || nutrientsEnabled ? (
<button
key={opt.kind}
type="button"
data-testid={`capture-picker-${opt.kind}`}
onClick={() => chooseKind(opt.kind)}
className="border-border hover:bg-accent/40 focus-visible:ring-ring/50 flex min-h-14 items-center gap-3 rounded-lg border px-4 py-3 text-left transition-colors focus-visible:ring-2 focus-visible:outline-none"
>
<span className="bg-primary/10 text-primary flex h-9 w-9 shrink-0 items-center justify-center rounded-full">
<opt.icon className="h-5 w-5" aria-hidden="true" />
</span>
</span>
</button>
))}
<span className="min-w-0">
<span className="block text-sm font-medium">{opt.label}</span>
<span className="text-muted-foreground block text-xs">
{opt.description}
</span>
</span>
</button>
) : null,
)}
</div>
</ResponsiveSheet>
{/* The chosen capture surface, reusing the existing form. */}
<ResponsiveSheet
open={kind !== null}
open={kind !== null && kind !== "water"}
onOpenChange={handleFormOpenChange}
title={formTitle}
footer={<div ref={setFooterEl} className="flex w-full" />}
@@ -187,6 +199,14 @@ export function CapturePicker({ open, onOpenChange }: CapturePickerProps) {
)}
</ResponsiveSheet>
{nutrientsEnabled && kind === "water" && (
<WaterQuickAddSheet
open
onOpenChange={handleFormOpenChange}
onSuccess={closeForm}
/>
)}
{/* v1.30.1 — confirm before discarding a partly-filled capture
form when the sheet is dismissed by an overlay tap, Escape,
or a mobile swipe-down. Copy shared with the dashboard