import { act, render, screen } from "@testing-library/react"; import { describe, it, expect } from "vitest"; import { LandingPage, type PublicBlock } from "./CmsBlocks"; import { FRAME_SANDBOX } from "@/app/lib/frameHtml"; // add-custom-html-block: an HTML block is a sealed frame sized by its own reports; "hide header" drops the header. const company = { code: "INS", name: "INS Sdn Bhd", logoImageId: 4, accentColor: null }; const page = (blocks: PublicBlock[], hideHeader = false) => ({ slug: "hotel", title: "Hotel day", hideHeader, blocks }); const HTML: PublicBlock = { type: "HTML", html: "

Designed

" }; const frame = () => document.querySelector("iframe") as HTMLIFrameElement; describe("LandingPage: Custom HTML", () => { it("shows an HTML block as a sealed frame from its own address, never inline", () => { render(); expect(frame()).toHaveAttribute("src", "/p/INS/hotel/frame/1"); expect(frame()).toHaveAttribute("sandbox", FRAME_SANDBOX); expect(frame()).toHaveAttribute("title", "Hotel day"); expect(frame().style.height).toBe("600px"); expect(screen.queryByText("Designed")).not.toBeInTheDocument(); expect(document.querySelector("script")).toBeNull(); }); it("uses the preview's frame address when given", () => { render(); expect(frame()).toHaveAttribute("src", "/pages/5/preview/frame/0"); }); it("grows to its frame's reported height and ignores other windows", () => { render(); act(() => { window.dispatchEvent(new MessageEvent("message", { data: { type: "colite-frame-height", height: 2400 }, source: window })); }); expect(frame().style.height).toBe("600px"); act(() => { window.dispatchEvent(new MessageEvent("message", { data: { type: "colite-frame-height", height: 2400 }, source: frame().contentWindow })); }); expect(frame().style.height).toBe("2400px"); }); it("hides the company header and shows the title to screen readers only when the page says so", () => { render(); expect(screen.queryByRole("img", { name: "INS Sdn Bhd" })).not.toBeInTheDocument(); expect(document.querySelector("header")).toBeNull(); expect(screen.getByRole("heading", { level: 1, name: "Hotel day" })).toHaveClass("sr-only"); }); it("starts a header-less page flush at the top: the hidden title takes no part in block spacing", () => { render(); const title = screen.getByRole("heading", { level: 1, name: "Hotel day" }); expect(title.parentElement!.className).not.toMatch(/space-y/); expect(frame().parentElement!.className).toMatch(/space-y/); }); });