79 lines
2.5 KiB
TypeScript
79 lines
2.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { buildChatPinnedMessagesVM, buildChatThreadVM, chatFeatureMessageVMSchema } from "./message-features.vm.js";
|
|
|
|
const message = {
|
|
id: "message_parent",
|
|
authorLabel: "Raffael Sheikh",
|
|
authorAvatarUrl: null,
|
|
bodyMarkdown: "Status **fertig**",
|
|
createdAtIso: "2026-07-16T08:00:00.000Z",
|
|
deleted: false,
|
|
mentions: [],
|
|
attachments: [],
|
|
reactions: [{ emoji: "👍", count: 2, reactedByViewer: true }],
|
|
pinned: true,
|
|
canReact: true,
|
|
canPin: true,
|
|
canEdit: true,
|
|
canDelete: true,
|
|
} as const;
|
|
|
|
const attachment = {
|
|
id: "message_parent:file_1",
|
|
fileId: "file_1",
|
|
kind: "file",
|
|
fileName: "montageplan.pdf",
|
|
mimeType: "application/pdf",
|
|
sizeBytes: 1_024,
|
|
downloadHref: "/demo/files/file_1/content/original",
|
|
previewHref: null,
|
|
altText: null,
|
|
durationSeconds: null,
|
|
scanStatus: "clean",
|
|
} as const;
|
|
|
|
describe("chat message feature view-models", () => {
|
|
it("builds a one-level thread with deterministic labels", () => {
|
|
const vm = buildChatThreadVM({
|
|
chatId: "chat_1",
|
|
threadId: "message_parent",
|
|
channelTitle: "Montage Nord",
|
|
backHref: "/demo/chat/chat_1",
|
|
parent: { ...message, attachments: [attachment] },
|
|
replies: [],
|
|
replyCount: 0,
|
|
canReply: true,
|
|
});
|
|
|
|
expect(vm).toMatchObject({
|
|
status: "ready",
|
|
data: {
|
|
composerPlaceholderKey: "chat.thread.composerPlaceholder",
|
|
emptyRepliesHeadlineKey: "chat.thread.empty.headline",
|
|
},
|
|
});
|
|
expect(vm.status === "ready" ? vm.data.parent.attachments : []).toEqual([attachment]);
|
|
});
|
|
|
|
it("sorts pinned messages newest first", () => {
|
|
const vm = buildChatPinnedMessagesVM({
|
|
chatId: "chat_1",
|
|
channelTitle: "Montage Nord",
|
|
backHref: "/demo/chat/chat_1",
|
|
rows: [
|
|
{ message, pinnedAtIso: "2026-07-15T08:00:00.000Z", pinnedByLabel: "A", note: null, messageHref: "#old", canUnpin: true },
|
|
{ message: { ...message, id: "message_new" }, pinnedAtIso: "2026-07-16T08:00:00.000Z", pinnedByLabel: "B", note: null, messageHref: "#new", canUnpin: true },
|
|
],
|
|
});
|
|
|
|
expect(vm.status === "ready" ? vm.data.rows.map((row) => row.message.id) : []).toEqual(["message_new", "message_parent"]);
|
|
});
|
|
|
|
it("rejects actions on deleted messages", () => {
|
|
expect(() =>
|
|
chatFeatureMessageVMSchema.parse({ ...message, deleted: true, bodyMarkdown: null, canReact: true, canPin: false })
|
|
).toThrow("chat.errors.integrityFailure");
|
|
});
|
|
});
|