|
1 | | -import { describe, test, expect, beforeAll } from "vitest" |
| 1 | +import { describe, test, expect, beforeAll, vi } from "vitest" |
2 | 2 | import { render, screen, fireEvent, waitFor, act } from "@testing-library/react" |
3 | 3 | import { i18n } from "@lingui/core" |
4 | 4 | import { I18nProvider } from "@lingui/react" |
5 | | -import { ReactNode } from "react" |
| 5 | +import { FC, ReactNode } from "react" |
6 | 6 | import { MainNavigation } from "./MainNavigation" |
7 | 7 | import { AuthProvider } from "../../store/AuthProvider" |
| 8 | +import type { SlotProps } from "../../AuroraApp" |
8 | 9 |
|
9 | 10 | import { |
10 | 11 | createRootRoute, |
@@ -245,4 +246,39 @@ describe("MainNavigation", () => { |
245 | 246 | // Check that default items are not rendered |
246 | 247 | expect(screen.queryByText("About")).toBeNull() |
247 | 248 | }) |
| 249 | + |
| 250 | + test("renders custom appName instead of default Aurora", async () => { |
| 251 | + await act(async () => { |
| 252 | + i18n.activate("en") |
| 253 | + }) |
| 254 | + |
| 255 | + const router = createTestRouter(<MainNavigation items={mainNavItems} appName="My Cloud" />) |
| 256 | + |
| 257 | + await waitFor(() => render(<RouterProvider router={router} />)) |
| 258 | + |
| 259 | + await waitFor(() => { |
| 260 | + expect(screen.getByText("My Cloud")).toBeDefined() |
| 261 | + expect(screen.queryByText("Aurora")).toBeNull() |
| 262 | + }) |
| 263 | + }) |
| 264 | + |
| 265 | + test("renders custom logo slot instead of default logo", async () => { |
| 266 | + await act(async () => { |
| 267 | + i18n.activate("en") |
| 268 | + }) |
| 269 | + |
| 270 | + const CustomLogo = (() => <img data-testid="custom-logo" src="/custom-logo.svg" alt="Custom" />) as FC<SlotProps> |
| 271 | + |
| 272 | + vi.spyOn(await import("@tanstack/react-router"), "useRouteContext").mockReturnValue({ trpcClient: {} }) |
| 273 | + |
| 274 | + const router = createTestRouter(<MainNavigation items={mainNavItems} slots={{ logo: CustomLogo }} />) |
| 275 | + |
| 276 | + await waitFor(() => render(<RouterProvider router={router} />)) |
| 277 | + |
| 278 | + await waitFor(() => { |
| 279 | + expect(screen.getByTestId("custom-logo")).toBeDefined() |
| 280 | + }) |
| 281 | + |
| 282 | + vi.restoreAllMocks() |
| 283 | + }) |
248 | 284 | }) |
0 commit comments