/** * Tests for the MainLayout component. * * Covers: * - BanGUI application version displayed in the footer when the sidebar is expanded. * - Version text hidden when the sidebar is collapsed. * - Navigation items rendered correctly. */ import { describe, it, expect, vi, beforeEach } from "vitest"; import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { MemoryRouter } from "react-router-dom"; import { FluentProvider, webLightTheme } from "@fluentui/react-components"; import { MainLayout } from "../../layouts/MainLayout"; // --------------------------------------------------------------------------- // Mocks // --------------------------------------------------------------------------- vi.mock("../../providers/AuthProvider", () => ({ useAuth: () => ({ logout: vi.fn() }), })); vi.mock("../../hooks/useServerStatus", () => ({ useServerStatus: () => ({ status: { online: true, version: "1.0.0", active_jails: 1, total_bans: 0, total_failures: 0 }, loading: false, error: null, refresh: vi.fn(), }), })); vi.mock("../../hooks/useBlocklist", () => ({ useBlocklistStatus: () => ({ hasErrors: false }), })); // --------------------------------------------------------------------------- // Helpers // --------------------------------------------------------------------------- function renderLayout(): void { render( , ); } // --------------------------------------------------------------------------- // Tests // --------------------------------------------------------------------------- describe("MainLayout", () => { beforeEach(() => { vi.clearAllMocks(); }); it("renders the navigation sidebar", () => { renderLayout(); expect(screen.getByRole("navigation", { name: "Main navigation" })).toBeInTheDocument(); }); it("does not show the BanGUI application version in the sidebar footer", () => { renderLayout(); // __APP_VERSION__ is stubbed to "0.0.0-test" via vitest.config.ts define. expect(screen.queryByText(/BanGUI v/)).not.toBeInTheDocument(); }); it("hides the logo text when the sidebar is collapsed", async () => { renderLayout(); const toggleButton = screen.getByRole("button", { name: /collapse sidebar/i }); await userEvent.click(toggleButton); expect(screen.queryByText("BanGUI")).not.toBeInTheDocument(); }); });