Files
immich-redaktions-plugin/src/modules/albums/catalog-content.test.tsx
T

125 lines
3.9 KiB
TypeScript

// @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(
<AlbumContactSheet
albums={[
{
id: "heimspiel",
albumName: "Heimspiel gegen Nord",
description: null,
albumThumbnailAssetId: "cover-1",
assetCount: 24,
},
]}
/>,
);
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(<PhotoGallery albumName="Heimspiel gegen Nord" items={[photo]} />);
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(
<PhotoGallery
albumName="Heimspiel gegen Nord"
downloadOptions={{
priceCents: 1_500,
priorUsagesByAsset: {
"22222222-2222-4222-8222-222222222222": [
{
id: "44444444-4444-4444-8444-444444444444",
purpose: "Titelgeschichte",
createdAt: "2026-08-09T10:00:00.000Z",
},
],
},
}}
items={[
{
...photo,
id: "22222222-2222-4222-8222-222222222222",
filename: "tor.jpg",
albumId: "33333333-3333-4333-8333-333333333333",
},
]}
/>,
);
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(
<PhotoGallery
albumName="Alle Alben"
downloadOptions={{ priceCents: 100, priorUsagesByAsset: {} }}
items={[{
...photo,
id: "22222222-2222-4222-8222-222222222222",
albumId: "33333333-3333-4333-8333-333333333333",
}]}
showAlbumName
/>,
);
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(
<PhotoGallery
albumName="Heimspiel gegen Nord"
items={[
{ ...photo, id: "a", filename: "first.jpg" },
{ ...photo, id: "b", filename: "second.jpg" },
]}
/>,
);
// 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();
});