import { render, screen } from "@testing-library/react"; import { getShowcaseAssets } from "@/lib/project-showcase"; import { CaseCover } from "./CaseCover"; import { getCaseMedia } from "./case-media"; /** * Testes de caminhos-base de CaseCover: sem captura (nada), com captura (moldura + pôster) * e os valores padrão de `sizes` e `priority`. */ jest.mock("./case-media", () => ({ getCaseMedia: jest.fn() })); const mockedGetCaseMedia = jest.mocked(getCaseMedia); const props = { id: "sev-modaintima", title: "SEV Moda Íntima", demoUrl: "https://sevmodaintima.com.br", }; afterEach(() => { mockedGetCaseMedia.mockReset(); }); describe("CaseCover", () => { it("path: no desktop capture -> renders nothing", () => { mockedGetCaseMedia.mockReturnValue(undefined); const { container } = render(); expect(container).toBeEmptyDOMElement(); expect(mockedGetCaseMedia).toHaveBeenCalledWith(props.id, "desktop"); }); it("path: capture found -> poster inside the browser frame, with the real domain in the bar", () => { mockedGetCaseMedia.mockImplementation(getShowcaseAssets); const { container } = render(); const image = screen.getByAltText(`Captura de tela do site ${props.title}`); expect(container.querySelector(".ds-bframe")).toContainElement(image); expect(image.getAttribute("src")).toContain( encodeURIComponent(`/videos/${props.id}/desktop.webp`), ); expect(container.querySelector(".ds-bframe-url")).toHaveTextContent( "sevmodaintima.com.br", ); }); it("path: sizes and priority omitted -> default sizes and lazy loading", () => { mockedGetCaseMedia.mockImplementation(getShowcaseAssets); render(); const image = screen.getByAltText(`Captura de tela do site ${props.title}`); expect(image).toHaveAttribute("sizes", "(min-width: 1024px) 560px, 100vw"); expect(image).toHaveAttribute("loading", "lazy"); }); it("path: sizes and priority given -> uses them", () => { mockedGetCaseMedia.mockImplementation(getShowcaseAssets); render(); const image = screen.getByAltText(`Captura de tela do site ${props.title}`); expect(image).toHaveAttribute("sizes", "320px"); expect(image).not.toHaveAttribute("loading", "lazy"); }); });