Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/app/src/modules/layout/Header/MobileMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function MobileMenu() {
</li>
</ul>
</div>
<Navigation />
{!session?.user && <Navigation />}
Comment thread
Viczei marked this conversation as resolved.
Comment thread
Viczei marked this conversation as resolved.
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { render, screen } from "@testing-library/react";
import { usePathname } from "next/navigation";
import { beforeEach, describe, expect, it, vi } from "vitest";

const mocks = vi.hoisted(() => ({
auth: vi.fn(),
}));

vi.mock("~/server/auth", () => ({
auth: mocks.auth,
}));

import { MobileMenu } from "../MobileMenu";

beforeEach(() => {
vi.mocked(usePathname).mockReturnValue("/");
});

describe("MobileMenu", () => {
it("renders the main navigation when no user is signed in", async () => {
mocks.auth.mockResolvedValue(null);

render(await MobileMenu());

expect(
screen.getByRole("navigation", { name: "Menu principal" }),
).toBeInTheDocument();
expect(
screen.getByRole("link", { name: "Se connecter" }),
).toBeInTheDocument();
});

it("hides the main navigation when a user is signed in", async () => {
mocks.auth.mockResolvedValue({
user: {
email: "jean.dupont@example.fr",
name: "Jean Dupont",
phone: null,
},
});

render(await MobileMenu());

expect(
screen.queryByRole("navigation", { name: "Menu principal" }),
).not.toBeInTheDocument();
expect(
screen.getByRole("button", { name: "Mon espace" }),
).toBeInTheDocument();
});
});
Loading