mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 08:12:52 +00:00
Merge branch 'fix/v1475-mobile' into release/v1.47.5
# Conflicts: # src/__tests__/baselines/source-function-lines.json # src/__tests__/baselines/version-stamp-comments.json
This commit is contained in:
commit
ad483fa4bc
52 files changed
+1838
-1027
No files matched your search
@@ -1,140 +0,0 @@
|
||||
/**
|
||||
* v1.11.5 — `sheetBodyHasUnsavedInput` dirty-check coverage.
|
||||
*
|
||||
* The quick-entry sheets confirm-on-dismiss only when the body holds unsaved
|
||||
* input. The original walk read `input` / `textarea` only, so a user who
|
||||
* changed just the mood `role="radio"` selector or opened a Radix Select
|
||||
* (type / medication) could lose the change on a backdrop dismiss with no
|
||||
* confirm. These cases lock the extended detection in — and pin the
|
||||
* over-trigger guard so a pristine sheet (no radio chosen, every Select on its
|
||||
* default and closed) still reads clean.
|
||||
*
|
||||
* The repo runs vitest in the Node environment (no jsdom / happy-dom). The
|
||||
* function only ever touches `document.querySelector` once (the sheet body) and
|
||||
* then `body.querySelectorAll` / `body.querySelector` against three fixed
|
||||
* selectors, so we drive it with a hand-rolled fake `document` that answers
|
||||
* exactly those selectors — no DOM engine, matching the repo's node-only test
|
||||
* convention (cf. the SSR-string tests elsewhere).
|
||||
*/
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { sheetBodyHasUnsavedInput } from "@/components/dashboard/quick-entry-sheets";
|
||||
|
||||
const BODY_SELECTOR = '[data-slot="responsive-sheet-body"]';
|
||||
const MOOD_RADIO_SELECTOR = '[role="radio"][aria-checked="true"]';
|
||||
const OPEN_SELECT_SELECTOR = '[role="combobox"][data-state="open"]';
|
||||
|
||||
interface FakeField {
|
||||
type: string;
|
||||
value?: string;
|
||||
disabled?: boolean;
|
||||
checked?: boolean;
|
||||
defaultChecked?: boolean;
|
||||
}
|
||||
|
||||
interface SheetFixture {
|
||||
fields?: FakeField[];
|
||||
moodRadioSelected?: boolean;
|
||||
openSelect?: boolean;
|
||||
}
|
||||
|
||||
/** Install a fake `document` whose queries answer the given fixture. */
|
||||
function installFakeDocument(fixture: SheetFixture | null): void {
|
||||
const body = fixture
|
||||
? {
|
||||
querySelectorAll: (sel: string) =>
|
||||
sel === "input, textarea" ? (fixture.fields ?? []) : [],
|
||||
querySelector: (sel: string) => {
|
||||
if (sel === MOOD_RADIO_SELECTOR)
|
||||
return fixture.moodRadioSelected ? {} : null;
|
||||
if (sel === OPEN_SELECT_SELECTOR)
|
||||
return fixture.openSelect ? {} : null;
|
||||
return null;
|
||||
},
|
||||
}
|
||||
: null;
|
||||
|
||||
(globalThis as { document?: unknown }).document = {
|
||||
querySelector: (sel: string) => (sel === BODY_SELECTOR ? body : null),
|
||||
};
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
delete (globalThis as { document?: unknown }).document;
|
||||
});
|
||||
|
||||
describe("sheetBodyHasUnsavedInput — mood radio", () => {
|
||||
it("is clean when no mood radio is selected (pristine)", () => {
|
||||
installFakeDocument({ moodRadioSelected: false });
|
||||
expect(sheetBodyHasUnsavedInput()).toBe(false);
|
||||
});
|
||||
|
||||
it("is dirty when a mood radio is selected", () => {
|
||||
installFakeDocument({ moodRadioSelected: true });
|
||||
expect(sheetBodyHasUnsavedInput()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("sheetBodyHasUnsavedInput — Radix Select", () => {
|
||||
it("is clean for a closed Select on its default value (no over-trigger)", () => {
|
||||
// A measurement-type / medication Select mounts with a non-placeholder
|
||||
// DEFAULT and is closed — a pristine sheet must NOT prompt the confirm.
|
||||
installFakeDocument({ openSelect: false });
|
||||
expect(sheetBodyHasUnsavedInput()).toBe(false);
|
||||
});
|
||||
|
||||
it("is dirty while a Select dropdown is open (mid-interaction)", () => {
|
||||
installFakeDocument({ openSelect: true });
|
||||
expect(sheetBodyHasUnsavedInput()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("sheetBodyHasUnsavedInput — text fields still honoured", () => {
|
||||
it("is clean for an empty pristine sheet", () => {
|
||||
installFakeDocument({
|
||||
fields: [
|
||||
{ type: "text", value: "" },
|
||||
{ type: "textarea", value: "" },
|
||||
{ type: "datetime-local", value: "2026-06-04T08:00" },
|
||||
],
|
||||
});
|
||||
expect(sheetBodyHasUnsavedInput()).toBe(false);
|
||||
});
|
||||
|
||||
it("is dirty when a text input carries a value", () => {
|
||||
installFakeDocument({ fields: [{ type: "text", value: "75.5" }] });
|
||||
expect(sheetBodyHasUnsavedInput()).toBe(true);
|
||||
});
|
||||
|
||||
it("ignores a prefilled date/time picker (v1.11.4 H1)", () => {
|
||||
installFakeDocument({
|
||||
fields: [{ type: "datetime-local", value: "2026-06-04T08:00" }],
|
||||
});
|
||||
expect(sheetBodyHasUnsavedInput()).toBe(false);
|
||||
});
|
||||
|
||||
it("ignores a disabled field carrying a value", () => {
|
||||
installFakeDocument({
|
||||
fields: [{ type: "text", value: "ignored", disabled: true }],
|
||||
});
|
||||
expect(sheetBodyHasUnsavedInput()).toBe(false);
|
||||
});
|
||||
|
||||
it("is dirty for a native checkbox toggled off its default", () => {
|
||||
installFakeDocument({
|
||||
fields: [{ type: "checkbox", checked: true, defaultChecked: false }],
|
||||
});
|
||||
expect(sheetBodyHasUnsavedInput()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("sheetBodyHasUnsavedInput — no sheet body", () => {
|
||||
it("is clean when no sheet body is mounted", () => {
|
||||
installFakeDocument(null);
|
||||
expect(sheetBodyHasUnsavedInput()).toBe(false);
|
||||
});
|
||||
|
||||
it("is clean when document is undefined (SSR)", () => {
|
||||
delete (globalThis as { document?: unknown }).document;
|
||||
expect(sheetBodyHasUnsavedInput()).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -31,7 +31,10 @@ import {
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { PageHeader } from "@/components/ui/page-header";
|
||||
import { PullToRefreshIndicator } from "@/components/ui/pull-to-refresh-indicator";
|
||||
import { ResponsiveSheet } from "@/components/ui/responsive-sheet";
|
||||
import {
|
||||
ResponsiveSheet,
|
||||
sheetBodyHasUnsavedInput,
|
||||
} from "@/components/ui/responsive-sheet";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { useMounted } from "@/hooks/use-mounted";
|
||||
import { useRecordCapabilities } from "@/hooks/use-record-capabilities";
|
||||
@@ -218,6 +221,7 @@ export default function LabsPage() {
|
||||
<ResponsiveSheet
|
||||
open={dialogOpen}
|
||||
onOpenChange={setDialogOpen}
|
||||
dirty={sheetBodyHasUnsavedInput}
|
||||
title={t("labs.addResult")}
|
||||
description={t("labs.addDescription")}
|
||||
footer={
|
||||
|
||||
@@ -16,7 +16,10 @@ import { Button } from "@/components/ui/button";
|
||||
import { PageHeader } from "@/components/ui/page-header";
|
||||
import { PageAuthGate } from "@/components/ui/page-auth-gate";
|
||||
import { PullToRefreshIndicator } from "@/components/ui/pull-to-refresh-indicator";
|
||||
import { ResponsiveSheet } from "@/components/ui/responsive-sheet";
|
||||
import {
|
||||
ResponsiveSheet,
|
||||
sheetBodyHasUnsavedInput,
|
||||
} from "@/components/ui/responsive-sheet";
|
||||
import { RevealWhenSettled } from "@/components/ui/reveal-when-settled";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Plus } from "lucide-react";
|
||||
@@ -179,6 +182,7 @@ export default function MeasurementsPage() {
|
||||
refuses. */}
|
||||
<ResponsiveSheet
|
||||
open={dialogOpen && canAddMeasurement}
|
||||
dirty={sheetBodyHasUnsavedInput}
|
||||
onOpenChange={(open) => {
|
||||
setDialogOpen(open);
|
||||
if (!open) {
|
||||
|
||||
@@ -46,6 +46,7 @@ vi.mock("@/lib/i18n/context", () => ({
|
||||
vi.mock("@/components/ui/responsive-sheet", () => ({
|
||||
ResponsiveSheet: ({ open }: { open: boolean; children?: ReactNode }) =>
|
||||
open ? <div data-slot="mood-sheet-open" /> : null,
|
||||
sheetBodyHasUnsavedInput: () => false,
|
||||
}));
|
||||
vi.mock("@/components/mood/mood-form", () => ({ MoodForm: () => null }));
|
||||
vi.mock("@/components/mood/mood-list", () => ({ MoodList: () => null }));
|
||||
|
||||
@@ -13,7 +13,10 @@ import { Button } from "@/components/ui/button";
|
||||
import { PageHeader } from "@/components/ui/page-header";
|
||||
import { PageAuthGate } from "@/components/ui/page-auth-gate";
|
||||
import { PullToRefreshIndicator } from "@/components/ui/pull-to-refresh-indicator";
|
||||
import { ResponsiveSheet } from "@/components/ui/responsive-sheet";
|
||||
import {
|
||||
ResponsiveSheet,
|
||||
sheetBodyHasUnsavedInput,
|
||||
} from "@/components/ui/responsive-sheet";
|
||||
import { ArrowRight, Plus, Wrench } from "lucide-react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { useEffect } from "react";
|
||||
@@ -177,6 +180,7 @@ export default function MoodPageClient() {
|
||||
<ResponsiveSheet
|
||||
open={sheetOpen}
|
||||
onOpenChange={setSheetOpen}
|
||||
dirty={sheetBodyHasUnsavedInput}
|
||||
title={t("dashboard.quickAddMood")}
|
||||
footer={<div ref={setFooterEl} className="flex w-full" />}
|
||||
>
|
||||
|
||||
Reference in new issue
Block a user