Secure Sakani portal and show full album titles
This commit is contained in:
1 parent
c40ccf77cf
commit
69264ce165
49 files changed
+1362
-601
No files matched your search
@@ -0,0 +1,55 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { afterEach, expect, test, vi } from "vitest";
|
||||
|
||||
import { DownloadLightboxForm } from "./DownloadLightboxForm";
|
||||
|
||||
vi.mock("next/navigation", () => ({ useRouter: () => ({ refresh: vi.fn() }) }));
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
test("confirms new and previous uses separately and preserves the keys after a failed request", async () => {
|
||||
const fetch = vi.fn().mockRejectedValue(new Error("connection lost"));
|
||||
vi.stubGlobal("fetch", fetch);
|
||||
render(<DownloadLightboxForm
|
||||
photos={[
|
||||
{ assetId: "first", albumId: "allowed", filename: "first.jpg" },
|
||||
{ assetId: "second", albumId: "allowed", filename: "second.jpg" },
|
||||
]}
|
||||
options={{
|
||||
priceCents: 1500,
|
||||
priorUsagesByAsset: {
|
||||
second: [{ id: "prior", purpose: "Früherer Artikel", createdAt: "2026-11-01T12:00:00Z" }],
|
||||
},
|
||||
}}
|
||||
/>);
|
||||
fireEvent.click(screen.getByRole("button", { name: "ZIP-Download vorbereiten" }));
|
||||
expect((screen.getByRole("button", { name: "ZIP herunterladen" }) as HTMLButtonElement).disabled).toBe(true);
|
||||
|
||||
fireEvent.change(screen.getByRole("combobox", { name: "first.jpg" }), { target: { value: "new" } });
|
||||
fireEvent.change(screen.getByRole("combobox", { name: "second.jpg" }), { target: { value: "prior" } });
|
||||
const submit = screen.getByRole<HTMLButtonElement>("button", { name: "Nutzungen bestätigen und laden" });
|
||||
expect(submit.disabled).toBe(true);
|
||||
fireEvent.change(screen.getByLabelText("Gemeinsamer Zweck für neue Nutzungen"), {
|
||||
target: { value: "Neuer Artikel" },
|
||||
});
|
||||
expect(screen.getByRole("status").textContent).toMatch(/1 neue Nutzung.*15,00/);
|
||||
fireEvent.click(submit);
|
||||
await waitFor(() => expect(submit.disabled).toBe(false));
|
||||
fireEvent.click(submit);
|
||||
await waitFor(() => expect(submit.disabled).toBe(false));
|
||||
|
||||
const payload = JSON.parse(fetch.mock.calls[0][1].body);
|
||||
expect(payload).toEqual({
|
||||
maxPriceCents: 1500,
|
||||
items: [
|
||||
{ assetId: "first", albumId: "allowed", purpose: "Neuer Artikel", idempotencyKey: expect.any(String) },
|
||||
{ assetId: "second", usageId: "prior", idempotencyKey: expect.any(String) },
|
||||
],
|
||||
});
|
||||
expect(JSON.parse(fetch.mock.calls[1][1].body)).toEqual(payload);
|
||||
});
|
||||
Reference in new issue
Block a user