import { render, screen, within } from "@testing-library/react"; import AiPage, { metadata } from "./page"; it("uses a short search title: with the layout suffix it fits in 44 characters", () => { // o template de app/layout.tsx acrescenta " | Evandro.dev.br" const suffix = " | Evandro.dev.br"; expect(metadata.title).toBe("Revisão de app feito com IA"); expect(`${metadata.title}${suffix}`.length).toBeLessThanOrEqual(44); expect(metadata).toMatchObject({ description: expect.any(String), alternates: { canonical: "https://evandro.dev.br/ia" }, }); // como nas outras páginas, o título da prévia de compartilhamento é o mesmo da busca, sem o sufixo expect(metadata.openGraph?.title).toBe("Revisão de app feito com IA"); expect(metadata.twitter?.title).toBe("Revisão de app feito com IA"); }); it("uses no lime outside the contact actions (the quote on the paper background is ink)", () => { const { container } = render(); expect( container.querySelector('[class*="border-[var(--slash)]"]'), ).toBeNull(); }); it("keeps the full AI content, with the cited incidents summarized only here", () => { render(); expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent( "Seu app feito com IA está pronto para receber clientes? Eu testo antes deles.", ); for (const heading of [ "Se a IA cria um sistema, por que contratar um desenvolvedor?", "O que casos documentados ensinam", "E a LGPD?", ]) { expect(screen.getByRole("heading", { name: heading })).toBeInTheDocument(); } for (const incident of [/Lovable:/, /Replit:/, /Base44:/]) { expect(screen.getByRole("heading", { name: incident })).toBeInTheDocument(); } expect( screen.getByRole("link", { name: "Reportagem da Semafor (em inglês)" }), ).toHaveAttribute("rel", "noopener noreferrer"); }); it("offers WhatsApp conversations about reviewing an AI-built system", () => { render(); const links = screen .getAllByRole("link") .filter((link) => link.getAttribute("href")?.startsWith("https://wa.me/")); expect(links.map((link) => link.textContent)).toEqual([ "Pedir a revisão do meu app", "Avaliar meu projeto", ]); for (const link of links) { const text = new URL(link.getAttribute("href") ?? "").searchParams.get( "text", ); // a mensagem tem de formar uma frase: "Quero conversar sobre a revisão de um aplicativo feito com IA." expect(text).toContain( "Quero conversar sobre a revisão de um aplicativo feito com IA.", ); } }); it("has breadcrumb navigation back to the home", () => { render(); const breadcrumb = screen.getByRole("navigation", { name: "Trilha de navegação", }); expect( within(breadcrumb).getByRole("link", { name: "Início" }), ).toHaveAttribute("href", "/"); expect( within(breadcrumb).getByText("Revisão de app feito com IA"), ).toHaveAttribute("aria-current", "page"); }); it("presents the review as an offer: what the person receives, with no price or deadline", () => { const { container } = render(); const offer = screen.getByRole("heading", { name: "O que você recebe na revisão", }); const section = offer.closest("section") as HTMLElement; const items = within(section) .getAllByRole("listitem") .map((item) => item.querySelector("h3")?.textContent); expect(items).toEqual([ "As falhas de acesso a dados", "O que dá para aproveitar", "O que é melhor refazer", "Um orçamento para pôr em produção", ]); expect(container.textContent).not.toMatch(/R\$|\d+ dias|em até \d+/); }); it("shows the report list in a card on the right half of the hero, next to the headline", () => { render(); const card = screen.getByTestId("ia-review-card"); expect(within(card).getByText("O que você recebe")).toBeInTheDocument(); expect( within(card) .getAllByRole("listitem") .map((item) => item.textContent?.replace(/^\d+/, "")), ).toEqual([ "As falhas de acesso a dados", "O que dá para aproveitar", "O que é melhor refazer", "Um orçamento para pôr em produção", ]); // o cartão divide a grade do hero com o título (metade direita no desktop) e não cria uma região de página const hero = screen.getByRole("heading", { level: 1 }).closest("section"); expect(hero).toContainElement(card); expect(card.parentElement).toHaveClass( "lg:grid-cols-[minmax(0,1.1fr)_minmax(0,0.9fr)]", ); expect(screen.queryByRole("complementary")).toBeNull(); // o título do cartão não repete o h2 "O que você recebe na revisão" da seção seguinte expect( screen.getAllByRole("heading", { name: /O que você recebe/ }), ).toHaveLength(1); }); it("keeps the secondary hero button inside the page: the portfolio cases are not reviews of AI-built apps", () => { render(); const hero = screen.getByRole("heading", { level: 1 }).closest("section"); const secondary = within(hero as HTMLElement).getByRole("link", { name: "Ver como a revisão funciona", }); expect(secondary).toHaveAttribute("href", "#ia-receber"); expect(document.querySelector(`section[id="ia-receber"]`)).not.toBeNull(); for (const link of within(hero as HTMLElement).getAllByRole("link")) { expect(link.getAttribute("href")).not.toMatch(/^\/cases/); } expect( screen.queryByRole("link", { name: "Ver projetos entregues" }), ).toBeNull(); }); it("keeps the incident news collapsed in a
, closed by default", () => { const { container } = render(); const heading = screen.getByRole("heading", { name: "O que casos documentados ensinam", }); const details = heading.closest("details") as HTMLDetailsElement; expect(details).not.toBeNull(); expect(details.open).toBe(false); expect(heading.closest("summary")).not.toBeNull(); for (const incident of [/Lovable:/, /Replit:/, /Base44:/]) { expect(within(details).getByText(incident)).toBeInTheDocument(); } // só os incidentes ficam recolhidos: a oferta e a LGPD ficam à vista expect(container.querySelectorAll("details")).toHaveLength(1); expect( screen .getByRole("heading", { name: "O que você recebe na revisão" }) .closest("details"), ).toBeNull(); });