Files
HealthLog/src/lib/dashboard/__tests__/hide-module-widgets.test.ts
T
Marc-André Bombeck 94e07d0d90 fix(dashboard): hide a switched-off module's widgets on every feed
The dashboard widget and summary maps are now views of the surface map.
The legacy dashboard feed painted the stored layout as saved, so the
medications card stayed with the module off; the mask the snapshot
applies now runs on that feed too, in the browser, from the same map.
The widgets route keeps returning the stored layout unmasked, because
Settings saves that value back.

The Today digest is the day's data and no longer waits on the AI
analysis switch, on the server prefetch or in the browser.
2026-09-24 09:42:17 +02:00

43 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { hideModuleWidgets } from "@/lib/dashboard/widget-modules";
const layout = {
version: 2,
widgets: [
{ id: "weight", visible: true, tileVisible: true, order: 0 },
{ id: "medications", visible: true, tileVisible: true, order: 1 },
{ id: "mood", visible: true, tileVisible: true, order: 2 },
{ id: "hrv", visible: true, tileVisible: true, order: 3 },
],
};
describe("hideModuleWidgets", () => {
it("hides the widgets of a switched-off module and keeps their order", () => {
const out = hideModuleWidgets(layout, { medications: false });
expect(out.widgets.map((w) => [w.id, w.visible, w.tileVisible])).toEqual([
["weight", true, true],
["medications", false, false],
["mood", true, true],
["hrv", true, true],
]);
});
it("hides the ids it is told to on top of the module mask", () => {
const out = hideModuleWidgets(layout, {}, new Set(["hrv"]));
expect(out.widgets.find((w) => w.id === "hrv")?.visible).toBe(false);
expect(out.widgets.find((w) => w.id === "mood")?.visible).toBe(true);
});
it("is a no-op before the module map is known", () => {
expect(hideModuleWidgets(layout, undefined).widgets).toEqual(
layout.widgets,
);
});
it("never writes through to the layout it was given", () => {
hideModuleWidgets(layout, { mood: false, medications: false });
expect(layout.widgets.every((w) => w.visible)).toBe(true);
});
});