// @vitest-environment jsdom import "@testing-library/jest-dom/vitest"; import type { ComponentProps, ReactNode } from "react"; import { fireEvent, render, screen } from "@testing-library/react"; import { buildChatChannelListVM } from "@hivegrid/view-models"; import { describe, expect, it, vi } from "vitest"; import { ChatChannelListPage, type ChatChannelListActions } from "./ChatChannelListPage"; vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (key: string, values?: Record) => (values ? `${key}:${Object.values(values).join("/")}` : key), i18n: { language: "de" }, }), })); vi.mock("~/locale/format", () => ({ useLocaleFormatters: () => ({ number: (value: number) => String(value), relativeDate: (value: string) => value, }), })); vi.mock("@subframe/core", () => ({ FeatherAtSign: () => , FeatherHash: () => , FeatherLock: () => , FeatherMessageCircle: () => , FeatherMessageSquare: () => , FeatherPin: () => , FeatherUsers: () => , })); vi.mock("~/ui/components/Avatar", () => ({ Avatar: ({ children }: { children?: ReactNode }) => {children} })); vi.mock("~/ui/components/BadgeFeedback", () => ({ BadgeFeedback: ({ children }: { children?: ReactNode }) => {children} })); vi.mock("~/ui/components/Button", () => ({ Button: ({ children, loading: _loading, icon: _icon, ...props }: ComponentProps<"button"> & { loading?: boolean; icon?: ReactNode }) => ( ), })); vi.mock("~/ui/components/ButtonGroup", () => ({ ButtonGroup: ({ children }: { children?: ReactNode }) =>
{children}
})); vi.mock("~/ui/components/Card", () => ({ Card: ({ children, ...props }: ComponentProps<"div">) =>
{children}
})); vi.mock("~/ui/components/EmptyState", () => ({ EmptyState: ({ title, body, action }: { title?: ReactNode; body?: ReactNode; action?: ReactNode }) => (
{title} {body} {action}
), })); vi.mock("~/ui/components/LoadingIndicatorSkeleton", () => ({ LoadingIndicatorSkeleton: (props: ComponentProps<"div">) =>
})); vi.mock("~/ui/components/SearchInput", () => ({ SearchInput: ({ fillContainer: _fill, hideShortcut: _shortcut, ...props }: ComponentProps<"input"> & { fillContainer?: boolean; hideShortcut?: boolean }) => ( ), })); vi.mock("~/ui/components/Select", () => ({ Select: Object.assign( ({ children }: { children?: ReactNode }) =>
{children}
, { Item: ({ children }: { children?: ReactNode }) => {children} } ), })); vi.mock("~/ui/components/Switch", () => ({ Switch: (props: ComponentProps<"input">) => })); vi.mock("../shared/PageShell", () => ({ PAGE_HEADER_ICON_CLASS: "", PageShell: ({ children }: { children?: ReactNode }) =>
{children}
, PageHeader: ({ title, actions }: { title?: ReactNode; actions?: ReactNode }) => (
{title} {actions}
), PageBody: ({ children }: { children?: ReactNode }) =>
{children}
, })); const actions = (onJoinChannel: ChatChannelListActions["onJoinChannel"]): ChatChannelListActions => ({ onOpenChannel: vi.fn(), onQueryChange: vi.fn(), onViewChange: vi.fn(), onShowArchivedChange: vi.fn(), onRetry: vi.fn(), onJoinChannel, }); const vm = buildChatChannelListVM({ rows: [], discoverRows: [ { id: "chat_public", title: "Montage Nord", description: "Offener Austausch", avatar: { imageUrl: null, fallbackLabel: "MN" }, memberCount: 7, isJoined: false, canJoin: true, joinHref: "/demo/chat", detailHref: null, }, ], filter: { query: "", view: "all", showArchived: false }, permissions: { canWrite: true, canCreateGroup: false, canCreateDm: false, canDiscover: true, canViewMentions: false, canSearch: true, canViewArchived: false, canAdmin: false, }, hrefs: { newChannel: "/demo/chat/new?kind=group", newDm: "/demo/chat/new?kind=dm", search: "/demo/chat/search", mentions: "/demo/chat/mentions", archived: "/demo/chat?archived=true", }, totals: { unread: 0, mentions: 0 }, }); describe("public channel discovery interim UI", () => { it("shows public groups as join-only rows and delegates the join intent", () => { const onJoinChannel = vi.fn(); const { rerender } = render(); expect(screen.getByText("chat.channelList.discover.headline")).toBeInTheDocument(); expect(screen.getByText("Offener Austausch")).toBeInTheDocument(); expect(screen.getByText("chat.channelList.discover.memberCount:7")).toBeInTheDocument(); expect(screen.queryByRole("link", { name: /Montage Nord/ })).not.toBeInTheDocument(); const joinButton = screen.getByRole("button", { name: "chat.channelList.discover.joinAria:Montage Nord" }); fireEvent.click(joinButton); expect(onJoinChannel).toHaveBeenCalledWith("chat_public", "/demo/chat"); rerender(); expect(screen.getByRole("button", { name: "chat.channelList.discover.joinAria:Montage Nord" })).toBeDisabled(); }); });