mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 15:23:29 +00:00
Until v1.4.14 the layout schema in `lib/dashboard-layout.ts` had a single `visible` flag per widget that controlled BOTH the upper-row strip tile AND the lower-row chart for the same metric. Marc wanted them as independent toggles — to keep the chart visible for tracking without the tile cluttering the strip, or vice versa. Schema upgrade (back-compat): - New optional `tileVisible: boolean` on `DashboardWidgetConfig`. When omitted on a saved layout, `resolveDashboardLayout()` mirrors it from `visible` so legacy users see no behavioural change until they flip the new switch. `serializeDashboardLayout()` always writes the field explicitly so a re-read keeps the user's choice. - Zod input schema (`/api/dashboard/widgets`) marks the field optional so older clients (web v1.4.14 cache, native iOS) can keep PUTting their existing payload shape. - Default layout sets `tileVisible: true` for the seven default-on widgets and `tileVisible: false` for the six default-off ones. Settings UI: - The single-column toggle list grows a SECOND switch column. Header row labels them "Tile" / "Kachel" and "Chart" / "Chart". Each widget now paints two switches (`data-slot="widget-tile-switch"` and `widget-chart-switch`) with discrete `aria-label`s `<metric> — Tile` / `<metric> — Chart` so a screen-reader user can tell them apart. Dashboard render (`src/app/page.tsx`): - `isWidgetVisible(id)` split into `isTileVisible(id)` (new flag with mirror fallback) and `isChartVisible(id)` (legacy flag). Each metric now has a `showXxxTile` AND `showXxxChart` gate. Glucose has no separate chart slot today, so its single flag still maps to the tile flag. Tests: - `resolveDashboardLayout()`: mirrors tileVisible from visible for legacy layouts, respects an explicit value, auto-appends new widgets with both flags `false`, defaults gracefully on null input. - `serializeDashboardLayout()`: persists tileVisible explicitly, derives from visible when missing, normalises order to dense 0-based. - `<DashboardLayoutSection>` SSR smoke: column headers paint EN + DE, both switch slots present, exactly one tile-switch + one chart-switch per widget. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
76 lines
2.7 KiB
TypeScript
76 lines
2.7 KiB
TypeScript
import { describe, it, expect, vi } from "vitest";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
|
|
import { DEFAULT_DASHBOARD_LAYOUT } from "@/lib/dashboard-layout";
|
|
|
|
/**
|
|
* v1.4.15 Fix 5 — independent strip-tile + chart toggles.
|
|
*
|
|
* The settings section grew a SECOND switch column for the upper-row
|
|
* tile, distinct from the existing chart switch. SSR smoke tests are
|
|
* sufficient here; full state-mutation testing would require a DOM
|
|
* runtime which the rest of the settings suite doesn't pull in.
|
|
*/
|
|
|
|
vi.mock("@tanstack/react-query", () => ({
|
|
useQuery: () => ({ data: DEFAULT_DASHBOARD_LAYOUT, isLoading: false }),
|
|
useQueryClient: () => ({ setQueryData: vi.fn() }),
|
|
useMutation: () => ({
|
|
mutate: vi.fn(),
|
|
mutateAsync: vi.fn(),
|
|
isPending: false,
|
|
}),
|
|
}));
|
|
|
|
vi.mock("sonner", () => ({
|
|
toast: {
|
|
success: vi.fn(),
|
|
error: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
import { I18nProvider } from "@/lib/i18n/context";
|
|
import { DashboardLayoutSection } from "../dashboard-layout-section";
|
|
|
|
function render(node: React.ReactElement, locale: "en" | "de" = "en") {
|
|
return renderToStaticMarkup(
|
|
<I18nProvider initialLocale={locale}>{node}</I18nProvider>,
|
|
);
|
|
}
|
|
|
|
describe("<DashboardLayoutSection> — tile + chart split", () => {
|
|
it("renders both Tile and Chart column headers in English", () => {
|
|
const html = render(<DashboardLayoutSection id="dashboard-layout" />);
|
|
// Column headers — the v1.4.15 split.
|
|
expect(html).toContain("Tile");
|
|
expect(html).toContain("Chart");
|
|
});
|
|
|
|
it("renders both column headers in German", () => {
|
|
const html = render(
|
|
<DashboardLayoutSection id="dashboard-layout" />,
|
|
"de",
|
|
);
|
|
expect(html).toContain("Kachel");
|
|
expect(html).toContain("Chart");
|
|
});
|
|
|
|
it("paints both switch slots per widget", () => {
|
|
const html = render(<DashboardLayoutSection id="dashboard-layout" />);
|
|
// The two new data-slots distinguish tile vs chart switches in
|
|
// visual-verify and other consumers.
|
|
expect(html).toContain('data-slot="widget-tile-switch"');
|
|
expect(html).toContain('data-slot="widget-chart-switch"');
|
|
});
|
|
|
|
it("each widget paints exactly one tile-switch and one chart-switch", () => {
|
|
const html = render(<DashboardLayoutSection id="dashboard-layout" />);
|
|
const tileSwitches = html.match(/data-slot="widget-tile-switch"/g) ?? [];
|
|
const chartSwitches = html.match(/data-slot="widget-chart-switch"/g) ?? [];
|
|
// Default layout has 13 widgets — both switch counts must match
|
|
// exactly so the split control covers every widget.
|
|
expect(tileSwitches).toHaveLength(DEFAULT_DASHBOARD_LAYOUT.widgets.length);
|
|
expect(chartSwitches).toHaveLength(DEFAULT_DASHBOARD_LAYOUT.widgets.length);
|
|
});
|
|
});
|