File size: 5,822 Bytes
fd2c364 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | import type { ReactNode } from "react";
import { render, screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it, vi } from "vitest";
import { MemoryRouter } from "react-router";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { SettingsNavigation } from "#/components/features/settings/settings-navigation";
import { SettingsDesktopSidebar } from "#/components/features/settings/settings-desktop-sidebar";
import { SettingsMobileHub } from "#/components/features/settings/settings-mobile-hub";
import { OSS_NAV_ITEMS } from "#/constants/settings-nav";
import { SettingsNavRenderedItem } from "#/hooks/use-settings-nav-items";
import { ActiveBackendProvider } from "#/contexts/active-backend-context";
const llmItem = OSS_NAV_ITEMS.find((item) => item.to === "/settings/llm")!;
const condenserItem = OSS_NAV_ITEMS.find(
(item) => item.to === "/settings/condenser",
)!;
const verificationItem = OSS_NAV_ITEMS.find(
(item) => item.to === "/settings/verification",
)!;
const acpAccessibleItems: SettingsNavRenderedItem[] = [
{ type: "item", item: llmItem },
{ type: "item", item: condenserItem },
{ type: "item", item: verificationItem },
];
const baseItems: SettingsNavRenderedItem[] = [
{ type: "header", text: "SETTINGS$TITLE" as never },
{ type: "item", item: llmItem },
{ type: "divider" },
{ type: "item", item: condenserItem },
];
function renderSettingsNavigation(ui: ReactNode) {
return render(
<QueryClientProvider
client={
new QueryClient({ defaultOptions: { queries: { retry: false } } })
}
>
<ActiveBackendProvider>
<MemoryRouter>{ui}</MemoryRouter>
</ActiveBackendProvider>
</QueryClientProvider>,
);
}
describe("SettingsNavigation", () => {
it("renders the provided OSS navigation items, headers, and dividers", () => {
renderSettingsNavigation(
<SettingsNavigation
isMobileMenuOpen={false}
onCloseMobileMenu={vi.fn()}
navigationItems={baseItems}
/>,
);
expect(screen.getByTestId("settings-navbar")).toBeInTheDocument();
expect(screen.getAllByText("SETTINGS$TITLE").length).toBeGreaterThan(0);
expect(screen.getAllByText("SETTINGS$NAV_LLM").length).toBeGreaterThan(0);
expect(
screen.getAllByText("SETTINGS$NAV_CONDENSER").length,
).toBeGreaterThan(0);
});
it("closes the mobile drawer when the close button is clicked", async () => {
const onCloseMobileMenu = vi.fn();
renderSettingsNavigation(
<SettingsNavigation
isMobileMenuOpen
onCloseMobileMenu={onCloseMobileMenu}
navigationItems={baseItems}
/>,
);
await userEvent.click(
screen.getByRole("button", { name: "SIDEBAR$CLOSE_MENU" }),
);
expect(onCloseMobileMenu).toHaveBeenCalledTimes(1);
});
it("closes the mobile drawer after a navigation item is selected", async () => {
const onCloseMobileMenu = vi.fn();
renderSettingsNavigation(
<SettingsNavigation
isMobileMenuOpen
onCloseMobileMenu={onCloseMobileMenu}
navigationItems={baseItems}
/>,
);
const mobileNav = screen.getByTestId("settings-navbar");
await userEvent.click(within(mobileNav).getByText("SETTINGS$NAV_LLM"));
expect(onCloseMobileMenu).toHaveBeenCalledTimes(1);
});
it("keeps ACP-accessible settings clickable in the desktop sidebar", () => {
renderSettingsNavigation(
<SettingsNavigation
isMobileMenuOpen={false}
onCloseMobileMenu={vi.fn()}
navigationItems={acpAccessibleItems}
/>,
);
const desktopNav = screen.getByTestId("settings-navbar-desktop");
for (const item of [llmItem, condenserItem, verificationItem]) {
const link = within(desktopNav).getByTestId(
`sidebar-settings-${item.to}`,
);
expect(link).toHaveAttribute("href", item.to);
expect(link).not.toHaveAttribute("aria-disabled");
}
});
});
// Focused unit coverage for the two components extracted out of this file.
// The ``SettingsNavigation`` suite above already exercises the behaviors both
// surfaces share (close button, item-select dismissal, the desktop
// disabled/tooltip wiring). These cover each extracted component's distinct
// contract that the composite does not assert.
describe("SettingsDesktopSidebar", () => {
it("renders a navigation link for each item entry and excludes headers and dividers", () => {
// Arrange + Act: baseItems holds one header, two items, and one divider.
renderSettingsNavigation(
<SettingsDesktopSidebar navigationItems={baseItems} />,
);
// Assert: only the two ``item`` entries become links — the header and
// divider are filtered out of the desktop rail.
const desktopNav = screen.getByTestId("settings-navbar-desktop");
const links = within(desktopNav).getAllByTestId(/^sidebar-settings-/);
expect(links).toHaveLength(2);
expect(
within(desktopNav).getByTestId("sidebar-settings-/settings/llm"),
).toBeInTheDocument();
expect(
within(desktopNav).getByTestId("sidebar-settings-/settings/condenser"),
).toBeInTheDocument();
});
});
describe("SettingsMobileHub", () => {
it("keeps ACP-accessible settings clickable in the mobile settings hub", () => {
renderSettingsNavigation(
<SettingsMobileHub navigationItems={acpAccessibleItems} />,
);
const mobileNav = screen.getByTestId("settings-mobile-hub");
for (const item of [llmItem, condenserItem, verificationItem]) {
const link = within(mobileNav).getByRole("link", {
name: item.text,
});
expect(link).toHaveAttribute("href", item.to);
expect(link).not.toHaveAttribute("aria-disabled");
}
});
});
|