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();
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();
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();
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();
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();
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();
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");
});
});