Hero e movimento - cena 3D em tempo real com os blocos da marca (kit feito no Blender, 3d/blocos.py): marca, tela, integrações e dados; segue a rolagem, tem vida em repouso, reage ao cursor e, parada no topo, passa sozinha pelos estados com legenda - três níveis de aparelho (full, lite, static); sem WebGL fica o pôster - título novo: "Sites e sistemas sob medida para o jeito que a sua empresa trabalha." - faixa de clientes com o ramo, linha do primeiro passo, hero alinhado às seções - rótulos digitados, entrada dos blocos, cortina de blocos entre páginas e capa compartilhada entre a lista de cases e o case Ofertas - atendimento no WhatsApp com IA e nota fiscal para a reforma tributária (páginas de serviço, cartões da home, formulário e aviso com data de validade) - página /ia atualizada, com fontes - peças 3D em loop nos cartões e topos de página (3d/pecas.py) Design - hover por papel (bloco nos botões, barra nos links), rótulos sem caixa alta - um destino por rótulo: "Falar sobre meu projeto" leva ao formulário, "Chamar no WhatsApp" abre o WhatsApp - logo montado em blocos, 404 redesenhado, grades sem célula vazia - ícones do PWA e manifesto novos Specs em specs/, contexto de design em DESIGN.md e PRODUCT.md.
160 lines
4.6 KiB
TypeScript
160 lines
4.6 KiB
TypeScript
import { render, screen } from "@testing-library/react";
|
|
import { useEffect, useState } from "react";
|
|
import { setNavigation } from "@/__mocks__/next/navigation";
|
|
import { resetFocusOnNavigation } from "./hooks/useFocusOnNavigation";
|
|
import Template from "./template";
|
|
|
|
const mockMounts = jest.fn();
|
|
const mockProps: Array<Record<string, unknown>> = [];
|
|
|
|
// o React estável do Jest não exporta <ViewTransition> (só o canary do Next); este dublê conta as montagens
|
|
jest.mock("react", () => {
|
|
const actual = jest.requireActual("react");
|
|
function ViewTransition({
|
|
children,
|
|
...props
|
|
}: { children?: React.ReactNode } & Record<string, unknown>) {
|
|
mockProps.push(props);
|
|
actual.useEffect(() => {
|
|
mockMounts();
|
|
}, []);
|
|
return actual.createElement("div", { "data-testid": "vt" }, children);
|
|
}
|
|
return { ...actual, ViewTransition };
|
|
});
|
|
|
|
function Counter() {
|
|
const [count, setCount] = useState(0);
|
|
useEffect(() => {
|
|
setCount(1);
|
|
}, []);
|
|
return <p data-testid="state">{count}</p>;
|
|
}
|
|
|
|
beforeEach(() => {
|
|
setNavigation({ pathname: "/cases" });
|
|
mockMounts.mockClear();
|
|
mockProps.length = 0;
|
|
resetFocusOnNavigation();
|
|
});
|
|
|
|
/** O contêiner que o layout põe em volta da página: o destino do foco depois da troca. */
|
|
function Shell({ children }: { children: React.ReactNode }) {
|
|
return (
|
|
<div id="main-content" tabIndex={-1} data-testid="main">
|
|
<Template>{children}</Template>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
describe("app/template", () => {
|
|
it("wraps the page in a ViewTransition of class page, without a name, that does not animate in-place updates", () => {
|
|
render(
|
|
<Template>
|
|
<main>Conteúdo</main>
|
|
</Template>,
|
|
);
|
|
|
|
expect(screen.getByTestId("vt")).toContainElement(screen.getByRole("main"));
|
|
expect(mockProps[0]).toMatchObject({ default: "page", update: "none" });
|
|
// sem nome: a página que sai e a que entra não formam par, e cada uma fica onde estava na tela
|
|
expect(mockProps[0]).not.toHaveProperty("name");
|
|
});
|
|
|
|
it("remounts the page (one exit, one entry) when only the second segment changes (/cases -> /cases/um-projeto)", () => {
|
|
const { rerender } = render(
|
|
<Template>
|
|
<Counter />
|
|
</Template>,
|
|
);
|
|
expect(mockMounts).toHaveBeenCalledTimes(1);
|
|
expect(screen.getByTestId("state")).toHaveTextContent("1");
|
|
|
|
setNavigation({ pathname: "/cases/sev-modaintima" });
|
|
rerender(
|
|
<Template>
|
|
<Counter />
|
|
</Template>,
|
|
);
|
|
|
|
// a chave é o caminho: a transição desmonta a página que sai e monta a que entra (e o estado dela recomeça)
|
|
expect(mockMounts).toHaveBeenCalledTimes(2);
|
|
});
|
|
|
|
it("does not remount when the path stays the same (only a re-render, or a #fragment change)", () => {
|
|
const { rerender } = render(
|
|
<Template>
|
|
<Counter />
|
|
</Template>,
|
|
);
|
|
|
|
rerender(
|
|
<Template>
|
|
<Counter />
|
|
</Template>,
|
|
);
|
|
|
|
expect(mockMounts).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("leaves the focus alone on the first load and moves it to #main-content, without scrolling, when the path changes", () => {
|
|
const scrollTo = jest.spyOn(window, "scrollTo");
|
|
const focus = jest.spyOn(HTMLElement.prototype, "focus");
|
|
const { rerender } = render(
|
|
<Shell>
|
|
<button type="button">Dentro da página</button>
|
|
</Shell>,
|
|
);
|
|
expect(focus).not.toHaveBeenCalled();
|
|
expect(screen.getByTestId("main")).not.toHaveFocus();
|
|
|
|
setNavigation({ pathname: "/cases/sev-modaintima" });
|
|
rerender(
|
|
<Shell>
|
|
<button type="button">Dentro da página</button>
|
|
</Shell>,
|
|
);
|
|
|
|
expect(screen.getByTestId("main")).toHaveFocus();
|
|
expect(focus).toHaveBeenCalledWith({ preventScroll: true });
|
|
expect(scrollTo).not.toHaveBeenCalled();
|
|
focus.mockRestore();
|
|
scrollTo.mockRestore();
|
|
});
|
|
|
|
it("does not take the focus on a re-render of the same path", () => {
|
|
const { rerender } = render(
|
|
<Shell>
|
|
<p>Página</p>
|
|
</Shell>,
|
|
);
|
|
rerender(
|
|
<Shell>
|
|
<p>Página de novo</p>
|
|
</Shell>,
|
|
);
|
|
expect(screen.getByTestId("main")).not.toHaveFocus();
|
|
});
|
|
|
|
it("never starts a view transition by itself, on the first load or on the focus move", () => {
|
|
const start = jest.fn();
|
|
Object.defineProperty(document, "startViewTransition", {
|
|
configurable: true,
|
|
value: start,
|
|
});
|
|
const { rerender } = render(
|
|
<Shell>
|
|
<p>Página</p>
|
|
</Shell>,
|
|
);
|
|
setNavigation({ pathname: "/servicos" });
|
|
rerender(
|
|
<Shell>
|
|
<p>Página</p>
|
|
</Shell>,
|
|
);
|
|
expect(start).not.toHaveBeenCalled();
|
|
Reflect.deleteProperty(document, "startViewTransition");
|
|
});
|
|
});
|