- packages/metadata: {variable} templates, Photo Mechanic code replacement, IPTC fields of the current pad (title = persons shown), IIM/XMP mapping, delivery folder and file-name templates (FPA, Liga)
- API: events with agenda and IPTC template, FTP logins, ingest worker (hash, dedupe, EXIF in Lisbon time, routing by agenda + capture time, previews), library culling, IPTC preview, code list, signed file URLs
- Realtime: Socket.io with Postgres LISTEN/NOTIFY fan-out
- Delivery: queue with fixed sequence numbers, 4000 px JPEG 100 with IPTC via ExifTool, WebDAV upload with retries, OCS share links, encrypted app passwords
- Web app: approved type and Lightroom-style workspace, grid/loupe with keyboard culling, players, IPTC panel, delivery queue, code list editor
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HT6iXLYUUp9pJz5Kza9xCW
66 lines
3.2 KiB
TypeScript
66 lines
3.2 KiB
TypeScript
import type { ApiClient, Me } from "@photoreport/sdk";
|
|
import { ApiError } from "@photoreport/sdk";
|
|
import { render, screen, waitFor } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { App } from "./App.js";
|
|
|
|
vi.mock("./library/realtime.js", () => ({ useLibraryLive: () => "live" }));
|
|
|
|
const ME: Me = {
|
|
user: { id: "u1", email: "[email protected]", name: "Ana", locale: "pt-PT" },
|
|
memberships: [{ role: "ADMIN", organization: { id: "o1", slug: "fpa", name: "FPA", mode: "AGENCY" } }],
|
|
preferences: { editorModules: ["crop", "basic"] },
|
|
};
|
|
|
|
function fakeApi(overrides: Partial<Record<keyof ApiClient, unknown>> = {}): ApiClient {
|
|
return {
|
|
client: "web",
|
|
resume: vi.fn().mockResolvedValue(false),
|
|
login: vi.fn().mockResolvedValue(undefined),
|
|
me: vi.fn().mockResolvedValue(ME),
|
|
logout: vi.fn().mockResolvedValue(undefined),
|
|
updateEditorModules: vi.fn().mockResolvedValue({ editorModules: ["crop", "basic", "toneCurve"] }),
|
|
listMembers: vi.fn().mockResolvedValue([]),
|
|
listEvents: vi.fn().mockResolvedValue({ events: [], inboxCount: 0 }),
|
|
listDeliveryTargets: vi.fn().mockResolvedValue({ targets: [] }),
|
|
absolute: (p: string) => p,
|
|
...overrides,
|
|
} as unknown as ApiClient;
|
|
}
|
|
|
|
describe("App", () => {
|
|
it("signs in with email and password and shows the library", async () => {
|
|
const api = fakeApi();
|
|
render(<App api={api} />);
|
|
await userEvent.type(await screen.findByLabelText("Email"), "[email protected]");
|
|
await userEvent.type(screen.getByLabelText("Palavra-passe"), "secret-password");
|
|
await userEvent.click(screen.getByRole("button", { name: "Entrar" }));
|
|
expect(api.login).toHaveBeenCalledWith("[email protected]", "secret-password");
|
|
expect(await screen.findByText(/Ainda não chegaram fotografias/)).toBeTruthy();
|
|
expect(screen.getByRole("link", { name: "Membros" })).toBeTruthy(); // admin sees member management
|
|
});
|
|
|
|
it("explains wrong credentials", async () => {
|
|
const api = fakeApi({ login: vi.fn().mockRejectedValue(new ApiError(401, "invalid_credentials", null)) });
|
|
render(<App api={api} />);
|
|
await userEvent.type(await screen.findByLabelText("Email"), "[email protected]");
|
|
await userEvent.type(screen.getByLabelText("Palavra-passe"), "wrong-password");
|
|
await userEvent.click(screen.getByRole("button", { name: "Entrar" }));
|
|
expect((await screen.findByRole("alert")).textContent).toBe("Email ou palavra-passe incorretos.");
|
|
});
|
|
|
|
it("starts with Crop and Basic and saves extra editor panels", async () => {
|
|
window.history.pushState({}, "", "/preferences");
|
|
const api = fakeApi({ resume: vi.fn().mockResolvedValue(true) });
|
|
render(<App api={api} />);
|
|
const crop = (await screen.findByLabelText("Recorte")) as HTMLInputElement;
|
|
expect(crop.checked).toBe(true);
|
|
expect((screen.getByLabelText("Básico") as HTMLInputElement).checked).toBe(true);
|
|
expect((screen.getByLabelText("Curva de tons") as HTMLInputElement).checked).toBe(false);
|
|
await userEvent.click(screen.getByLabelText("Curva de tons"));
|
|
await waitFor(() => expect(api.updateEditorModules).toHaveBeenCalledWith(["crop", "basic", "toneCurve"]));
|
|
window.history.pushState({}, "", "/");
|
|
});
|
|
});
|