Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
78 lines
4.7 KiB
TypeScript
78 lines
4.7 KiB
TypeScript
import { render, screen, within } from "@testing-library/react";
|
|
import { describe, it, expect } from "vitest";
|
|
import { LandingPage, type PublicBlock } from "./CmsBlocks";
|
|
|
|
// add-page-sections: card sections, the CTA band, section looks and the image-less hero.
|
|
const company = { code: "INS", name: "INS Sdn Bhd", logoImageId: null, accentColor: "#FFEE00" };
|
|
const page = (blocks: PublicBlock[]) => ({ slug: "hotel", title: "Hotel day", blocks });
|
|
|
|
describe("LandingPage: sections", () => {
|
|
it("shows feature cards with their icons, titles and texts", () => {
|
|
render(<LandingPage company={company} page={page([{
|
|
type: "FEATURES", heading: "What we do", text: "One partner.",
|
|
cards: [{ icon: "wifi", title: "Managed WiFi", text: "Guests connect." }, { icon: "tv", title: "In-room TV", text: "Casting." }],
|
|
}])} />);
|
|
expect(screen.getByRole("heading", { name: "What we do" })).toBeInTheDocument();
|
|
expect(screen.getByText("One partner.")).toBeInTheDocument();
|
|
const items = screen.getAllByRole("listitem");
|
|
expect(items).toHaveLength(2);
|
|
expect(within(items[0]).getByRole("heading", { name: "Managed WiFi" })).toBeInTheDocument();
|
|
expect(items[0].querySelector("svg.lucide-wifi")).not.toBeNull();
|
|
expect(items[1].querySelector("svg.lucide-tv")).not.toBeNull();
|
|
});
|
|
|
|
it("numbers steps in order", () => {
|
|
render(<LandingPage company={company} page={page([{
|
|
type: "STEPS", heading: "How it works",
|
|
cards: [{ title: "Survey", text: "We visit." }, { title: "Install", text: "We fit it." }, { title: "Support", text: "We stay." }],
|
|
}])} />);
|
|
const list = screen.getByRole("list");
|
|
expect(list.tagName).toBe("OL");
|
|
const items = within(list).getAllByRole("listitem");
|
|
expect(items.map((li) => li.textContent)).toEqual(["1SurveyWe visit.", "2InstallWe fit it.", "3SupportWe stay."]);
|
|
});
|
|
|
|
it("shows a trust strip of short items", () => {
|
|
render(<LandingPage company={company} page={page([{ type: "TRUST", cards: [{ title: "Certified with LG" }, { title: "Local support" }] }])} />);
|
|
expect(screen.getAllByRole("listitem").map((li) => li.textContent)).toEqual(["Certified with LG", "Local support"]);
|
|
});
|
|
|
|
it("shows a call-to-action band with its button, and drops an unsafe one", () => {
|
|
render(<LandingPage company={company} page={page([
|
|
{ type: "CTA", heading: "Ready?", text: "Talk to us.", buttonLabel: "Get a quote", buttonUrl: "#signup" },
|
|
{ type: "CTA", heading: "Bad", buttonLabel: "Evil", buttonUrl: "javascript:alert(1)" },
|
|
])} />);
|
|
expect(screen.getByRole("heading", { name: "Ready?" })).toBeInTheDocument();
|
|
expect(screen.getByRole("link", { name: "Get a quote" })).toHaveAttribute("href", "#signup");
|
|
expect(screen.queryByRole("link", { name: "Evil" })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("draws a non-default look as a full-width band and leaves default blocks as before", () => {
|
|
render(<LandingPage company={company} page={page([
|
|
{ type: "CTA", heading: "Dark", buttonLabel: "Go", buttonUrl: "/x", look: "DARK" },
|
|
{ type: "CTA", heading: "Accent", buttonLabel: "Go", buttonUrl: "/x", look: "ACCENT" },
|
|
{ type: "CTA", heading: "Muted", buttonLabel: "Go", buttonUrl: "/x", look: "MUTED" },
|
|
{ type: "CTA", heading: "Plain", buttonLabel: "Go", buttonUrl: "/x" },
|
|
{ type: "CTA", heading: "Junk", buttonLabel: "Go", buttonUrl: "/x", look: "NEON" as never },
|
|
])} />);
|
|
const band = (name: string) => screen.getByRole("heading", { name }).closest("[data-look]");
|
|
expect(band("Dark")).toHaveAttribute("data-look", "DARK");
|
|
expect(band("Dark")).toHaveClass("bg-foreground", "text-background");
|
|
expect(band("Accent")).toHaveClass("bg-primary", "text-primary-foreground");
|
|
expect(band("Muted")).toHaveClass("bg-muted");
|
|
expect(band("Plain")).toBeNull();
|
|
expect(band("Junk")).toBeNull();
|
|
// On an accent band the button flips, so it never matches the band's colour.
|
|
expect(within(band("Accent") as HTMLElement).getByRole("link", { name: "Go" })).toHaveClass("bg-background", "text-foreground");
|
|
});
|
|
|
|
it("shows a hero without an image as text on its look's background", () => {
|
|
render(<LandingPage company={company} page={page([{ type: "HERO", heading: "No picture", buttonLabel: "Join", buttonUrl: "#signup", look: "DARK" }])} />);
|
|
expect(screen.getByRole("heading", { name: "No picture" })).toBeInTheDocument();
|
|
expect(document.querySelector("main img")).toBeNull();
|
|
expect(screen.getByRole("link", { name: "Join" })).toBeInTheDocument();
|
|
// On a band the hero takes the band's colours; its own grey box would put light text on a light background.
|
|
expect(screen.getByRole("heading", { name: "No picture" }).closest("section")).not.toHaveClass("bg-muted");
|
|
});
|
|
});
|