186 lines
6.3 KiB
TypeScript
186 lines
6.3 KiB
TypeScript
// @vitest-environment jsdom
|
|
import "@testing-library/jest-dom/vitest";
|
|
import { fireEvent, render, screen, within } from "@testing-library/react";
|
|
import { MemoryRouter } from "react-router";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { buildChatPinnedMessagesVM, buildChatThreadVM } from "@hivegrid/view-models";
|
|
|
|
import { ChatPinnedMessagesPage } from "./ChatPinnedMessagesPage";
|
|
import { ChatThreadPage } from "./ChatThreadPage";
|
|
|
|
vi.mock("react-i18next", () => ({
|
|
useTranslation: () => ({
|
|
t: (key: string, values?: Record<string, unknown>) => (values ? `${key}:${Object.values(values).join("/")}` : key),
|
|
}),
|
|
}));
|
|
vi.mock("~/locale/format", () => ({
|
|
useLocaleFormatters: () => ({ date: (value: string) => `date:${value}`, number: (value: number) => String(value) }),
|
|
}));
|
|
|
|
const message = {
|
|
id: "message_1",
|
|
authorLabel: "Mara Klein",
|
|
authorAvatarUrl: null,
|
|
bodyMarkdown: "Bitte **prüfen**",
|
|
createdAtIso: "2026-07-16T08:00:00.000Z",
|
|
deleted: false,
|
|
mentions: [],
|
|
attachments: [
|
|
{
|
|
id: "message_1:file_1",
|
|
fileId: "file_1",
|
|
kind: "file",
|
|
fileName: "montageplan.pdf",
|
|
mimeType: "application/pdf",
|
|
sizeBytes: 1024,
|
|
downloadHref: "/demo/files/file_1/content/original",
|
|
previewHref: null,
|
|
altText: null,
|
|
durationSeconds: null,
|
|
scanStatus: "clean",
|
|
},
|
|
],
|
|
reactions: [{ emoji: "👍", count: 2, reactedByViewer: true }],
|
|
pinned: true,
|
|
canReact: true,
|
|
canPin: true,
|
|
canEdit: true,
|
|
canDelete: true,
|
|
} as const;
|
|
|
|
describe("AK-P15b thread and pinned interim screens", () => {
|
|
it("sends a reply and delegates reaction and pin actions", () => {
|
|
const onDraftChange = vi.fn();
|
|
const onSendReply = vi.fn();
|
|
const onToggleReaction = vi.fn();
|
|
const onTogglePin = vi.fn();
|
|
const onRetryFeature = vi.fn();
|
|
const onEditMessage = vi.fn();
|
|
const onDeleteMessage = vi.fn();
|
|
const vm = buildChatThreadVM({
|
|
chatId: "chat_1",
|
|
threadId: "message_1",
|
|
channelTitle: "Montage Nord",
|
|
backHref: "/demo/chat/chat_1",
|
|
parent: message,
|
|
replies: [],
|
|
replyCount: 0,
|
|
canReply: true,
|
|
});
|
|
|
|
render(
|
|
<MemoryRouter>
|
|
<ChatThreadPage
|
|
vm={vm}
|
|
draft="Antwort"
|
|
busy={false}
|
|
errorKey={null}
|
|
featureErrorKeys={{ message_1: "chat.errors.invalidInput" }}
|
|
actions={{
|
|
onBack: vi.fn(),
|
|
onDraftChange,
|
|
onSendReply,
|
|
onToggleReaction,
|
|
onTogglePin,
|
|
onEditMessage,
|
|
onDeleteMessage,
|
|
onRetryFeature,
|
|
onRetry: vi.fn(),
|
|
}}
|
|
/>
|
|
</MemoryRouter>
|
|
);
|
|
|
|
fireEvent.change(screen.getByRole("combobox", { name: "chat.thread.replyLabel" }), { target: { value: "Neu" } });
|
|
expect(onDraftChange).toHaveBeenCalledWith("Neu", 3);
|
|
fireEvent.click(screen.getByRole("button", { name: "chat.thread.sendReply" }));
|
|
expect(onSendReply).toHaveBeenCalledWith("Antwort");
|
|
fireEvent.click(screen.getByRole("button", { name: "chat.reaction.remove:👍" }));
|
|
expect(onToggleReaction).toHaveBeenCalledWith("message_1", "👍", false);
|
|
fireEvent.click(screen.getByRole("button", { name: "chat.pinned.unpin" }));
|
|
expect(onTogglePin).toHaveBeenCalledWith("message_1", false);
|
|
expect(screen.getByText("chat.errors.invalidInput")).toBeInTheDocument();
|
|
expect(screen.getByText("montageplan.pdf")).toBeInTheDocument();
|
|
fireEvent.click(screen.getByRole("button", { name: "shared.retry" }));
|
|
expect(onRetryFeature).toHaveBeenCalledWith("message_1");
|
|
});
|
|
|
|
it("shows pinned rows and unpins only after an explicit action", () => {
|
|
const onUnpin = vi.fn();
|
|
const vm = buildChatPinnedMessagesVM({
|
|
chatId: "chat_1",
|
|
channelTitle: "Montage Nord",
|
|
backHref: "/demo/chat/chat_1",
|
|
rows: [
|
|
{
|
|
message,
|
|
pinnedAtIso: "2026-07-16T09:00:00.000Z",
|
|
pinnedByLabel: "Raffael Sheikh",
|
|
note: null,
|
|
messageHref: "/demo/chat/chat_1?message=message_1#message-message_1",
|
|
canUnpin: true,
|
|
},
|
|
],
|
|
});
|
|
|
|
render(
|
|
<MemoryRouter>
|
|
<ChatPinnedMessagesPage vm={vm} busyMessageId={null} errorKey={null} actions={{ onBack: vi.fn(), onUnpin, onRetry: vi.fn() }} />
|
|
</MemoryRouter>
|
|
);
|
|
|
|
expect(screen.getByText("chat.pinned.by:Raffael Sheikh")).toBeInTheDocument();
|
|
fireEvent.click(screen.getAllByRole("button", { name: "chat.pinned.unpin" }).at(-1)!);
|
|
expect(onUnpin).toHaveBeenCalledWith("message_1");
|
|
});
|
|
|
|
it("confirms thread-message edits and deletes before delegating them", () => {
|
|
const onEditMessage = vi.fn();
|
|
const onDeleteMessage = vi.fn();
|
|
const vm = buildChatThreadVM({
|
|
chatId: "chat_1",
|
|
threadId: "message_1",
|
|
channelTitle: "Montage Nord",
|
|
backHref: "/demo/chat/chat_1",
|
|
parent: message,
|
|
replies: [],
|
|
replyCount: 0,
|
|
canReply: true,
|
|
});
|
|
|
|
render(
|
|
<MemoryRouter>
|
|
<ChatThreadPage
|
|
vm={vm}
|
|
draft=""
|
|
busy={false}
|
|
errorKey={null}
|
|
actions={{
|
|
onBack: vi.fn(),
|
|
onDraftChange: vi.fn(),
|
|
onSendReply: vi.fn(),
|
|
onToggleReaction: vi.fn(),
|
|
onTogglePin: vi.fn(),
|
|
onEditMessage,
|
|
onDeleteMessage,
|
|
onRetry: vi.fn(),
|
|
}}
|
|
/>
|
|
</MemoryRouter>
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "chat.message.edit" }));
|
|
const editDialog = screen.getByRole("dialog");
|
|
expect(within(editDialog).getByRole("heading", { name: "chat.message.editTitle" })).toBeInTheDocument();
|
|
fireEvent.change(within(editDialog).getByRole("textbox"), { target: { value: "Aktualisiert" } });
|
|
fireEvent.click(within(editDialog).getByRole("button", { name: "chat.message.save" }));
|
|
expect(onEditMessage).toHaveBeenCalledWith("message_1", "Aktualisiert");
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "chat.message.delete" }));
|
|
const deleteDialog = screen.getByRole("dialog");
|
|
expect(within(deleteDialog).getByRole("heading", { name: "chat.message.deleteConfirmTitle" })).toBeInTheDocument();
|
|
fireEvent.click(within(deleteDialog).getByRole("button", { name: "chat.message.delete" }));
|
|
expect(onDeleteMessage).toHaveBeenCalledWith("message_1");
|
|
});
|
|
});
|