- ZIP download from the Merkzettel: every photo is a new usage by default; only already downloaded photos offer "Neu / Bereits genutzt" (SegmentedControl), with thumbnails and a cost summary. "Bild auslassen" is gone. - Toasts (Sakani Toaster) for admin saves, deletes and errors; billing errors are readable and use router.refresh instead of reloads. Errors inside modal dialogs stay inline (a toast would sit behind the backdrop). - Album overview in blog-listing style, Sakani Pagination for albums, search and usage history, skeleton loading states. - Registration stepper; verification mail lands on step 3. - Editorials as a searchable, filterable table; audit log with event picker, German labels and collapsible details. - Release notes 2.4.0 seeded (migration 0009). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
191 lines
5.1 KiB
TypeScript
191 lines
5.1 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { render, screen, fireEvent, cleanup } from "@testing-library/react";
|
|
import { afterEach, expect, test, vi } from "vitest";
|
|
|
|
vi.mock("next/navigation", () => ({ useRouter: () => ({ refresh: vi.fn(), push: vi.fn() }) }));
|
|
|
|
import { BillingSelection } from "./BillingSelection";
|
|
import type { FinalizedReportSummary } from "./page-content";
|
|
import type { BillingPosition, RepeatDownloadPosition } from "@/modules/billing/queries";
|
|
|
|
afterEach(cleanup);
|
|
|
|
const openPosition: BillingPosition = {
|
|
id: "u1",
|
|
assetId: "asset-1",
|
|
filename: "jubel.jpg",
|
|
albumName: "Presse 2026",
|
|
purpose: "Titelgeschichte",
|
|
reference: "Ausgabe 8/26",
|
|
priceCents: 6_000,
|
|
collab: false,
|
|
status: "open",
|
|
selectable: true,
|
|
createdAt: new Date("2026-08-05T10:00:00.000Z"),
|
|
reportNumber: null,
|
|
invoiceNumber: null,
|
|
};
|
|
|
|
const billedPosition: BillingPosition = {
|
|
id: "u2",
|
|
assetId: "asset-2",
|
|
filename: "sport.jpg",
|
|
albumName: "Presse 2026",
|
|
purpose: "Sportbericht",
|
|
reference: null,
|
|
priceCents: 1_500,
|
|
collab: false,
|
|
status: "billed",
|
|
selectable: false,
|
|
createdAt: new Date("2026-08-06T10:00:00.000Z"),
|
|
reportNumber: 42,
|
|
invoiceNumber: "RE-2026-042",
|
|
};
|
|
|
|
const reopenedPosition: BillingPosition = {
|
|
id: "u3",
|
|
assetId: "asset-3",
|
|
filename: "redaktion.jpg",
|
|
albumName: "Presse 2026",
|
|
purpose: "Reopened",
|
|
reference: null,
|
|
priceCents: 1_500,
|
|
collab: false,
|
|
status: "reopened",
|
|
selectable: true,
|
|
createdAt: new Date("2026-08-07T10:00:00.000Z"),
|
|
reportNumber: null,
|
|
invoiceNumber: null,
|
|
};
|
|
|
|
const repeatDownload: RepeatDownloadPosition = {
|
|
id: "d1",
|
|
assetId: "asset-1",
|
|
usageId: "u1",
|
|
authorizedAt: new Date("2026-08-10T12:00:00.000Z"),
|
|
status: "completed",
|
|
repeatDownloadNote: "Zweite Nutzung",
|
|
};
|
|
|
|
const defaultProps = {
|
|
editorialId: "e1",
|
|
repeatDownloads: [] as RepeatDownloadPosition[],
|
|
year: 2026,
|
|
quarter: 3,
|
|
periodLabel: "Q3 2026",
|
|
reports: [] as FinalizedReportSummary[],
|
|
};
|
|
|
|
function getCheckbox(filename: string): HTMLInputElement {
|
|
return screen.getByRole("checkbox", {
|
|
name: `${filename} auswählen`,
|
|
}) as HTMLInputElement;
|
|
}
|
|
|
|
test("renders billable positions with individual checkboxes", () => {
|
|
render(
|
|
<BillingSelection
|
|
{...defaultProps}
|
|
positions={[openPosition, billedPosition]}
|
|
/>,
|
|
);
|
|
|
|
expect(screen.getByText("jubel.jpg")).toBeTruthy();
|
|
expect(screen.getByText("sport.jpg")).toBeTruthy();
|
|
expect(getCheckbox("jubel.jpg").checked).toBe(false);
|
|
});
|
|
|
|
test("disables the checkbox for billed positions and shows report reference", () => {
|
|
render(
|
|
<BillingSelection
|
|
{...defaultProps}
|
|
positions={[billedPosition]}
|
|
/>,
|
|
);
|
|
|
|
const checkbox = getCheckbox("sport.jpg");
|
|
expect(checkbox.disabled).toBe(true);
|
|
expect(screen.getByText(/Bericht Nr\. 42/)).toBeTruthy();
|
|
expect(screen.getByText(/RE-2026-042/)).toBeTruthy();
|
|
});
|
|
|
|
test("selects all open positions via Alle offenen im Quartal", () => {
|
|
render(
|
|
<BillingSelection
|
|
{...defaultProps}
|
|
positions={[openPosition, billedPosition, reopenedPosition]}
|
|
/>,
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: /Alle offenen im Quartal/i }));
|
|
|
|
expect(getCheckbox("jubel.jpg").checked).toBe(true);
|
|
expect(getCheckbox("redaktion.jpg").checked).toBe(true);
|
|
expect(getCheckbox("sport.jpg").checked).toBe(false);
|
|
});
|
|
|
|
test("clears the selection via Auswahl aufheben", () => {
|
|
render(
|
|
<BillingSelection
|
|
{...defaultProps}
|
|
positions={[openPosition]}
|
|
/>,
|
|
);
|
|
|
|
const checkbox = getCheckbox("jubel.jpg");
|
|
fireEvent.click(checkbox);
|
|
expect(checkbox.checked).toBe(true);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: /Auswahl aufheben/i }));
|
|
expect(checkbox.checked).toBe(false);
|
|
});
|
|
|
|
test("displays selected count and cents-derived EUR total", () => {
|
|
const { container } = render(
|
|
<BillingSelection
|
|
{...defaultProps}
|
|
positions={[openPosition, reopenedPosition]}
|
|
/>,
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: /Alle offenen im Quartal/i }));
|
|
|
|
const summary = container.querySelector(".billing-summary");
|
|
expect(summary?.textContent ?? "").toMatch(/2 Nutzungen ausgewählt/);
|
|
expect(summary?.textContent ?? "").toMatch(/75,00 EUR/);
|
|
});
|
|
|
|
test("renders repeat downloads in a separate section", () => {
|
|
render(
|
|
<BillingSelection
|
|
{...defaultProps}
|
|
positions={[openPosition]}
|
|
repeatDownloads={[repeatDownload]}
|
|
/>,
|
|
);
|
|
|
|
expect(screen.getByText(/Kostenlose Wiederabrufe/)).toBeTruthy();
|
|
expect(screen.getByText("Zweite Nutzung")).toBeTruthy();
|
|
});
|
|
|
|
test("shows empty state when no billable positions exist", () => {
|
|
render(
|
|
<BillingSelection
|
|
{...defaultProps}
|
|
positions={[]}
|
|
/>,
|
|
);
|
|
|
|
expect(screen.getByText(/Keine abrechenbaren Nutzungen/)).toBeTruthy();
|
|
});
|
|
|
|
test("offers only quarterly periods", () => {
|
|
render(<BillingSelection {...defaultProps} positions={[openPosition]} />);
|
|
|
|
expect(screen.queryByRole("link", { name: /Monatsansicht/i })).toBeNull();
|
|
expect(screen.queryByText("Monat")).toBeNull();
|
|
expect(screen.getByText("Quartal")).toBeTruthy();
|
|
expect(screen.getByText(/Zeitraum: Q3 2026/)).toBeTruthy();
|
|
});
|