test(frontend): add UserMenu RTL coverage for local-mode menu actions

This commit is contained in:
Abhimanyu Saharan
2026-02-12 19:47:47 +00:00
committed by Abhimanyu Saharan
parent 8981202f8f
commit d739e31196

View File

@@ -0,0 +1,50 @@
import { describe, expect, it, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { UserMenu } from "./UserMenu";
const useUserMock = vi.hoisted(() => vi.fn());
const clearLocalAuthTokenMock = vi.hoisted(() => vi.fn());
const isLocalAuthModeMock = vi.hoisted(() => vi.fn());
vi.mock("next/image", () => ({
default: (props: React.ImgHTMLAttributes<HTMLImageElement>) => (
// eslint-disable-next-line @next/next/no-img-element
<img {...props} alt={props.alt ?? ""} />
),
}));
vi.mock("next/link", () => ({
default: ({ children, href, ...rest }: any) => (
<a href={typeof href === "string" ? href : "#"} {...rest}>
{children}
</a>
),
}));
vi.mock("@/auth/clerk", () => ({
useUser: useUserMock,
SignOutButton: ({ children }: { children: React.ReactNode }) => children,
}));
vi.mock("@/auth/localAuth", () => ({
clearLocalAuthToken: clearLocalAuthTokenMock,
isLocalAuthMode: isLocalAuthModeMock,
}));
describe("UserMenu", () => {
it("renders and opens local-mode menu actions", async () => {
const user = userEvent.setup();
useUserMock.mockReturnValue({ user: null });
isLocalAuthModeMock.mockReturnValue(true);
render(<UserMenu />);
await user.click(screen.getByRole("button", { name: /open user menu/i }));
expect(screen.getByRole("link", { name: /open boards/i })).toBeInTheDocument();
expect(screen.getByRole("link", { name: /create board/i })).toBeInTheDocument();
expect(screen.getByRole("button", { name: /sign out/i })).toBeInTheDocument();
});
});