The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
[Test] UI: Add unit tests for 10 previously untested components
yuneng-jiang20c1d984a610
diff --git a/ui/litellm-dashboard/src/components/AIHub/AgentHubTableColumns.test.tsx b/ui/litellm-dashboard/src/components/AIHub/AgentHubTableColumns.test.tsxnew file mode 100644index 00000000000..c32df2f5466--- /dev/null+++ b/ui/litellm-dashboard/src/components/AIHub/AgentHubTableColumns.test.tsx@@ -0,0 +1,132 @@+import { render, screen } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import { vi } from "vitest";+import { flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table";+import { getAgentHubTableColumns, AgentHubData } from "./AgentHubTableColumns";++const mockAgent: AgentHubData = {+ agent_id: "agent-1",+ protocolVersion: "1.0",+ name: "Test Agent",+ description: "A test agent for unit testing",+ url: "https://agent.example.com",+ version: "2.0",+ capabilities: { streaming: true, caching: false },+ defaultInputModes: ["text"],+ defaultOutputModes: ["text", "image"],+ skills: [+ { id: "s1", name: "Skill One", description: "First skill" },+ { id: "s2", name: "Skill Two", description: "Second skill" },+ { id: "s3", name: "Skill Three", description: "Third skill" },+ ],+ is_public: true,+};++function TestTable({ data, publicPage = false }: { data: AgentHubData[]; publicPage?: boolean }) {+ const showModal = vi.fn();+ const copyToClipboard = vi.fn();+ const columns = getAgentHubTableColumns(showModal, copyToClipboard, publicPage);+ const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel() });++ return (+ <table>+ <thead>+ {table.getHeaderGroups().map((hg) => (+ <tr key={hg.id}>+ {hg.headers.map((h) => (+ <th key={h.id}>{flexRender(h.column.columnDef.header, h.getContext())}</th>+ ))}+ </tr>+ ))}+ </thead>+ <tbody>+ {table.getRowModel().rows.map((row) => (+ <tr key={row.id}>+ {row.getVisibleCells().map((cell) => (+ <td key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</td>+ ))}+ </tr>+ ))}+ </tbody>+ </table>+ );+}++describe("AgentHubTableColumns", () => {+ it("should render", () => {+ render(<TestTable data={[mockAgent]} />);+ expect(screen.getByText("Test Agent")).toBeInTheDocument();+ });++ it("should display the agent description", () => {+ render(<TestTable data={[mockAgent]} />);+ // Description appears in both the description column and the mobile view within agent name column+ expect(screen.getAllByText("A test agent for unit testing").length).toBeGreaterThanOrEqual(1);+ });++ it("should display the version with a 'v' prefix", () => {+ render(<TestTable data={[mockAgent]} />);+ expect(screen.getByText("v2.0")).toBeInTheDocument();+ });++ it("should display the protocol version", () => {+ render(<TestTable data={[mockAgent]} />);+ expect(screen.getByText("1.0")).toBeInTheDocument();+ });++ it("should show skill count with correct pluralization", () => {+ render(<TestTable data={[mockAgent]} />);+ expect(screen.getByText("3 skills")).toBeInTheDocument();+ });++ it("should show first two skills and '+1' for overflow", () => {+ render(<TestTable data={[mockAgent]} />);+ expect(screen.getByText("Skill One")).toBeInTheDocument();+ expect(screen.getByText("Skill Two")).toBeInTheDocument();+ expect(screen.getByText("+1")).toBeInTheDocument();+ });++ it("should show only true capabilities as badges", () => {+ render(<TestTable data={[mockAgent]} />);+ expect(screen.getByText("streaming")).toBeInTheDocument();+ expect(screen.queryByText("caching")).not.toBeInTheDocument();+ });++ it("should display I/O modes", () => {+ render(<TestTable data={[mockAgent]} />);+ expect(screen.getByText("text")).toBeInTheDocument();+ expect(screen.getByText("text, image")).toBeInTheDocument();+ });++ it("should display 'Yes' badge for public agents", () => {+ render(<TestTable data={[mockAgent]} />);+ expect(screen.getByText("Yes")).toBeInTheDocument();+ });++ it("should display 'No' badge for non-public agents", () => {+ const privateAgent = { ...mockAgent, is_public: false };+ render(<TestTable data={[privateAgent]} />);+ expect(screen.getByText("No")).toBeInTheDocument();+ });++ it("should display a Details button", () => {+ render(<TestTable data={[mockAgent]} />);+ expect(screen.getByRole("button", { name: /details|info/i })).toBeInTheDocument();+ });++ it("should show '-' when agent has no capabilities", () => {+ const noCapAgent = { ...mockAgent, capabilities: {} };+ render(<TestTable data={[noCapAgent]} />);+ // The dash is rendered in the capabilities column+ expect(screen.getByText("-")).toBeInTheDocument();+ });++ it("should show singular 'skill' for one skill", () => {+ const oneSkillAgent = {+ ...mockAgent,+ skills: [{ id: "s1", name: "Only Skill", description: "One" }],+ };+ render(<TestTable data={[oneSkillAgent]} />);+ expect(screen.getByText("1 skill")).toBeInTheDocument();+ });+});diff --git a/ui/litellm-dashboard/src/components/DebugWarningBanner.test.tsx b/ui/litellm-dashboard/src/components/DebugWarningBanner.test.tsxnew file mode 100644index 00000000000..4c99175162d--- /dev/null+++ b/ui/litellm-dashboard/src/components/DebugWarningBanner.test.tsx@@ -0,0 +1,38 @@+import { renderWithProviders, screen } from "../../tests/test-utils";+import { vi } from "vitest";+import { DebugWarningBanner } from "./DebugWarningBanner";++const mockUseHealthReadiness = vi.fn();+vi.mock("@/app/(dashboard)/hooks/healthReadiness/useHealthReadiness", () => ({+ useHealthReadiness: () => mockUseHealthReadiness(),+}));++describe("DebugWarningBanner", () => {+ afterEach(() => {+ vi.resetAllMocks();+ });++ it("should render", () => {+ mockUseHealthReadiness.mockReturnValue({ data: { is_detailed_debug: true } });+ renderWithProviders(<DebugWarningBanner />);+ expect(screen.getByText(/Performance Warning/i)).toBeInTheDocument();+ });++ it("should render nothing when debug mode is disabled", () => {+ mockUseHealthReadiness.mockReturnValue({ data: { is_detailed_debug: false } });+ const { container } = renderWithProviders(<DebugWarningBanner />);+ expect(container.firstChild).toBeNull();+ });++ it("should render nothing when health data is undefined", () => {+ mockUseHealthReadiness.mockReturnValue({ data: undefined });+ const { container } = renderWithProviders(<DebugWarningBanner />);+ expect(container.firstChild).toBeNull();+ });++ it("should mention LITELLM_LOG=DEBUG in the description", () => {+ mockUseHealthReadiness.mockReturnValue({ data: { is_detailed_debug: true } });+ renderWithProviders(<DebugWarningBanner />);+ expect(screen.getByText(/LITELLM_LOG=DEBUG/)).toBeInTheDocument();+ });+});diff --git a/ui/litellm-dashboard/src/components/EntityUsageExport/ExportFormatSelector.test.tsx b/ui/litellm-dashboard/src/components/EntityUsageExport/ExportFormatSelector.test.tsxnew file mode 100644index 00000000000..a88f9cb116c--- /dev/null+++ b/ui/litellm-dashboard/src/components/EntityUsageExport/ExportFormatSelector.test.tsx@@ -0,0 +1,36 @@+import { render, screen } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import { vi } from "vitest";+import ExportFormatSelector from "./ExportFormatSelector";++describe("ExportFormatSelector", () => {+ it("should render", () => {+ render(<ExportFormatSelector value="csv" onChange={vi.fn()} />);+ expect(screen.getByText("Format")).toBeInTheDocument();+ });++ it("should display the current value as csv", () => {+ render(<ExportFormatSelector value="csv" onChange={vi.fn()} />);+ expect(screen.getByText("CSV (Excel, Google Sheets)")).toBeInTheDocument();+ });++ it("should display the current value as json", () => {+ render(<ExportFormatSelector value="json" onChange={vi.fn()} />);+ expect(screen.getByText("JSON (includes metadata)")).toBeInTheDocument();+ });++ it("should call onChange when a different format is selected", async () => {+ const onChange = vi.fn();+ const user = userEvent.setup();+ render(<ExportFormatSelector value="csv" onChange={onChange} />);++ // Open the Ant Design Select dropdown+ await user.click(screen.getByText("CSV (Excel, Google Sheets)"));+ // Select JSON option from the dropdown+ const jsonOption = await screen.findByText("JSON (includes metadata)", {+ selector: ".ant-select-item-option-content",+ });+ await user.click(jsonOption);+ expect(onChange).toHaveBeenCalledWith("json", expect.anything());+ });+});diff --git a/ui/litellm-dashboard/src/components/EntityUsageExport/ExportSummary.test.tsx b/ui/litellm-dashboard/src/components/EntityUsageExport/ExportSummary.test.tsxnew file mode 100644index 00000000000..ab426e291b1--- /dev/null+++ b/ui/litellm-dashboard/src/components/EntityUsageExport/ExportSummary.test.tsx@@ -0,0 +1,35 @@+import { render, screen } from "@testing-library/react";+import ExportSummary from "./ExportSummary";++describe("ExportSummary", () => {+ const dateRange = {+ from: new Date("2025-01-01"),+ to: new Date("2025-01-31"),+ };++ it("should render", () => {+ render(<ExportSummary dateRange={dateRange} selectedFilters={[]} />);+ expect(screen.getByText(/2025/)).toBeInTheDocument();+ });++ it("should display formatted date range", () => {+ render(<ExportSummary dateRange={dateRange} selectedFilters={[]} />);+ const text = screen.getByText(/\d+.*-.*\d+/);+ expect(text).toBeInTheDocument();+ });++ it("should show singular 'filter' for one filter", () => {+ render(<ExportSummary dateRange={dateRange} selectedFilters={["team-a"]} />);+ expect(screen.getByText(/1 filter$/)).toBeInTheDocument();+ });++ it("should show plural 'filters' for multiple filters", () => {+ render(<ExportSummary dateRange={dateRange} selectedFilters={["team-a", "team-b"]} />);+ expect(screen.getByText(/2 filters/)).toBeInTheDocument();+ });++ it("should not show filter text when no filters applied", () => {+ render(<ExportSummary dateRange={dateRange} selectedFilters={[]} />);+ expect(screen.queryByText(/filter/)).not.toBeInTheDocument();+ });+});diff --git a/ui/litellm-dashboard/src/components/EntityUsageExport/ExportTypeSelector.test.tsx b/ui/litellm-dashboard/src/components/EntityUsageExport/ExportTypeSelector.test.tsxnew file mode 100644index 00000000000..6ccf8822e02--- /dev/null+++ b/ui/litellm-dashboard/src/components/EntityUsageExport/ExportTypeSelector.test.tsx@@ -0,0 +1,37 @@+import { render, screen } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import { vi } from "vitest";+import ExportTypeSelector from "./ExportTypeSelector";++describe("ExportTypeSelector", () => {+ it("should render", () => {+ render(<ExportTypeSelector value="daily" onChange={vi.fn()} entityType="team" />);+ expect(screen.getByText("Export type")).toBeInTheDocument();+ });++ it("should render all three radio options", () => {+ render(<ExportTypeSelector value="daily" onChange={vi.fn()} entityType="team" />);+ expect(screen.getAllByRole("radio")).toHaveLength(3);+ });++ it("should interpolate entity type in labels", () => {+ render(<ExportTypeSelector value="daily" onChange={vi.fn()} entityType="organization" />);+ expect(screen.getByText(/Day-by-day breakdown by organization$/)).toBeInTheDocument();+ expect(screen.getByText(/organization and key/)).toBeInTheDocument();+ expect(screen.getByText(/organization and model/)).toBeInTheDocument();+ });++ it("should call onChange when a different option is selected", async () => {+ const onChange = vi.fn();+ const user = userEvent.setup();+ render(<ExportTypeSelector value="daily" onChange={onChange} entityType="team" />);+ await user.click(screen.getByText(/by team and key/));+ expect(onChange).toHaveBeenCalledWith("daily_with_keys");+ });++ it("should have the correct radio checked based on value prop", () => {+ render(<ExportTypeSelector value="daily_with_models" onChange={vi.fn()} entityType="team" />);+ const radios = screen.getAllByRole("radio");+ expect(radios[2]).toBeChecked();+ });+});diff --git a/ui/litellm-dashboard/src/components/EntityUsageExport/UsageExportHeader.test.tsx b/ui/litellm-dashboard/src/components/EntityUsageExport/UsageExportHeader.test.tsxnew file mode 100644index 00000000000..729d6fd3406--- /dev/null+++ b/ui/litellm-dashboard/src/components/EntityUsageExport/UsageExportHeader.test.tsx@@ -0,0 +1,73 @@+import { renderWithProviders, screen } from "../../../tests/test-utils";+import userEvent from "@testing-library/user-event";+import { vi } from "vitest";+import UsageExportHeader from "./UsageExportHeader";+import type { EntitySpendData } from "./types";++vi.mock("./EntityUsageExportModal", () => ({+ default: ({ isOpen, onClose }: { isOpen: boolean; onClose: () => void }) =>+ isOpen ? (+ <div data-testid="export-modal">+ <button onClick={onClose}>Close</button>+ </div>+ ) : null,+}));++const defaultProps = {+ dateValue: { from: new Date("2025-01-01"), to: new Date("2025-01-31") },+ entityType: "team" as const,+ spendData: {+ results: [],+ metadata: {+ total_spend: 0,+ total_api_requests: 0,+ total_successful_requests: 0,+ total_failed_requests: 0,+ total_tokens: 0,+ },+ } satisfies EntitySpendData,+};++describe("UsageExportHeader", () => {+ it("should render", () => {+ renderWithProviders(<UsageExportHeader {...defaultProps} />);+ expect(screen.getByRole("button", { name: /export data/i })).toBeInTheDocument();+ });++ it("should open the export modal when the export button is clicked", async () => {+ const user = userEvent.setup();+ renderWithProviders(<UsageExportHeader {...defaultProps} />);+ await user.click(screen.getByRole("button", { name: /export data/i }));+ expect(screen.getByTestId("export-modal")).toBeInTheDocument();+ });++ it("should close the export modal when onClose is called", async () => {+ const user = userEvent.setup();+ renderWithProviders(<UsageExportHeader {...defaultProps} />);+ await user.click(screen.getByRole("button", { name: /export data/i }));+ await user.click(screen.getByRole("button", { name: /close/i }));+ expect(screen.queryByTestId("export-modal")).not.toBeInTheDocument();+ });++ it("should not show filter dropdown when showFilters is false", () => {+ renderWithProviders(<UsageExportHeader {...defaultProps} showFilters={false} />);+ expect(screen.queryByText(/filter/i)).not.toBeInTheDocument();+ });++ it("should show filter dropdown when showFilters is true and options provided", () => {+ renderWithProviders(+ <UsageExportHeader+ {...defaultProps}+ showFilters+ filterLabel="Team"+ filterPlaceholder="Select teams"+ filterOptions={[+ { label: "Team A", value: "team-a" },+ { label: "Team B", value: "team-b" },+ ]}+ onFiltersChange={vi.fn()}+ />,+ );+ expect(screen.getByText("Team")).toBeInTheDocument();+ });+});diff --git a/ui/litellm-dashboard/src/components/GuardrailsMonitor/GuardrailConfig.test.tsx b/ui/litellm-dashboard/src/components/GuardrailsMonitor/GuardrailConfig.test.tsxnew file mode 100644index 00000000000..fd9ad61599b--- /dev/null+++ b/ui/litellm-dashboard/src/components/GuardrailsMonitor/GuardrailConfig.test.tsx@@ -0,0 +1,84 @@+import { render, screen, act } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import { vi } from "vitest";+import { GuardrailConfig } from "./GuardrailConfig";++describe("GuardrailConfig", () => {+ const defaultProps = {+ guardrailName: "Content Safety",+ guardrailType: "Content Safety",+ provider: "bedrock",+ };++ it("should render", () => {+ render(<GuardrailConfig {...defaultProps} />);+ expect(screen.getByText("Parameters")).toBeInTheDocument();+ });++ it("should display the guardrail name in the parameters description", () => {+ render(<GuardrailConfig {...defaultProps} />);+ expect(screen.getByText(/Configure Content Safety behavior/)).toBeInTheDocument();+ });++ it("should show version history when 'View history' is clicked", async () => {+ const user = userEvent.setup();+ render(<GuardrailConfig {...defaultProps} />);+ await user.click(screen.getByRole("button", { name: /view history/i }));+ expect(screen.getByText("Initial configuration")).toBeInTheDocument();+ expect(screen.getByText("Added custom categories list")).toBeInTheDocument();+ });++ it("should toggle version history text between View/Hide", async () => {+ const user = userEvent.setup();+ render(<GuardrailConfig {...defaultProps} />);+ const button = screen.getByRole("button", { name: /view history/i });+ await user.click(button);+ expect(screen.getByRole("button", { name: /hide history/i })).toBeInTheDocument();+ });++ it("should show custom code textarea when custom code override is toggled on", async () => {+ const user = userEvent.setup();+ render(<GuardrailConfig {...defaultProps} />);+ const switches = screen.getAllByRole("switch");+ // The second switch is the custom code override toggle+ const customCodeSwitch = switches[1];+ await user.click(customCodeSwitch);+ expect(screen.getByPlaceholderText(/async def evaluate/)).toBeInTheDocument();+ });++ it("should hide custom code textarea when custom code override is off", () => {+ render(<GuardrailConfig {...defaultProps} />);+ // There's an input for categories, but no textarea+ expect(screen.queryByPlaceholderText(/async def evaluate/)).not.toBeInTheDocument();+ });++ it("should show the re-run button in idle state", () => {+ render(<GuardrailConfig {...defaultProps} />);+ expect(screen.getByRole("button", { name: /re-run on failing logs/i })).toBeInTheDocument();+ });++ it("should show loading state when re-run is clicked", async () => {+ vi.useFakeTimers({ shouldAdvanceTime: true });+ const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });+ render(<GuardrailConfig {...defaultProps} />);+ await user.click(screen.getByRole("button", { name: /re-run on failing logs/i }));+ expect(screen.getByText(/Running on 10 samples/)).toBeInTheDocument();+ vi.useRealTimers();+ });++ it("should show success message after re-run completes", async () => {+ vi.useFakeTimers({ shouldAdvanceTime: true });+ const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });+ render(<GuardrailConfig {...defaultProps} />);+ await user.click(screen.getByRole("button", { name: /re-run on failing logs/i }));+ act(() => { vi.advanceTimersByTime(2500); });+ expect(screen.getByText(/7\/10 would now pass/)).toBeInTheDocument();+ vi.useRealTimers();+ });++ it("should display the Revert and Save buttons", () => {+ render(<GuardrailConfig {...defaultProps} />);+ expect(screen.getByRole("button", { name: /revert/i })).toBeInTheDocument();+ expect(screen.getByRole("button", { name: /save as v4/i })).toBeInTheDocument();+ });+});diff --git a/ui/litellm-dashboard/src/components/GuardrailsMonitor/MetricCard.test.tsx b/ui/litellm-dashboard/src/components/GuardrailsMonitor/MetricCard.test.tsxnew file mode 100644index 00000000000..9352cf46556--- /dev/null+++ b/ui/litellm-dashboard/src/components/GuardrailsMonitor/MetricCard.test.tsx@@ -0,0 +1,34 @@+import { render, screen } from "@testing-library/react";+import { MetricCard } from "./MetricCard";++describe("MetricCard", () => {+ it("should render", () => {+ render(<MetricCard label="Total Requests" value={1234} />);+ expect(screen.getByText("Total Requests")).toBeInTheDocument();+ });++ it("should display the numeric value", () => {+ render(<MetricCard label="Total Requests" value={1234} />);+ expect(screen.getByText("1234")).toBeInTheDocument();+ });++ it("should display a string value", () => {+ render(<MetricCard label="Pass Rate" value="95.2%" />);+ expect(screen.getByText("95.2%")).toBeInTheDocument();+ });++ it("should display subtitle when provided", () => {+ render(<MetricCard label="Blocked" value={42} subtitle="Last 7 days" />);+ expect(screen.getByText("Last 7 days")).toBeInTheDocument();+ });++ it("should not display subtitle when not provided", () => {+ render(<MetricCard label="Blocked" value={42} />);+ expect(screen.queryByText(/days/)).not.toBeInTheDocument();+ });++ it("should display icon when provided", () => {+ render(<MetricCard label="Status" value="OK" icon={<span data-testid="icon">!</span>} />);+ expect(screen.getByTestId("icon")).toBeInTheDocument();+ });+});diff --git a/ui/litellm-dashboard/src/components/GuardrailsMonitor/ScoreChart.test.tsx b/ui/litellm-dashboard/src/components/GuardrailsMonitor/ScoreChart.test.tsxnew file mode 100644index 00000000000..b950dd9a302--- /dev/null+++ b/ui/litellm-dashboard/src/components/GuardrailsMonitor/ScoreChart.test.tsx@@ -0,0 +1,47 @@+import { render, screen } from "@testing-library/react";+import { ScoreChart } from "./ScoreChart";++vi.mock("@tremor/react", async (importOriginal) => {+ const actual = await importOriginal<typeof import("@tremor/react")>();+ return {+ ...actual,+ BarChart: ({ data, categories }: { data: unknown[]; categories: string[] }) => (+ <div data-testid="bar-chart" data-categories={categories.join(",")}>+ {data.length} data points+ </div>+ ),+ };+});++describe("ScoreChart", () => {+ it("should render", () => {+ render(<ScoreChart />);+ expect(screen.getByText("Request Outcomes Over Time")).toBeInTheDocument();+ });++ it("should show empty state when no data provided", () => {+ render(<ScoreChart />);+ expect(screen.getByText("No chart data for this period")).toBeInTheDocument();+ });++ it("should show empty state when data is an empty array", () => {+ render(<ScoreChart data={[]} />);+ expect(screen.getByText("No chart data for this period")).toBeInTheDocument();+ });++ it("should render chart when data is provided", () => {+ const data = [+ { date: "2025-01-01", passed: 100, blocked: 5 },+ { date: "2025-01-02", passed: 120, blocked: 3 },+ ];+ render(<ScoreChart data={data} />);+ expect(screen.getByTestId("bar-chart")).toBeInTheDocument();+ expect(screen.getByText("2 data points")).toBeInTheDocument();+ });++ it("should pass correct categories to the chart", () => {+ const data = [{ date: "2025-01-01", passed: 100, blocked: 5 }];+ render(<ScoreChart data={data} />);+ expect(screen.getByTestId("bar-chart")).toHaveAttribute("data-categories", "passed,blocked");+ });+});diff --git a/ui/litellm-dashboard/src/components/HelpLink.test.tsx b/ui/litellm-dashboard/src/components/HelpLink.test.tsxnew file mode 100644index 00000000000..2e9b44a9e90--- /dev/null+++ b/ui/litellm-dashboard/src/components/HelpLink.test.tsx@@ -0,0 +1,128 @@+import { render, screen } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import { HelpLink, HelpIcon, DocsMenu } from "./HelpLink";++describe("HelpLink", () => {+ it("should render", () => {+ render(<HelpLink href="https://docs.example.com" />);+ expect(screen.getByRole("link")).toBeInTheDocument();+ });++ it("should display default 'Learn more' text when no children provided", () => {+ render(<HelpLink href="https://docs.example.com" />);+ expect(screen.getByText("Learn more")).toBeInTheDocument();+ });++ it("should display custom children text", () => {+ render(<HelpLink href="https://docs.example.com">Custom docs link</HelpLink>);+ expect(screen.getByText("Custom docs link")).toBeInTheDocument();+ });++ it("should open in a new tab with noopener noreferrer", () => {+ render(<HelpLink href="https://docs.example.com" />);+ const link = screen.getByRole("link");+ expect(link).toHaveAttribute("target", "_blank");+ expect(link).toHaveAttribute("rel", "noopener noreferrer");+ });++ it("should have accessible screen reader text", () => {+ render(<HelpLink href="https://docs.example.com" />);+ expect(screen.getByText("(opens in a new tab)")).toBeInTheDocument();+ });+});++describe("HelpIcon", () => {+ it("should render", () => {+ render(<HelpIcon content="Some help text" />);+ expect(screen.getByRole("button", { name: /help information/i })).toBeInTheDocument();+ });++ it("should show tooltip content on mouse enter", async () => {+ const user = userEvent.setup();+ render(<HelpIcon content="Helpful tooltip text" />);+ await user.hover(screen.getByRole("button", { name: /help information/i }));+ expect(screen.getByText("Helpful tooltip text")).toBeInTheDocument();+ });++ it("should hide tooltip content on mouse leave", async () => {+ const user = userEvent.setup();+ render(<HelpIcon content="Helpful tooltip text" />);+ const button = screen.getByRole("button", { name: /help information/i });+ await user.hover(button);+ await user.unhover(button);+ expect(screen.queryByText("Helpful tooltip text")).not.toBeInTheDocument();+ });++ it("should show learn more link when learnMoreHref is provided", async () => {+ const user = userEvent.setup();+ render(<HelpIcon content="Help text" learnMoreHref="https://docs.example.com" />);+ await user.hover(screen.getByRole("button", { name: /help information/i }));+ expect(screen.getByText("Learn more")).toBeInTheDocument();+ });++ it("should use custom learnMoreText when provided", async () => {+ const user = userEvent.setup();+ render(+ <HelpIcon content="Help text" learnMoreHref="https://docs.example.com" learnMoreText="Read docs" />,+ );+ await user.hover(screen.getByRole("button", { name: /help information/i }));+ expect(screen.getByText("Read docs")).toBeInTheDocument();+ });+});++describe("DocsMenu", () => {+ const items = [+ { label: "Custom pricing", href: "https://docs.example.com/pricing" },+ { label: "Spend tracking", href: "https://docs.example.com/spend" },+ ];++ it("should render", () => {+ render(<DocsMenu items={items} />);+ expect(screen.getByRole("button", { name: /docs/i })).toBeInTheDocument();+ });++ it("should show menu items when clicked", async () => {+ const user = userEvent.setup();+ render(<DocsMenu items={items} />);+ await user.click(screen.getByRole("button", { name: /docs/i }));+ expect(screen.getByText("Custom pricing")).toBeInTheDocument();+ expect(screen.getByText("Spend tracking")).toBeInTheDocument();+ });++ it("should hide menu items when clicked again", async () => {+ const user = userEvent.setup();+ render(<DocsMenu items={items} />);+ const button = screen.getByRole("button", { name: /docs/i });+ await user.click(button);+ await user.click(button);+ expect(screen.queryByText("Custom pricing")).not.toBeInTheDocument();+ });++ it("should set aria-expanded correctly", async () => {+ const user = userEvent.setup();+ render(<DocsMenu items={items} />);+ const button = screen.getByRole("button", { name: /docs/i });+ expect(button).toHaveAttribute("aria-expanded", "false");+ await user.click(button);+ expect(button).toHaveAttribute("aria-expanded", "true");+ });++ it("should close menu when clicking outside", async () => {+ const user = userEvent.setup();+ render(+ <div>+ <DocsMenu items={items} />+ <button>Outside</button>+ </div>,+ );+ await user.click(screen.getByRole("button", { name: /docs/i }));+ expect(screen.getByText("Custom pricing")).toBeInTheDocument();+ await user.click(screen.getByRole("button", { name: /outside/i }));+ expect(screen.queryByText("Custom pricing")).not.toBeInTheDocument();+ });++ it("should display custom children text", () => {+ render(<DocsMenu items={items}>Help</DocsMenu>);+ expect(screen.getByText("Help")).toBeInTheDocument();+ });+});