Files
co-lite/solvway-admin-portal/app/components/pages/CmsBlocks.html.test.tsx
T
ngqileandClaude Opus 5.5 36dbb4c949 fix(pages): keep the frame's sandbox policy past the config headers
next.config's baseline Content-Security-Policy replaced the frame route's
own header, so a frame address opened directly ran without the sandbox.
A later headers rule for the two frame paths restores it. Also drop the
gap above a header-less page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
2026-12-02 18:18:51 +08:00

51 lines
2.9 KiB
TypeScript

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: "<h1>Designed</h1><script>x()</script>" };
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(<LandingPage company={company} page={page([{ type: "FAQ", items: [{ question: "Q", answer: "A" }] }, HTML])} />);
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(<LandingPage company={company} page={page([HTML])} frameBase="/pages/5/preview/frame" preview />);
expect(frame()).toHaveAttribute("src", "/pages/5/preview/frame/0");
});
it("grows to its frame's reported height and ignores other windows", () => {
render(<LandingPage company={company} page={page([HTML])} />);
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(<LandingPage company={company} page={page([HTML], true)} />);
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(<LandingPage company={company} page={page([HTML], true)} />);
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/);
});
});