diff --git a/src/lib/__tests__/cardLayout.test.ts b/src/lib/__tests__/cardLayout.test.ts index 2342648..81f1fa8 100644 --- a/src/lib/__tests__/cardLayout.test.ts +++ b/src/lib/__tests__/cardLayout.test.ts @@ -49,6 +49,22 @@ describe("cardLayout utilities", () => { }); describe("toggleBlockVisibility", () => { + + it("toggles block visibility correctly for a custom mock layout and preserves extra properties", () => { + const mockLayout = { + extraProp: "preserved", + blocks: [ + { id: "profile" as const, visible: true, column: "full" as const }, + { id: "stats" as const, visible: false, column: "left" as const } + ] + } as unknown as import("../types").CardLayout; + + const next = toggleBlockVisibility(mockLayout, "profile"); + + expect(next).toHaveProperty("extraProp", "preserved"); + expect(next.blocks.find(b => b.id === "profile")?.visible).toBe(false); + expect(next.blocks.find(b => b.id === "stats")?.visible).toBe(false); + }); it("toggles block visibility to false", () => { const layout = cloneDefaultCardLayout(); // 'bio' is visible by default const next = toggleBlockVisibility(layout, "bio"); diff --git a/src/lib/cardLayout.ts b/src/lib/cardLayout.ts index 16f4f38..f30a493 100644 --- a/src/lib/cardLayout.ts +++ b/src/lib/cardLayout.ts @@ -70,6 +70,7 @@ export function normalizeCardLayout(input: unknown): CardLayout { export function toggleBlockVisibility(layout: CardLayout, blockId: CardBlockId): CardLayout { return { + ...layout, blocks: layout.blocks.map((block) => block.id === blockId ? { ...block, visible: !block.visible } : block ),