96 lines
3.7 KiB
TypeScript
96 lines
3.7 KiB
TypeScript
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
vi.mock("react-i18next", () => ({
|
|
useTranslation: () => ({
|
|
t: (key: string, values?: Record<string, unknown>) => (values ? `${key}:${JSON.stringify(values)}` : key),
|
|
}),
|
|
}));
|
|
vi.mock("~/locale/format", () => ({ useLocaleFormatters: () => ({ date: (value: string) => value }) }));
|
|
|
|
import { buildChatAuditOverviewVM } from "@hivegrid/view-models";
|
|
|
|
import { ChatAuditOverviewPage } from "./ChatAuditOverviewPage";
|
|
|
|
describe("AK-P15b chat audit interim UI", () => {
|
|
it("keeps the audit list locked until a non-empty justification is submitted", () => {
|
|
const onStartSession = vi.fn();
|
|
render(
|
|
<ChatAuditOverviewPage
|
|
vm={buildChatAuditOverviewVM({ session: null, channels: [] })}
|
|
actions={{ onStartSession, onEndSession: vi.fn(), onOpenChannel: vi.fn(), onArchiveChannel: vi.fn() }}
|
|
/>
|
|
);
|
|
|
|
const button = screen.getByRole("button", { name: "chat.audit.session.start" });
|
|
expect((button as HTMLButtonElement).disabled).toBe(true);
|
|
fireEvent.change(screen.getByRole("textbox", { name: "chat.audit.reason.label" }), { target: { value: "Kundenreklamation prüfen" } });
|
|
expect((button as HTMLButtonElement).disabled).toBe(false);
|
|
fireEvent.click(button);
|
|
expect(onStartSession).toHaveBeenCalledWith("Kundenreklamation prüfen");
|
|
});
|
|
|
|
it("only exposes read-only open actions during an active session", () => {
|
|
const onOpenChannel = vi.fn();
|
|
render(
|
|
<ChatAuditOverviewPage
|
|
vm={buildChatAuditOverviewVM({
|
|
session: { id: "session-1", reason: "Supportfall", expiresAtIso: "2026-07-16T10:15:00.000Z" },
|
|
channels: [
|
|
{
|
|
id: "dm-1",
|
|
kind: "dm",
|
|
title: "Anna · Ben",
|
|
description: null,
|
|
participantLabels: ["Anna", "Ben"],
|
|
memberCount: 2,
|
|
isPrivate: true,
|
|
archivedAtIso: null,
|
|
lastMessageAtIso: null,
|
|
detailHref: "/demo/settings/chat/audit/dm-1",
|
|
},
|
|
],
|
|
canAdminister: false,
|
|
})}
|
|
actions={{ onStartSession: vi.fn(), onEndSession: vi.fn(), onOpenChannel, onArchiveChannel: vi.fn() }}
|
|
/>
|
|
);
|
|
|
|
expect(screen.getByText("chat.audit.readOnly.title")).toBeTruthy();
|
|
expect(screen.queryByText(/send|delete|edit/iu)).toBeNull();
|
|
fireEvent.click(screen.getByRole("button", { name: /chat.audit.openChannelLabel/u }));
|
|
expect(onOpenChannel).toHaveBeenCalledWith("/demo/settings/chat/audit/dm-1");
|
|
});
|
|
|
|
it("confirms an audited cleanup archive only for chat administrators", () => {
|
|
const onArchiveChannel = vi.fn();
|
|
render(
|
|
<ChatAuditOverviewPage
|
|
vm={buildChatAuditOverviewVM({
|
|
session: { id: "session-1", reason: "Supportfall", expiresAtIso: "2026-07-16T10:15:00.000Z" },
|
|
canAdminister: true,
|
|
channels: [
|
|
{
|
|
id: "group-1",
|
|
kind: "group",
|
|
title: "Bauleitung",
|
|
description: null,
|
|
participantLabels: [],
|
|
memberCount: 2,
|
|
isPrivate: true,
|
|
archivedAtIso: null,
|
|
lastMessageAtIso: null,
|
|
detailHref: "/demo/settings/chat/audit/group-1",
|
|
},
|
|
],
|
|
})}
|
|
actions={{ onStartSession: vi.fn(), onEndSession: vi.fn(), onOpenChannel: vi.fn(), onArchiveChannel }}
|
|
/>
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: /chat.audit.actions.archiveLabel/u }));
|
|
fireEvent.click(screen.getByRole("button", { name: "shared.confirm" }));
|
|
expect(onArchiveChannel).toHaveBeenCalledWith("group-1");
|
|
});
|
|
});
|