48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { render, screen } from "@testing-library/react";
|
|
import { expect, test, vi } from "vitest";
|
|
|
|
import { EditorialDetailContent } from "@/modules/editorials/admin-detail";
|
|
import { AlbumGrantError } from "@/modules/albums/grants";
|
|
import { loadAssignableAlbums } from "./page-content";
|
|
|
|
const editorial = {
|
|
id: "00000000-0000-4000-8000-000000000001",
|
|
name: "Neue Redaktion",
|
|
contactName: "Mara Muster",
|
|
loginEmail: "mara@example.com",
|
|
status: "pending_approval" as const,
|
|
emailVerifiedAt: null,
|
|
currentPriceCents: null,
|
|
};
|
|
|
|
test("the editorial detail links admins to its album-assignment page", () => {
|
|
render(<EditorialDetailContent editorial={editorial} hasActiveGrant={false} />);
|
|
|
|
expect(screen.getByRole("link", { name: /albumrechte verwalten/i }).getAttribute("href")).toBe(
|
|
"/admin/redaktionen/00000000-0000-4000-8000-000000000001/alben",
|
|
);
|
|
expect(screen.queryByText(/folgt im nächsten schritt/i)).toBeNull();
|
|
});
|
|
|
|
test("only an explicit Immich-unavailable error renders the unavailable album state", async () => {
|
|
const service = {
|
|
listAssignableAlbums: vi.fn().mockRejectedValue(new AlbumGrantError("IMMICH_UNAVAILABLE")),
|
|
};
|
|
|
|
await expect(loadAssignableAlbums(editorial.id, service)).resolves.toEqual({
|
|
albums: [],
|
|
unavailable: true,
|
|
});
|
|
});
|
|
|
|
test("database and programming errors propagate instead of being displayed as Immich unavailable", async () => {
|
|
const databaseFailure = new Error("database connection lost");
|
|
const service = {
|
|
listAssignableAlbums: vi.fn().mockRejectedValue(databaseFailure),
|
|
};
|
|
|
|
await expect(loadAssignableAlbums(editorial.id, service)).rejects.toBe(databaseFailure);
|
|
});
|