import { render } from "@testing-library/react"; import { SEO_IDS } from "@/lib/seo"; import { serviceOffers, siteUrl } from "@/lib/site-content"; import CinematicHome from "./CinematicHome"; /** * Dados estruturados da home: um único script `application/ld+json` com as três ofertas (nós Service ligados à * Person). O WebSite e a Person já saem do layout (app/layout.tsx), e repeti-los aqui duplicaria os dados. Sem * ProfessionalService nem LocalBusiness: a política de docs/seo-geo-operations.md os exclui. */ jest.mock("../Hero", () => ({ __esModule: true, default: () => null })); jest.mock("../Projects", () => ({ __esModule: true, default: () => null })); jest.mock("../About", () => ({ __esModule: true, default: () => null })); jest.mock("../WorkModalities", () => ({ WorkModalities: () => null })); jest.mock("../HomeFaq", () => ({ __esModule: true, default: () => null })); jest.mock("../Testimonials", () => ({ __esModule: true, default: () => null })); jest.mock("../Contact", () => ({ __esModule: true, default: () => null })); jest.mock("./CinematicMain", () => ({ __esModule: true, default: ({ children }: { children: React.ReactNode }) => (
{children}
), })); function structuredData() { const { container } = render(); return Array.from( container.querySelectorAll('script[type="application/ld+json"]'), ).map((script) => JSON.parse(script.textContent ?? "")); } describe("CinematicHome: dados estruturados", () => { it("emits exactly one ld+json script, before the scenes", () => { const { container } = render(); const scripts = container.querySelectorAll( 'script[type="application/ld+json"]', ); expect(scripts).toHaveLength(1); expect(container.firstElementChild).toBe(scripts[0]); }); it("describes only the three offers as Service nodes tied to the person, without repeating what the layout emits", () => { const [data] = structuredData(); expect(data["@context"]).toBe("https://schema.org"); expect(data["@graph"]).toHaveLength(3); for (const offer of data["@graph"]) { expect(offer["@type"]).toBe("Service"); expect(offer.provider).toEqual({ "@id": SEO_IDS.person }); expect( offer.areaServed.map(({ name }: { name: string }) => name), ).toEqual(["Garuva", "Joinville", "Santa Catarina", "Brasil"]); } expect(data["@graph"].map(({ name }: { name: string }) => name)).toEqual( serviceOffers.map(({ name }) => name), ); expect(data["@graph"].map(({ url }: { url: string }) => url)).toEqual( serviceOffers.map(({ href }) => `${siteUrl}${href}`), ); expect(JSON.stringify(data)).not.toMatch(/"@type":"(WebSite|Person)"/); }); it("never emits ProfessionalService, LocalBusiness or an offer catalog (docs/seo-geo-operations.md)", () => { const [data] = structuredData(); expect(JSON.stringify(data)).not.toMatch( /ProfessionalService|LocalBusiness|OfferCatalog/, ); }); });