47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { buildChatMessageDiscoveryVM } from "@hivegrid/view-models";
|
|
|
|
import { mergeChatMessageDiscoveryPages } from "./ChatMessageDiscoveryRouteView";
|
|
|
|
const hrefs = { chat: "/demo/chat", search: "/demo/chat/search", mentions: "/demo/chat/mentions" } as const;
|
|
|
|
function row(id: string) {
|
|
return {
|
|
id,
|
|
chatId: "chat_1",
|
|
channelKind: "group" as const,
|
|
channelTitle: "Montage",
|
|
authorLabel: "Ada Lovelace",
|
|
authorAvatar: { imageUrl: null, fallbackLabel: "AL" },
|
|
body: `Message ${id}`,
|
|
createdAtIso: "2026-07-16T11:00:00.000Z",
|
|
detailHref: `/demo/chat/chat_1?message=${id}`,
|
|
isThreadReply: false,
|
|
};
|
|
}
|
|
|
|
describe("chat message discovery pagination", () => {
|
|
it("appends cursor pages once and keeps the incoming next cursor", () => {
|
|
const first = buildChatMessageDiscoveryVM({ mode: "search", query: "heat", rows: [row("m2")], nextCursor: "cursor_2", hrefs });
|
|
const second = buildChatMessageDiscoveryVM({
|
|
mode: "search",
|
|
query: "heat",
|
|
rows: [row("m2"), row("m1")],
|
|
nextCursor: null,
|
|
hrefs,
|
|
});
|
|
|
|
const merged = mergeChatMessageDiscoveryPages(first, second);
|
|
expect(merged.status === "ready" && merged.data.rows.map(({ id }) => id)).toEqual(["m2", "m1"]);
|
|
expect(merged.status === "ready" && merged.data.nextCursor).toBeNull();
|
|
});
|
|
|
|
it("does not mix pages from different queries", () => {
|
|
const first = buildChatMessageDiscoveryVM({ mode: "search", query: "heat", rows: [row("m2")], hrefs });
|
|
const other = buildChatMessageDiscoveryVM({ mode: "search", query: "solar", rows: [row("m1")], hrefs });
|
|
|
|
expect(mergeChatMessageDiscoveryPages(first, other)).toEqual(other);
|
|
});
|
|
});
|