25 lines
968 B
TypeScript
25 lines
968 B
TypeScript
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(
|
|
<ChatContext.Provider
|
|
value={{ isChatOpen: false, openChat, closeChat: () => {} }}
|
|
>
|
|
<ChatButton />
|
|
</ChatContext.Provider>,
|
|
{ ws: { unreadChatCount: 4 } },
|
|
);
|
|
await user.click(screen.getByRole("button", { name: "Chat (4 unread)" }));
|
|
expect(openChat).toHaveBeenCalled();
|
|
await waitFor(() => expect(screen.getByText("4")).toBeInTheDocument());
|
|
});
|
|
});
|