62 lines
2.0 KiB
TypeScript
62 lines
2.0 KiB
TypeScript
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import { buildChatChannelListVM } from "@hivegrid/view-models";
|
|
|
|
import { ChatChannelListPage } from "./ChatChannelListPage";
|
|
|
|
vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
|
|
vi.mock("~/locale/format", () => ({
|
|
useLocaleFormatters: () => ({ date: (value: string) => value, number: (value: number) => String(value) }),
|
|
}));
|
|
|
|
describe("chat message discovery reachability", () => {
|
|
it("opens cross-channel search and mentions from the member chat index", () => {
|
|
const openSearch = vi.fn();
|
|
const openMentions = vi.fn();
|
|
const vm = buildChatChannelListVM({
|
|
rows: [],
|
|
discoverRows: [],
|
|
filter: { query: "", view: "all", showArchived: false },
|
|
permissions: {
|
|
canWrite: true,
|
|
canCreateGroup: false,
|
|
canCreateDm: false,
|
|
canDiscover: true,
|
|
canViewMentions: true,
|
|
canSearch: true,
|
|
canViewArchived: true,
|
|
canAdmin: false,
|
|
},
|
|
hrefs: {
|
|
newChannel: "/demo/chat/new",
|
|
newDm: "/demo/chat/new?mode=dm",
|
|
search: "/demo/chat/search",
|
|
mentions: "/demo/chat/mentions",
|
|
archived: "/demo/chat/archived",
|
|
},
|
|
totals: { unread: 0, mentions: 0 },
|
|
});
|
|
|
|
render(
|
|
<ChatChannelListPage
|
|
vm={vm}
|
|
actions={{
|
|
onOpenChannel: vi.fn(),
|
|
onQueryChange: vi.fn(),
|
|
onViewChange: vi.fn(),
|
|
onShowArchivedChange: vi.fn(),
|
|
onRetry: vi.fn(),
|
|
onOpenMessageSearch: openSearch,
|
|
onOpenMentions: openMentions,
|
|
}}
|
|
/>
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "chat.messageDiscovery.actions.search" }));
|
|
fireEvent.click(screen.getByRole("button", { name: "chat.messageDiscovery.actions.mentions" }));
|
|
expect(openSearch).toHaveBeenCalledWith("/demo/chat/search");
|
|
expect(openMentions).toHaveBeenCalledWith("/demo/chat/mentions");
|
|
});
|
|
});
|