Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/components/screens/chat/ChatAuditAdministrationPanel.test.tsx
T

58 lines
2.2 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),
}),
}));
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(
<ChatAuditAdministrationPanel
vm={vm(false)}
actions={{ onArchive: vi.fn(), onChangeMemberRole: vi.fn(), onRemoveMember: vi.fn() }}
/>
);
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(
<ChatAuditAdministrationPanel
vm={vm(true)}
actions={{ onArchive, onChangeMemberRole, onRemoveMember }}
/>
);
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" }],
});
}