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) => (values ? `${key}:${JSON.stringify(values)}` : key), }), })); import { buildChatAuditAdministrationVM } from "@hivegrid/view-models"; import { ChatAuditAdministrationPanel } from "./ChatAuditAdministrationPanel"; describe("AK-P15b chat audit administration panel", () => { it("shows no mutation controls to a read-all auditor without chat admin", () => { render( ); expect(screen.getByText("chat.audit.administration.readOnlyTitle")).toBeTruthy(); expect(screen.queryByRole("button", { name: "chat.audit.actions.promote" })).toBeNull(); }); it("supports force-role, force-remove, and archive actions with confirmation", () => { const onArchive = vi.fn(); const onChangeMemberRole = vi.fn(); const onRemoveMember = vi.fn(); render( ); fireEvent.click(screen.getByRole("button", { name: "chat.audit.actions.promote" })); expect(onChangeMemberRole).toHaveBeenCalledWith("member-a", "admin"); fireEvent.click(screen.getByRole("button", { name: /chat.audit.actions.removeMemberLabel/u })); fireEvent.click(screen.getByRole("button", { name: "shared.confirm" })); expect(onRemoveMember).toHaveBeenCalledWith("member-a"); fireEvent.click(screen.getByRole("button", { name: "chat.audit.actions.archive" })); fireEvent.click(screen.getByRole("button", { name: "shared.confirm" })); expect(onArchive).toHaveBeenCalledOnce(); }); }); function vm(canAdminister: boolean) { return buildChatAuditAdministrationVM({ channel: { id: "chat-a", kind: "group", title: "Bauleitung", archivedAtIso: null }, canAdminister, members: [{ userId: "member-a", displayName: "Anna Adler", avatarUrl: null, roleInChat: "member" }], }); }