Files
portifolio-evandrodevbr/app/components/Hero.paths.test.tsx
T
Evandro Fonseca Junior 9e2d65a926 fix(home): oferta leva ao formulário, ofertas logo depois da vitrine
O botão das ofertas rola até o contato com o tipo marcado e não quebra mais as âncoras; ofertas com o que você recebe e primeiro passo, logo depois da vitrine; bloco de IA fora da home; cartão largo da SEV no hero do celular; separador da faixa de clientes só entre itens; favicon de 13 para 1,8 KB; pré-carregamento só no hover e nunca de /#... fora da home; X do menu e cabeçalho opaco; WhatsApp com "o case"; /ia com 3 passos e modelo de relatório ilustrativo; Sobre alinhado ao currículo; CSP Report-Only com os domínios do Ads.
2026-10-14 19:14:47 -03:00

132 lines
4.2 KiB
TypeScript

import { fireEvent, render, screen } from "@testing-library/react";
import Hero from "./Hero";
/**
* Testes de caminhos-base de Hero (complemento de Hero.test.tsx): anos de experiência (sem stats, sem anos, zero anos, com anos),
* links sociais (externo x mailto, com rastreio), faixa de clientes e endereço do trabalho em destaque.
*/
jest.mock("./cinematic/HeroField", () => ({
__esModule: true,
default: () => <div data-testid="hero-field" />,
}));
beforeEach(() => {
jest.replaceProperty(process.env, "NODE_ENV", "production");
localStorage.setItem("evandro.analytics-consent.v1", "granted");
window.gtag = jest.fn();
});
afterEach(() => {
jest.restoreAllMocks();
localStorage.clear();
delete window.gtag;
});
describe("Hero: anos de experiência (na linha de clientes)", () => {
it.each([
["no stats at all", undefined],
["stats without years", {}],
["zero years", { years: 0 }],
])("path: %s -> no experience text", (_label, stats) => {
const { container } = render(<Hero stats={stats} />);
expect(container.querySelector("dl")).toBeNull();
expect(screen.queryByText("anos de experiência")).toBeNull();
});
it("path: years given -> the number and its label sit in the same line as the clients", () => {
const { container } = render(
<Hero
stats={{ years: 7 }}
clients={[{ id: "lavacao-047", name: "Lavação 047" }]}
/>,
);
expect(container.querySelector("dl")).toBeNull();
const strip = screen.getByText("Já entregue para:").parentElement;
expect(strip).toHaveTextContent("Lavação 047");
expect(strip).toHaveTextContent("7 anos de experiência");
});
it("path: years given but no clients -> only the experience text, with no 'Já entregue para'", () => {
render(<Hero stats={{ years: 7 }} />);
expect(screen.getByText("anos de experiência")).toBeInTheDocument();
expect(screen.queryByText("Já entregue para:")).toBeNull();
});
});
describe("Hero: links sociais", () => {
it("path: LinkedIn (http link) -> new tab with noopener and a social_click", () => {
render(<Hero />);
const link = screen.getByRole("link", { name: "LinkedIn" });
expect(link).toHaveAttribute("target", "_blank");
expect(link).toHaveAttribute("rel", "noopener noreferrer");
fireEvent.click(link, { button: 0 });
expect(window.gtag).toHaveBeenCalledWith(
"event",
"social_click",
expect.objectContaining({ network: "linkedin" }),
);
});
it("path: e-mail (mailto link) -> same tab, no rel, and an email_click from the hero", () => {
render(<Hero />);
const link = screen.getByRole("link", { name: "Email" });
expect(link).not.toHaveAttribute("target");
expect(link).not.toHaveAttribute("rel");
link.addEventListener("click", (event) => event.preventDefault());
fireEvent.click(link, { button: 0 });
expect(window.gtag).toHaveBeenCalledWith(
"event",
"email_click",
expect.objectContaining({ placement: "hero" }),
);
});
});
describe("Hero: faixa de clientes e trabalho em destaque", () => {
it("path: clients given -> the strip links each client to its case", () => {
render(<Hero clients={[{ id: "lavacao-047", name: "Lavação 047" }]} />);
expect(screen.getByText("Já entregue para:")).toBeInTheDocument();
expect(screen.getByRole("link", { name: "Lavação 047" })).toHaveAttribute(
"href",
"/cases/lavacao-047",
);
});
it("path: no clients -> no strip", () => {
render(<Hero />);
expect(screen.queryByText("Já entregue para:")).toBeNull();
});
it("path: workUrl given -> the browser bar of the featured work shows it", () => {
render(<Hero workUrl={{ text: "lavacao.example.com", secure: true }} />);
expect(screen.getByTestId("hero-work")).toHaveTextContent(
"lavacao.example.com",
);
});
it("path: workUrl omitted -> the browser bar shows no address", () => {
render(<Hero />);
expect(screen.getByTestId("hero-work")).not.toHaveTextContent(".com");
});
it("path: the main button carries the id that hides the floating WhatsApp", () => {
render(<Hero />);
expect(
screen.getByRole("link", { name: /Falar sobre meu projeto/ }),
).toHaveAttribute("id", "hero-contact-cta");
});
});