|
| 1 | +import { render, screen } from "@testing-library/react"; |
| 2 | +import { usePathname } from "next/navigation"; |
| 3 | +import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 4 | + |
| 5 | +const mocks = vi.hoisted(() => ({ |
| 6 | + auth: vi.fn(), |
| 7 | +})); |
| 8 | + |
| 9 | +vi.mock("~/server/auth", () => ({ |
| 10 | + auth: mocks.auth, |
| 11 | +})); |
| 12 | + |
| 13 | +import { MobileMenu } from "../MobileMenu"; |
| 14 | + |
| 15 | +beforeEach(() => { |
| 16 | + vi.mocked(usePathname).mockReturnValue("/"); |
| 17 | +}); |
| 18 | + |
| 19 | +describe("MobileMenu", () => { |
| 20 | + it("renders the main navigation when no user is signed in", async () => { |
| 21 | + mocks.auth.mockResolvedValue(null); |
| 22 | + |
| 23 | + render(await MobileMenu()); |
| 24 | + |
| 25 | + expect( |
| 26 | + screen.getByRole("navigation", { name: "Menu principal" }), |
| 27 | + ).toBeInTheDocument(); |
| 28 | + expect( |
| 29 | + screen.getByRole("link", { name: "Se connecter" }), |
| 30 | + ).toBeInTheDocument(); |
| 31 | + }); |
| 32 | + |
| 33 | + it("hides the main navigation when a user is signed in", async () => { |
| 34 | + mocks.auth.mockResolvedValue({ |
| 35 | + user: { |
| 36 | + email: "jean.dupont@example.fr", |
| 37 | + name: "Jean Dupont", |
| 38 | + phone: null, |
| 39 | + }, |
| 40 | + }); |
| 41 | + |
| 42 | + render(await MobileMenu()); |
| 43 | + |
| 44 | + expect( |
| 45 | + screen.queryByRole("navigation", { name: "Menu principal" }), |
| 46 | + ).not.toBeInTheDocument(); |
| 47 | + expect( |
| 48 | + screen.getByRole("button", { name: "Mon espace" }), |
| 49 | + ).toBeInTheDocument(); |
| 50 | + }); |
| 51 | +}); |
0 commit comments