Três ofertas (site que traz pedidos pelo WhatsApp, sistema para tirar a operação da planilha, revisão de sistema existente) com miniatura e formulário com o tipo escolhido; botão principal do hero abre o WhatsApp; moldura da SEV no hero do celular; menu fecha ao navegar, Esc, foco preso incluindo a barra de cookies e espaço para ela; CinematicHome como componente de servidor com ilha cliente; /ia com H1 de oferta e cartão do que você recebe; botão flutuante em aside com transform; AVIF antes de WebP; copy sem repetir contato direto.
70 lines
2.4 KiB
TypeScript
70 lines
2.4 KiB
TypeScript
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import ContactOfferLink from "./ContactOfferLink";
|
|
import { CONTACT_KIND_EVENT } from "./contact-subject";
|
|
|
|
jest.mock("next/link", () => ({
|
|
__esModule: true,
|
|
default: ({
|
|
children,
|
|
prefetch,
|
|
...props
|
|
}: { children?: React.ReactNode; prefetch?: boolean | null } & Record<
|
|
string,
|
|
unknown
|
|
>) => (
|
|
<a data-prefetch={String(prefetch)} {...props}>
|
|
{children}
|
|
</a>
|
|
),
|
|
}));
|
|
|
|
describe("ContactOfferLink", () => {
|
|
it("links to the form with the type in the address, and prefetches nothing until hover or focus", () => {
|
|
render(
|
|
<ContactOfferLink kind="sistema" className="botao">
|
|
Começar pelo sistema
|
|
</ContactOfferLink>,
|
|
);
|
|
|
|
const link = screen.getByRole("link", { name: "Começar pelo sistema" });
|
|
expect(link).toHaveAttribute("href", "/?tipo=sistema#contact");
|
|
expect(link).toHaveClass("botao");
|
|
expect(link).toHaveAttribute("data-prefetch", "false");
|
|
fireEvent.mouseEnter(link);
|
|
expect(link).toHaveAttribute("data-prefetch", "null");
|
|
});
|
|
|
|
it("tells the form which type was chosen, through a window event, when it is clicked", () => {
|
|
const heard: unknown[] = [];
|
|
const listener = (event: Event) =>
|
|
heard.push((event as CustomEvent).detail);
|
|
window.addEventListener(CONTACT_KIND_EVENT, listener);
|
|
try {
|
|
render(<ContactOfferLink kind="revisao">Começar</ContactOfferLink>);
|
|
|
|
fireEvent.click(screen.getByRole("link", { name: "Começar" }));
|
|
expect(heard).toEqual(["revisao"]);
|
|
} finally {
|
|
window.removeEventListener(CONTACT_KIND_EVENT, listener);
|
|
}
|
|
});
|
|
|
|
it("still tells the form when another handler already cancelled the click (the home scroll manager does that to scroll by itself)", () => {
|
|
const heard: unknown[] = [];
|
|
const listener = (event: Event) =>
|
|
heard.push((event as CustomEvent).detail);
|
|
const cancel = (event: Event) => event.preventDefault();
|
|
window.addEventListener(CONTACT_KIND_EVENT, listener);
|
|
document.addEventListener("click", cancel, true);
|
|
try {
|
|
render(<ContactOfferLink kind="site">Começar</ContactOfferLink>);
|
|
|
|
fireEvent.click(screen.getByRole("link", { name: "Começar" }));
|
|
expect(heard).toEqual(["site"]);
|
|
} finally {
|
|
window.removeEventListener(CONTACT_KIND_EVENT, listener);
|
|
document.removeEventListener("click", cancel, true);
|
|
}
|
|
});
|
|
});
|