From d739e311961d327bb6b541b1b2b35940e431476b Mon Sep 17 00:00:00 2001 From: Abhimanyu Saharan Date: Thu, 12 Feb 2026 19:47:47 +0000 Subject: [PATCH] test(frontend): add UserMenu RTL coverage for local-mode menu actions --- .../components/organisms/UserMenu.test.tsx | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 frontend/src/components/organisms/UserMenu.test.tsx diff --git a/frontend/src/components/organisms/UserMenu.test.tsx b/frontend/src/components/organisms/UserMenu.test.tsx new file mode 100644 index 00000000..dd4cde18 --- /dev/null +++ b/frontend/src/components/organisms/UserMenu.test.tsx @@ -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) => ( + // eslint-disable-next-line @next/next/no-img-element + {props.alt + ), +})); + +vi.mock("next/link", () => ({ + default: ({ children, href, ...rest }: any) => ( + + {children} + + ), +})); + +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(); + + 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(); + }); +});