// @vitest-environment jsdom import { cleanup, fireEvent, render, screen, within } from "@testing-library/react"; import { afterEach, expect, test } from "vitest"; import { AlbumContactSheet } from "./catalog-content"; import { PhotoGallery } from "./photo-gallery"; afterEach(cleanup); test("renders granted albums as labelled contact-sheet links", () => { render( , ); const album = screen.getByRole("link", { name: /heimspiel gegen nord/i }); expect(album.getAttribute("href")).toBe("/redaktion/alben/heimspiel"); expect(screen.getByText("24 Fotos")).not.toBeNull(); expect(screen.getByAltText("Titelbild: Heimspiel gegen Nord").getAttribute("src")).toBe( "/api/assets/cover-1/thumbnail", ); }); const photo = { id: "asset-1", filename: "tor-des-sieges.jpg", takenAt: "2026-08-08T18:42:00.000Z", width: null, height: null, albumId: "heimspiel", albumName: "Heimspiel gegen Nord", }; test("renders the gallery list labelled by album name", () => { render(); expect(screen.getByRole("list", { name: /fotos aus heimspiel gegen nord/i })).not.toBeNull(); expect(screen.getByAltText("tor-des-sieges.jpg").getAttribute("src")).toBe( "/api/assets/asset-1/thumbnail", ); }); test("renders the server-scoped download choices for a catalog photo", () => { render( , ); expect(screen.getByRole("button", { name: /original laden/i })).not.toBeNull(); }); test("offers the existing download workflow on a global search result and its lightbox", () => { render( , ); expect(screen.getByRole("button", { name: /original laden/i })).not.toBeNull(); fireEvent.click(screen.getByRole("button", { name: /tor-des-sieges\.jpg vergrößern/i })); expect(within(screen.getByRole("dialog")).getByRole("button", { name: /original laden/i })).not.toBeNull(); }); test("opens a full-screen lightbox when a photo tile is clicked", () => { render( , ); // No lightbox before clicking. expect(screen.queryByRole("dialog")).toBeNull(); fireEvent.click(screen.getByRole("button", { name: /first\.jpg vergrößern/i })); const dialog = screen.getByRole("dialog"); expect(dialog.getAttribute("aria-modal")).toBe("true"); // Lightbox image + tile image both carry the alt, so the dialog contains one. expect(dialog.querySelector(".lightbox-image")?.getAttribute("alt")).toBe("first.jpg"); expect(screen.getByRole("button", { name: /nächstes bild/i })).not.toBeNull(); // No previous on the first photo. expect(screen.queryByRole("button", { name: /vorheriges bild/i })).toBeNull(); });