import { describe, expect, test, vi } from "vitest"; import { screen, waitFor } from "@testing-library/react"; import { userEvent } from "@testing-library/user-event"; import { ChatButton } from "../../../components/layout/ChatButton.tsx"; import { ChatContext } from "../../../contexts/chat/ChatContext.ts"; import { renderWithContexts } from "../../render.tsx"; describe("ChatButton", () => { test("the chat button opens the chat and shows unread", async () => { const openChat = vi.fn(); const user = userEvent.setup(); renderWithContexts( {} }} > , { ws: { unreadChatCount: 4 } }, ); await user.click(screen.getByRole("button", { name: "Chat (4 unread)" })); expect(openChat).toHaveBeenCalled(); await waitFor(() => expect(screen.getByText("4")).toBeInTheDocument()); }); });