import { act, render, screen } from "@testing-library/react"; import CinematicOverlays from "./CinematicOverlays"; let mockPathname = "/"; jest.mock("next/navigation", () => ({ usePathname: () => mockPathname })); // o grão vem por import dinâmico (pacote próprio): aqui ele vira um marcador, e o contador diz se o pacote foi pedido const mockLoaded = jest.fn(); jest.mock("./FilmGrain", () => { mockLoaded(); return { __esModule: true, default: function MockGrain() { return
; }, }; }); /** O import dinâmico do grão resolve em microtarefas. */ const loaded = () => act(async () => { for (let i = 0; i < 5; i++) await Promise.resolve(); }); const original = window.matchMedia; function mockMedia(active: string[] = []) { window.matchMedia = jest.fn().mockImplementation((query: string) => ({ matches: active.includes(query), media: query, addEventListener() {}, removeEventListener() {}, })); } beforeEach(() => { mockPathname = "/"; mockMedia(); }); afterEach(() => { window.matchMedia = original; }); /* * Os três primeiros testes vêm antes de qualquer um que carregue o grão: o módulo, depois de pedido uma vez, fica * no registro do Jest, então "o pacote nunca foi pedido" só vale enquanto ninguém o pediu. */ describe("CinematicOverlays: where the grain package is never requested", () => { it("does not request the grain on a touch screen (nothing invisible left measuring the page); the progress bar stays", async () => { mockMedia(["(pointer: coarse)"]); const { container } = render(