Skip to content

Commit bd706f6

Browse files
committed
test(aurora): add tests for useShadowDOM, appName, logo slot and fix title fallback
1 parent 8803ba9 commit bd706f6

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

packages/aurora/src/client/components/Slot.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,13 @@ describe("Slot", () => {
4848
})
4949
expect(HTMLElement.prototype.attachShadow).toHaveBeenCalledWith({ mode: "open" })
5050
})
51+
52+
it("renders the component without a shadow root when useShadowDOM is false", async () => {
53+
let container!: HTMLElement
54+
await act(async () => {
55+
;({ container } = render(<Slot component={TestWidget} useShadowDOM={false} />))
56+
})
57+
expect(container.querySelector("[data-testid='test-widget']")).toBeTruthy()
58+
expect(HTMLElement.prototype.attachShadow).not.toHaveBeenCalled()
59+
})
5160
})

packages/aurora/src/client/components/navigation/MainNavigation.test.tsx

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { describe, test, expect, beforeAll } from "vitest"
1+
import { describe, test, expect, beforeAll, vi } from "vitest"
22
import { render, screen, fireEvent, waitFor, act } from "@testing-library/react"
33
import { i18n } from "@lingui/core"
44
import { I18nProvider } from "@lingui/react"
5-
import { ReactNode } from "react"
5+
import { FC, ReactNode } from "react"
66
import { MainNavigation } from "./MainNavigation"
77
import { AuthProvider } from "../../store/AuthProvider"
8+
import type { SlotProps } from "../../AuroraApp"
89

910
import {
1011
createRootRoute,
@@ -245,4 +246,39 @@ describe("MainNavigation", () => {
245246
// Check that default items are not rendered
246247
expect(screen.queryByText("About")).toBeNull()
247248
})
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+
})
248284
})

0 commit comments

Comments
 (0)