import { render, screen } from "@testing-library/react"; import { getRelatedServices } from "@/lib/site-content"; import { CaseContactSection } from "./CaseContactSection"; /** * Testes de caminhos-base de CaseContactSection: o convite de um case de cliente ("projeto parecido") e o de * um projeto de laboratório ("problema parecido"), o link para a lista de cases e os serviços ligados. */ const sev = { id: "sev-modaintima", title: "SEV Moda Íntima" }; const nutri = { id: "nutriscan", title: "NutriScan" }; function messageOf(link: HTMLElement) { return new URL(link.getAttribute("href") ?? "").searchParams.get("text"); } describe("CaseContactSection", () => { it("path: client case -> 'projeto parecido' invitation, WhatsApp with the case title, services listed", () => { render(); expect( screen.getByRole("heading", { level: 2, name: "Quer um projeto parecido com este?", }), ).toBeVisible(); const cta = screen.getByRole("link", { name: "Conversar sobre um projeto parecido", }); expect(cta).toHaveAttribute("target", "_blank"); expect(messageOf(cta)).toContain( `Quero conversar sobre um projeto parecido com o da ${sev.title}.`, ); expect(getRelatedServices(sev.id).length).toBeGreaterThan(0); expect( screen.getAllByRole("link", { name: /^Ver o serviço:/ }).length, ).toBeGreaterThan(0); expect( screen.getByRole("link", { name: "Ver outros cases" }), ).toHaveAttribute("href", "/cases"); }); it("path: laboratory case -> 'problema parecido' invitation and no mention of a similar project", () => { render(); expect( screen.getByRole("heading", { level: 2, name: "Fale sobre o seu caso" }), ).toBeVisible(); const cta = screen.getByRole("link", { name: "Tem um problema parecido? Vamos conversar.", }); expect(messageOf(cta)).toContain( `Quero conversar sobre um problema parecido com o do projeto ${nutri.title}.`, ); expect( screen.queryByRole("link", { name: "Conversar sobre um projeto parecido", }), ).toBeNull(); // o NutriScan não é citado por nenhum serviço: sem cartões, o convite continua expect(getRelatedServices(nutri.id)).toHaveLength(0); expect(screen.queryByRole("link", { name: /^Ver o serviço:/ })).toBeNull(); expect( screen.getByRole("link", { name: "Ver outros cases" }), ).toBeVisible(); }); });