import { act, fireEvent, render, screen, within } from "@testing-library/react"; import { renderToString } from "react-dom/server"; import { getFeaturedProjects } from "@/lib/portfolio-data"; import { getShowcaseConfig, mobileFractionAt } from "@/lib/project-showcase"; import { ProjectReel } from "./ProjectReel"; import { ShowcaseProvider } from "./ShowcaseProvider"; import { reelOffset, videoProgress } from "./showcase-math"; let reducedMotion = false; jest.mock("@/app/hooks/useReducedMotion", () => ({ useReducedMotion: () => reducedMotion, })); const PIN = 800; const CONTAINER = 7000; const SCROLLABLE = CONTAINER - PIN; const HEADER = 60; let reelTop = HEADER; const projects = getFeaturedProjects(null); const weights = [ "sev-modaintima", "lavacao-047", "nutriscan", "sc-plus", "as-servicos", ].map((id) => getShowcaseConfig(id)?.weight ?? 1); const originalRect = Element.prototype.getBoundingClientRect; const originalOffsetHeight = Object.getOwnPropertyDescriptor( HTMLElement.prototype, "offsetHeight", ); beforeAll(() => { Object.defineProperty(HTMLElement.prototype, "offsetHeight", { configurable: true, get(this: HTMLElement) { if (this.classList.contains("ds-reel")) return CONTAINER; if (this.classList.contains("ds-reel-pin")) return PIN; return 0; }, }); Element.prototype.getBoundingClientRect = function rect(this: Element) { if (this.classList.contains("ds-reel")) return { top: reelTop, bottom: reelTop + CONTAINER, height: CONTAINER, left: 0, right: 1000, width: 1000, x: 0, y: reelTop, } as DOMRect; return originalRect.call(this); }; window.scrollTo = jest.fn(); }); afterAll(() => { Element.prototype.getBoundingClientRect = originalRect; if (originalOffsetHeight) Object.defineProperty( HTMLElement.prototype, "offsetHeight", originalOffsetHeight, ); }); beforeEach(() => { jest.useFakeTimers(); reducedMotion = false; reelTop = HEADER; (window.scrollTo as jest.Mock).mockClear(); jest.spyOn(HTMLMediaElement.prototype, "play").mockResolvedValue(); jest.spyOn(HTMLMediaElement.prototype, "pause").mockImplementation(() => {}); }); afterEach(() => { jest.useRealTimers(); jest.restoreAllMocks(); }); function renderReel() { const view = render( , ); act(() => { jest.advanceTimersByTime(50); }); return view; } /** jsdom não carrega mídia: cada