Skip to content

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]

test(ui): query antd controls accessibly instead of by internal CSS class

Yuneng Jiang7d15c5b6da89
diff --git a/ui/litellm-dashboard/eslint.config.mjs b/ui/litellm-dashboard/eslint.config.mjs
index b5e876bfbba..73d1ee439b4 100644
--- a/ui/litellm-dashboard/eslint.config.mjs
+++ b/ui/litellm-dashboard/eslint.config.mjs
@@ -84,6 +84,12 @@ const eslintConfig = [
"no-restricted-syntax": "off",
},
},
+ {
+ files: ["src/**/*.test.{ts,tsx}", "tests/**/*.{ts,tsx}"],
+ rules: {
+ "local/no-antd-class-selectors": "error",
+ },
+ },
];
export default eslintConfig;
diff --git a/ui/litellm-dashboard/scripts/eslint-rules/index.mjs b/ui/litellm-dashboard/scripts/eslint-rules/index.mjs
index 9e9f901a6df..52db03a2c10 100644
--- a/ui/litellm-dashboard/scripts/eslint-rules/index.mjs
+++ b/ui/litellm-dashboard/scripts/eslint-rules/index.mjs
@@ -2,6 +2,7 @@ import noLargeInlineObjectArg from "./no-large-inline-object-arg.mjs";
import noLongConditionChain from "./no-long-condition-chain.mjs";
import noComplexJsxArrow from "./no-complex-jsx-arrow.mjs";
import filenamePascalCase from "./filename-pascal-case.mjs";
+import noAntdClassSelectors from "./no-antd-class-selectors.mjs";
const plugin = {
rules: {
@@ -9,6 +10,7 @@ const plugin = {
"no-long-condition-chain": noLongConditionChain,
"no-complex-jsx-arrow": noComplexJsxArrow,
"filename-pascal-case": filenamePascalCase,
+ "no-antd-class-selectors": noAntdClassSelectors,
},
};
diff --git a/ui/litellm-dashboard/scripts/eslint-rules/no-antd-class-selectors.mjs b/ui/litellm-dashboard/scripts/eslint-rules/no-antd-class-selectors.mjs
new file mode 100644
index 00000000000..c95bdb0467f
--- /dev/null
+++ b/ui/litellm-dashboard/scripts/eslint-rules/no-antd-class-selectors.mjs
@@ -0,0 +1,45 @@
+const SELECTOR_REFERENCE = /\.(?:ant|anticon)-[a-z0-9-]+/;
+const BARE_CLASS_REFERENCE = /^(?:ant|anticon)-[a-z0-9-]+$/;
+const CLASS_ASSERTION_CALLEES = new Set(["toHaveClass", "contains", "toContain"]);
+
+const isClassAssertionArgument = (node) => {
+ const call = node.parent;
+ if (call?.type !== "CallExpression" || !call.arguments.includes(node)) return false;
+ const callee = call.callee;
+ return callee?.type === "MemberExpression" && CLASS_ASSERTION_CALLEES.has(callee.property?.name);
+};
+
+const rule = {
+ meta: {
+ type: "problem",
+ docs: {
+ description:
+ "Disallow locating or asserting on antd's internal CSS classes in tests; query by role, label or text instead.",
+ },
+ schema: [],
+ messages: {
+ antdClass:
+ 'Test depends on antd internal class "{{value}}". Query by role, label or text (getByLabelText, getByRole("combobox"), getByTitle) so the test survives the shadcn migration.',
+ },
+ },
+ create(context) {
+ const report = (node, value) => {
+ if (typeof value !== "string") return;
+ const matches =
+ SELECTOR_REFERENCE.test(value) || (BARE_CLASS_REFERENCE.test(value) && isClassAssertionArgument(node));
+ if (!matches) return;
+ context.report({ node, messageId: "antdClass", data: { value } });
+ };
+
+ return {
+ Literal(node) {
+ report(node, node.value);
+ },
+ TemplateElement(node) {
+ report(node, node.value.cooked);
+ },
+ };
+ },
+};
+
+export default rule;
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/add_guardrail_form.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/add_guardrail_form.test.tsx
index 91d95155e82..a386fca598e 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/add_guardrail_form.test.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/add_guardrail_form.test.tsx
@@ -26,6 +26,7 @@ describe("AddGuardrailForm close behavior", () => {
const { onClose } = renderForm();
expect(screen.getByText("Create guardrail")).toBeInTheDocument();
+ // eslint-disable-next-line local/no-antd-class-selectors -- exercises antd Modal mask dismissal; the mask has no role and is not reachable by an accessible query
const wrap = document.querySelector(".ant-modal-wrap") as HTMLElement;
expect(wrap).toBeTruthy();
fireEvent.mouseDown(wrap);
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info.test.tsx
index 5fcf07d3f8b..aae1998644a 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info.test.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info.test.tsx
@@ -1,5 +1,5 @@
import * as networking from "@/components/networking";
-import { fireEvent, render, waitFor } from "@testing-library/react";
+import { fireEvent, render, waitFor, within } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import GuardrailInfoView from "./guardrail_info";
@@ -153,7 +153,7 @@ describe("Guardrail Info", () => {
});
// Find the info icon and hover over it
- const infoIcon = container.querySelector(".anticon-info-circle");
+ const infoIcon = within(container).getByRole("img", { name: "info-circle" });
expect(infoIcon).toBeInTheDocument();
if (infoIcon) {
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/OAuthFormFields.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/OAuthFormFields.test.tsx
index 0ea4766154c..48964490339 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/OAuthFormFields.test.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/OAuthFormFields.test.tsx
@@ -177,8 +177,7 @@ describe("OAuthFormFields", () => {
<OAuthFormFields isM2M={false} />
</WithForm>,
);
- const authMethodLabel = screen.getByText("Token Endpoint Auth Method (optional)");
- const selector = authMethodLabel.closest(".ant-form-item")!.querySelector(".ant-select-selector")!;
+ const selector = screen.getByLabelText("Token Endpoint Auth Method (optional)");
await act(async () => {
fireEvent.mouseDown(selector);
});
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/compareUI/components/ModelSelector.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/compareUI/components/ModelSelector.test.tsx
index 3c5c52e8772..b6965da60fe 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/playground/components/compareUI/components/ModelSelector.test.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/playground/components/compareUI/components/ModelSelector.test.tsx
@@ -1,43 +1,38 @@
-import { render, waitFor } from "@testing-library/react";
+import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it, vi } from "vitest";
import { ModelSelector } from "./ModelSelector";
+const MODELS = ["gpt-4", "gpt-3.5-turbo"];
+
describe("ModelSelector", () => {
it("should render", () => {
- const onChange = vi.fn();
- const models = ["gpt-4", "gpt-3.5-turbo"];
- const { container } = render(<ModelSelector value="" onChange={onChange} models={models} />);
- const select = container.querySelector(".ant-select");
- expect(select).toBeInTheDocument();
+ render(<ModelSelector value="" onChange={vi.fn()} models={MODELS} />);
+ expect(screen.getByRole("combobox")).toBeInTheDocument();
});
- it("allows selecting a model and displays custom values", async () => {
+ it("reports the model the user picks from the dropdown", async () => {
const user = userEvent.setup();
const onChange = vi.fn();
- const models = ["gpt-4", "gpt-3.5-turbo"];
- const { container } = render(<ModelSelector value="" onChange={onChange} models={models} />);
+ render(<ModelSelector value="" onChange={onChange} models={MODELS} />);
- const select = container.querySelector(".ant-select-selector") as HTMLElement;
- await user.click(select);
+ await user.click(screen.getByRole("combobox"));
+ await user.click(await screen.findByTitle("gpt-4"));
- await waitFor(() => {
- const gpt4Option = document.querySelector('[title="gpt-4"].ant-select-item-option') as HTMLElement;
- expect(gpt4Option).toBeInTheDocument();
- });
-
- const gpt4Option = document.querySelector('[title="gpt-4"].ant-select-item-option') as HTMLElement;
- await user.click(gpt4Option);
expect(onChange).toHaveBeenCalledWith("gpt-4");
+ });
+
+ it("displays a custom value that is not one of the known models", () => {
+ render(<ModelSelector value="custom-model-123" onChange={vi.fn()} models={MODELS} />);
+
+ expect(screen.getByTitle("custom-model-123")).toHaveTextContent("custom-model-123");
+ });
- const { container: container2, rerender } = render(
- <ModelSelector value="custom-model-123" onChange={onChange} models={models} />,
- );
- const selectedValue = container2.querySelector(".ant-select-selection-item");
- expect(selectedValue).toHaveTextContent("custom-model-123");
+ it("disables the control when disabled is set", () => {
+ const { rerender } = render(<ModelSelector value="custom-model-123" onChange={vi.fn()} models={MODELS} />);
+ expect(screen.getByRole("combobox")).toBeEnabled();
- rerender(<ModelSelector value="custom-model-123" onChange={onChange} models={models} disabled={true} />);
- const selectElement = container2.querySelector(".ant-select");
- expect(selectElement).toHaveClass("ant-select-disabled");
+ rerender(<ModelSelector value="custom-model-123" onChange={vi.fn()} models={MODELS} disabled={true} />);
+ expect(screen.getByRole("combobox")).toBeDisabled();
});
});
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/policies/_components/add_attachment_form.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/policies/_components/add_attachment_form.test.tsx
index fca487df14e..9b599f55eee 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/policies/_components/add_attachment_form.test.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/policies/_components/add_attachment_form.test.tsx
@@ -1,5 +1,5 @@
import React from "react";
-import { screen, waitFor, within } from "@testing-library/react";
+import { screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { renderWithProviders } from "@/../tests/test-utils";
import { beforeEach, describe, expect, it, vi } from "vitest";
@@ -139,8 +139,7 @@ describe("AddAttachmentForm", () => {
};
const enterTeam = async (user: UserEvent, value: string) => {
- const item = screen.getByText("Teams").closest(".ant-form-item") as HTMLElement;
- const input = within(item).getByRole("combobox");
+ const input = screen.getByLabelText("Teams");
await user.click(input);
await user.type(input, `${value}{Enter}`);
};
diff --git a/ui/litellm-dashboard/src/components/Settings/AdminSettings/LoggingSettings/LoggingSettings.test.tsx b/ui/litellm-dashboard/src/components/Settings/AdminSettings/LoggingSettings/LoggingSettings.test.tsx
index a5ef93d2151..7c01c579251 100644
--- a/ui/litellm-dashboard/src/components/Settings/AdminSettings/LoggingSettings/LoggingSettings.test.tsx
+++ b/ui/litellm-dashboard/src/components/Settings/AdminSettings/LoggingSettings/LoggingSettings.test.tsx
@@ -6,7 +6,7 @@ import {
import { useStoreRequestInSpendLogs } from "@/app/(dashboard)/hooks/storeRequestInSpendLogs/useStoreRequestInSpendLogs";
import NotificationsManager from "@/components/molecules/notifications_manager";
import { parseErrorMessage } from "@/components/shared/errorUtils";
-import { screen, waitFor } from "@testing-library/react";
+import { screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { renderWithProviders } from "../../../../../tests/test-utils";
@@ -368,7 +368,7 @@ describe("LoggingSettings", () => {
const saveButton = screen.getByRole("button", { name: /Saving/i });
expect(saveButton).toBeInTheDocument();
- expect(saveButton.className).toContain("ant-btn-loading");
+ expect(within(saveButton).getByRole("img", { name: "loading" })).toBeInTheDocument();
});
it("should show loading state on save button when delete pending", () => {
@@ -381,7 +381,7 @@ describe("LoggingSettings", () => {
const saveButton = screen.getByRole("button", { name: /Saving/i });
expect(saveButton).toBeInTheDocument();
- expect(saveButton.className).toContain("ant-btn-loading");
+ expect(within(saveButton).getByRole("img", { name: "loading" })).toBeInTheDocument();
});
it("should render form with initial values from config data", () => {
@@ -508,6 +508,7 @@ describe("LoggingSettings", () => {
expect(screen.queryByPlaceholderText("e.g., 7d, 30d")).not.toBeInTheDocument();
expect(screen.queryByRole("button", { name: "Save Settings" })).not.toBeInTheDocument();
+ // eslint-disable-next-line local/no-antd-class-selectors -- antd Skeleton exposes no role, label or aria-busy to query the loading affordance by
const skeletons = document.querySelectorAll(".ant-skeleton");
expect(skeletons.length).toBeGreaterThan(0);
});
diff --git a/ui/litellm-dashboard/src/components/Teams.test.tsx b/ui/litellm-dashboard/src/components/Teams.test.tsx
index 79d994140e9..22ec986ba82 100644
--- a/ui/litellm-dashboard/src/components/Teams.test.tsx
+++ b/ui/litellm-dashboard/src/components/Teams.test.tsx
@@ -1,5 +1,5 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
-import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
+import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { NuqsTestingAdapter, OnUrlUpdateFunction } from "nuqs/adapters/testing";
import React from "react";
@@ -208,7 +208,7 @@ describe("Teams - handleCreate organization handling", () => {
};
// Simulate the handleCreate logic
- let organizationId = formValues?.organization_id || null;
+ const organizationId = formValues?.organization_id || null;
if (organizationId === "" || typeof organizationId !== "string") {
formValues.organization_id = null;
} else {
@@ -226,7 +226,7 @@ describe("Teams - handleCreate organization handling", () => {
models: [],
};
- let organizationId = formValues?.organization_id || null;
+ const organizationId = formValues?.organization_id || null;
if (organizationId === "" || typeof organizationId !== "string") {
formValues.organization_id = null;
} else {
@@ -243,7 +243,7 @@ describe("Teams - handleCreate organization handling", () => {
models: [],
};
- let organizationId = formValues?.organization_id || null;
+ const organizationId = formValues?.organization_id || null;
if (organizationId === "" || typeof organizationId !== "string") {
formValues.organization_id = null;
} else {
@@ -260,7 +260,7 @@ describe("Teams - handleCreate organization handling", () => {
models: [],
};
- let organizationId = formValues?.organization_id || null;
+ const organizationId = formValues?.organization_id || null;
if (organizationId === "" || typeof organizationId !== "string") {
formValues.organization_id = null;
} else {
@@ -278,7 +278,7 @@ describe("Teams - handleCreate organization handling", () => {
max_budget: 100,
};
- let organizationId = formValues?.organization_id || null;
+ const organizationId = formValues?.organization_id || null;
if (organizationId === "" || typeof organizationId !== "string") {
formValues.organization_id = null;
} else {
@@ -308,7 +308,7 @@ describe("Teams - handleCreate organization handling", () => {
models: [],
};
- let organizationId = formValues?.organization_id || currentOrg?.organization_id;
+ const organizationId = formValues?.organization_id || currentOrg?.organization_id;
if (organizationId === "" || typeof organizationId !== "string") {
formValues.organization_id = null;
} else {
@@ -522,14 +522,13 @@ describe("Teams - Create Team CTA is grouped with the tabs on the left", () => {
});
it("renders the Create Team button inside the tab bar, ahead of the tabs", () => {
- const { container } = renderWithQueryClient(<Teams accessToken="test-token" userID="user-123" userRole="Admin" />);
+ renderWithQueryClient(<Teams accessToken="test-token" userID="user-123" userRole="Admin" />);
const createButton = screen.getByTestId("create-team-button");
- const tabNav = container.querySelector(".ant-tabs-nav");
+ const tabBar = screen.getByRole("tablist").parentElement!;
// The CTA lives in the tab bar's left slot, not the standalone page header.
- expect(tabNav).not.toBeNull();
- expect(tabNav!.contains(createButton)).toBe(true);
+ expect(tabBar.contains(createButton)).toBe(true);
// It reads as the left end of the cluster: it precedes the first tab in DOM order.
const firstTab = screen.getByRole("tab", { name: "Your Teams" });
@@ -690,7 +689,7 @@ describe("Teams - Reset Budget in team create", () => {
});
};
- const resetBudgetField = () => screen.getByText("Reset Budget").closest(".ant-form-item") as HTMLElement;
+ const resetBudgetSelect = () => screen.getByLabelText("Reset Budget");
const submitCreateModal = async () => {
fireEvent.change(screen.getByLabelText(/team name/i), { target: { value: "Test Team" } });
@@ -708,7 +707,7 @@ describe("Teams - Reset Budget in team create", () => {
it("should send an explicit null budget_duration when Never resets is selected", async () => {
await openCreateModal();
- await userEvent.click(within(resetBudgetField()).getByRole("combobox"));
+ await userEvent.click(resetBudgetSelect());
await userEvent.click(await screen.findByText("Never resets"));
const payload = await submitCreateModal();
@@ -729,7 +728,7 @@ describe("Teams - Reset Budget in team create", () => {
it("should send the picked duration when one is selected", async () => {
await openCreateModal();
- await userEvent.click(within(resetBudgetField()).getByRole("combobox"));
+ await userEvent.click(resetBudgetSelect());
await userEvent.click(await screen.findByText("weekly"));
const payload = await submitCreateModal();
@@ -741,7 +740,7 @@ describe("Teams - Reset Budget in team create", () => {
await openCreateModal();
await waitFor(() => {
- expect(within(resetBudgetField()).getByText("Default: monthly (30d)")).toBeInTheDocument();
+ expect(screen.getByText("Default: monthly (30d)")).toBeInTheDocument();
});
});
@@ -751,7 +750,7 @@ describe("Teams - Reset Budget in team create", () => {
await openCreateModal();
await waitFor(() => {
- expect(within(resetBudgetField()).getByText("n/a")).toBeInTheDocument();
+ expect(screen.getByText("n/a")).toBeInTheDocument();
});
});
});
diff --git a/ui/litellm-dashboard/src/components/add_model/add_auto_router_tab.test.tsx b/ui/litellm-dashboard/src/components/add_model/add_auto_router_tab.test.tsx
index 7d42d85ccfb..efc1d77871e 100644
--- a/ui/litellm-dashboard/src/components/add_model/add_auto_router_tab.test.tsx
+++ b/ui/litellm-dashboard/src/components/add_model/add_auto_router_tab.test.tsx
@@ -23,7 +23,7 @@ const ALL_FAMILY_MODELS: ModelGroup[] = [
const ANTHROPIC_ONLY_MODEL = ANTHROPIC_TIERS.COMPLEX[0];
const openTemplateDropdown = (): void => {
- fireEvent.mouseDown(screen.getByTestId("template-selector").querySelector(".ant-select-selector")!);
+ fireEvent.mouseDown(within(screen.getByTestId("template-selector")).getByRole("combobox"));
};
// Detailed Configuration is collapsed by default, so any test reaching into it (a tier select, an
@@ -32,13 +32,14 @@ const expandDetailedConfiguration = (): void => {
fireEvent.click(screen.getByTestId("detailed-configuration-toggle"));
};
-// The rendered antd option whose text starts with a preset label. Matching on text (not role +
-// accessible name) sidesteps antd's list re-rendering options in place on every state change.
+const visibleOptions = (): HTMLElement[] =>
+ // eslint-disable-next-line local/no-antd-class-selectors -- antd puts role="option" only on a hidden mirror list of raw values; the visible options carry no role, no aria-disabled, and only a tooltip in title
+ Array.from(document.querySelectorAll<HTMLElement>(".ant-select-item-option"));
+
const optionByLabel = (label: string): HTMLElement | undefined =>
- Array.from(document.querySelectorAll<HTMLElement>(".ant-select-item-option")).find((el) =>
- el.textContent?.startsWith(label),
- );
+ visibleOptions().find((el) => el.textContent?.startsWith(label));
+// eslint-disable-next-line local/no-antd-class-selectors -- antd signals option disabled state only through this class
const isOptionDisabled = (option: HTMLElement): boolean => option.classList.contains("ant-select-item-option-disabled");
const { mockFetchAvailableModels, mockFetchAllModelDeployments } = vi.hoisted(() => ({
@@ -349,9 +350,7 @@ describe("AddAutoRouterTab", () => {
renderWithProviders(<Harness />);
openTemplateDropdown();
- const labels = Array.from(document.querySelectorAll<HTMLElement>(".ant-select-item-option")).map(
- (option) => option.querySelector(".font-medium")?.textContent,
- );
+ const labels = visibleOptions().map((option) => option.querySelector(".font-medium")?.textContent);
expect(labels).toEqual(["Anthropic Family", "OpenAI Family", "Custom Configuration"]);
});
@@ -670,9 +669,7 @@ describe("AddAutoRouterTab", () => {
await waitFor(() => {
expect(isOptionDisabled(optionByLabel("Anthropic Family")!)).toBe(false);
});
- const labels = Array.from(document.querySelectorAll<HTMLElement>(".ant-select-item-option")).map(
- (option) => option.querySelector(".font-medium")?.textContent,
- );
+ const labels = visibleOptions().map((option) => option.querySelector(".font-medium")?.textContent);
expect(labels).toEqual(["Anthropic Family", "OpenAI Family", "Custom Configuration"]);
});
diff --git a/ui/litellm-dashboard/src/components/common_components/KeyLifecycleSettings.test.tsx b/ui/litellm-dashboard/src/components/common_components/KeyLifecycleSettings.test.tsx
index 896d8a14717..a4263e2f321 100644
--- a/ui/litellm-dashboard/src/components/common_components/KeyLifecycleSettings.test.tsx
+++ b/ui/litellm-dashboard/src/components/common_components/KeyLifecycleSettings.test.tsx
@@ -44,6 +44,8 @@ const Harness: React.FC<HarnessProps> = ({ isCreateMode = true, onFinish = () =>
const getDurationInput = (isCreateMode = true) =>
screen.getByPlaceholderText(isCreateMode ? CREATE_PLACEHOLDER : EDIT_PLACEHOLDER) as HTMLInputElement;
+const isRenderedSelection = (el: HTMLElement): boolean => !el.closest('[role="listbox"]');
+
describe("KeyLifecycleSettings", () => {
beforeEach(() => {
vi.clearAllMocks();
@@ -155,7 +157,7 @@ describe("KeyLifecycleSettings", () => {
await user.click(screen.getByRole("combobox"));
await user.click(await screen.findByText("90 days"));
- await waitFor(() => expect(document.querySelector(".ant-select-selection-item")?.textContent).toBe("90 days"));
+ await waitFor(() => expect(screen.getAllByTitle("90 days").some(isRenderedSelection)).toBe(true));
expect(screen.getByTestId("rotation-interval-value")).toHaveTextContent("90d");
});
diff --git a/ui/litellm-dashboard/src/components/edit_auto_router/edit_auto_router_modal.test.tsx b/ui/litellm-dashboard/src/components/edit_auto_router/edit_auto_router_modal.test.tsx
index 74dea8cc2ed..254a34abf40 100644
--- a/ui/litellm-dashboard/src/components/edit_auto_router/edit_auto_router_modal.test.tsx
+++ b/ui/litellm-dashboard/src/components/edit_auto_router/edit_auto_router_modal.test.tsx
@@ -263,6 +263,7 @@ describe("EditAutoRouterModal classifier context window", () => {
expect(await screen.findByLabelText("Classifier system prompt")).toBeInTheDocument();
expect(baseElement.querySelectorAll('[data-slot="dialog-content"]')).toHaveLength(2);
+ // eslint-disable-next-line local/no-antd-class-selectors -- the assertion IS that no antd modal renders; naming the class is the point
expect(baseElement.querySelector(".ant-modal")).toBeNull();
});
diff --git a/ui/litellm-dashboard/src/components/model_dashboard/ModelSettingsModal/ModelSettingsModal.test.tsx b/ui/litellm-dashboard/src/components/model_dashboard/ModelSettingsModal/ModelSettingsModal.test.tsx
index 21c26c15b5a..a1b5de3d0ea 100644
--- a/ui/litellm-dashboard/src/components/model_dashboard/ModelSettingsModal/ModelSettingsModal.test.tsx
+++ b/ui/litellm-dashboard/src/components/model_dashboard/ModelSettingsModal/ModelSettingsModal.test.tsx
@@ -2,7 +2,7 @@ import { useProxyConfig } from "@/app/(dashboard)/hooks/proxyConfig/useProxyConf
import { useStoreModelInDB } from "@/app/(dashboard)/hooks/storeModelInDB/useStoreModelInDB";
import NotificationsManager from "@/components/molecules/notifications_manager";
import { parseErrorMessage } from "@/components/shared/errorUtils";
-import { screen, waitFor } from "@testing-library/react";
+import { screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { renderWithProviders } from "../../../../tests/test-utils";
@@ -235,7 +235,7 @@ describe("ModelSettingsModal", () => {
const saveButton = screen.getByRole("button", { name: /Saving/i });
expect(saveButton).toBeInTheDocument();
- expect(saveButton.className).toContain("ant-btn-loading");
+ expect(within(saveButton).getByRole("img", { name: "loading" })).toBeInTheDocument();
});
it("should not render modal when isVisible is false", () => {
@@ -280,6 +280,7 @@ describe("ModelSettingsModal", () => {
renderWithProviders(<ModelSettingsModal {...defaultProps} />);
expect(screen.queryByRole("switch")).not.toBeInTheDocument();
+ // eslint-disable-next-line local/no-antd-class-selectors -- antd Skeleton exposes no role, label or aria-busy to query the loading affordance by
const skeletons = document.querySelectorAll(".ant-skeleton");
expect(skeletons.length).toBeGreaterThan(0);
});
diff --git a/ui/litellm-dashboard/src/components/team/TeamInfo.test.tsx b/ui/litellm-dashboard/src/components/team/TeamInfo.test.tsx
index cfb7ad1a5ad..22481eaa4b2 100644
--- a/ui/litellm-dashboard/src/components/team/TeamInfo.test.tsx
+++ b/ui/litellm-dashboard/src/components/team/TeamInfo.test.tsx
@@ -982,18 +982,18 @@ describe("TeamInfoView", () => {
expect(screen.getByLabelText("Team Name")).toBeInTheDocument();
});
- return screen.getByText("Reset Budget").closest(".ant-form-item") as HTMLElement;
+ return screen.getByLabelText("Reset Budget");
};
it("should send an explicit null budget_duration when a stored Reset Budget is cleared", async () => {
const user = userEvent.setup({ delay: null });
- const resetBudgetItem = await openSettingsEditorForTeam(user, { budget_duration: "30d" });
+ const resetBudgetSelect = await openSettingsEditorForTeam(user, { budget_duration: "30d" });
- await user.click(within(resetBudgetItem).getByRole("combobox"));
+ await user.click(resetBudgetSelect);
await user.click(await screen.findByText("Never resets"));
await waitFor(() => {
- expect(within(resetBudgetItem).getByText("Never resets")).toBeInTheDocument();
+ expect(resetBudgetSelect).toHaveTextContent("Never resets");
});
await user.click(screen.getByRole("button", { name: /save changes/i }));
@@ -1022,9 +1022,9 @@ describe("TeamInfoView", () => {
it("should send the newly picked budget_duration when one is selected", async () => {
const user = userEvent.setup({ delay: null });
- const resetBudgetItem = await openSettingsEditorForTeam(user, { budget_duration: null });
+ const resetBudgetSelect = await openSettingsEditorForTeam(user, { budget_duration: null });
- await user.click(within(resetBudgetItem).getByRole("combobox"));
+ await user.click(resetBudgetSelect);
await user.click(await screen.findByText("weekly"));
await user.click(screen.getByRole("button", { name: /save changes/i }));
@@ -1457,20 +1457,11 @@ describe("TeamInfoView", () => {
expect(screen.getByLabelText(/^Guardrails/)).toBeInTheDocument();
});
- const dropdownsBefore = new Set(document.querySelectorAll(".ant-select-dropdown"));
-
await user.click(screen.getByLabelText(/^Guardrails/));
- return waitFor(
- () => {
- const opened = Array.from(document.querySelectorAll(".ant-select-dropdown")).find(
- (el) => !dropdownsBefore.has(el),
- );
- expect(opened).toBeDefined();
- return opened as HTMLElement;
- },
- { timeout: 5000 },
- );
+ const listbox = await screen.findByRole("listbox", {}, { timeout: 5000 });
+ // eslint-disable-next-line local/no-antd-class-selectors -- antd renders group headers outside the listbox and its popup container exposes no role or accessible name
+ return listbox.closest(".ant-select-dropdown") as HTMLElement;
};
beforeEach(() => {
@@ -1548,19 +1539,16 @@ describe("TeamInfoView", () => {
await user.click(screen.getByRole("tab", { name: "Settings" }));
await user.click(await screen.findByRole("button", { name: /edit settings/i }));
- const routesLabel = await screen.findByText("Allowed Pass Through Routes");
- const routesFormItem = routesLabel.closest(".ant-form-item") as HTMLElement;
-
- await user.click(within(routesFormItem).getByRole("combobox"));
+ await user.click(await screen.findByRole("combobox", { name: "Select pass through routes" }));
const option = await screen.findByText("POST /bedrock-passthrough");
await user.click(option);
+ await user.keyboard("{Escape}");
+
await waitFor(() => {
- expect(within(routesFormItem).getByText(/\/bedrock-passthrough/)).toBeInTheDocument();
+ expect(screen.getByText("POST /bedrock-passthrough")).toBeInTheDocument();
});
-
- await user.keyboard("{Escape}");
await user.click(screen.getByRole("button", { name: /save changes/i }));
await waitFor(() => {
diff --git a/ui/litellm-dashboard/src/components/templates/key_edit_view.test.tsx b/ui/litellm-dashboard/src/components/templates/key_edit_view.test.tsx
index cdbd3197f7d..a570ba66d75 100644
--- a/ui/litellm-dashboard/src/components/templates/key_edit_view.test.tsx
+++ b/ui/litellm-dashboard/src/components/templates/key_edit_view.test.tsx
@@ -1,4 +1,4 @@
-import { fireEvent, screen, waitFor, within } from "@testing-library/react";
+import { fireEvent, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { renderWithProviders } from "../../../tests/test-utils";
@@ -108,6 +108,25 @@ vi.mock("../common_components/AccessGroupSelector", () => ({
),
}));
+/* eslint-disable local/no-antd-class-selectors -- the "Key Type" and "Models" Form.Items wrap a noStyle nested item, so antd renders a label with no associated control and there is no accessible query for these selects */
+const antdSelectorFor = (label: HTMLElement): Element =>
+ label.closest(".ant-form-item")!.querySelector(".ant-select-selector")!;
+/* eslint-enable local/no-antd-class-selectors */
+
+const visibleOptions = (): HTMLElement[] =>
+ // eslint-disable-next-line local/no-antd-class-selectors -- antd puts role="option" only on a hidden mirror list; the visible, clickable options carry no role or accessible name
+ Array.from(document.querySelectorAll<HTMLElement>(".ant-select-item-option"));
+
+const isOptionDisabled = (option: HTMLElement): boolean =>
+ // eslint-disable-next-line local/no-antd-class-selectors -- antd signals option disabled state only through this class; the rendered options carry no aria-disabled
+ option.classList.contains("ant-select-item-option-disabled");
+
+const optionByContent = (label: string): HTMLElement | undefined =>
+ visibleOptions().find(
+ // eslint-disable-next-line local/no-antd-class-selectors -- the option's own label text lives in this child node, with no accessible equivalent
+ (el) => el.querySelector(".ant-select-item-option-content")?.textContent === label,
+ );
+
describe("KeyEditView", () => {
const MOCK_KEY_DATA: KeyResponse = {
token: "test-token-123",
@@ -879,10 +898,7 @@ describe("KeyEditView", () => {
/>,
);
- const resetBudgetItem = (await screen.findByText("Reset Budget")).closest(".ant-form-item");
- expect(resetBudgetItem).not.toBeNull();
- const combobox = within(resetBudgetItem as HTMLElement).getByRole("combobox");
- await userEvent.click(combobox);
+ await userEvent.click(await screen.findByLabelText("Reset Budget"));
const weeklyOption = await screen.findByText("weekly");
await userEvent.click(weeklyOption);
@@ -960,12 +976,12 @@ describe("KeyEditView", () => {
/>,
);
- const resetBudgetItem = (await screen.findByText("Reset Budget")).closest(".ant-form-item") as HTMLElement;
- await userEvent.click(within(resetBudgetItem).getByRole("combobox"));
+ const resetBudget = await screen.findByLabelText("Reset Budget");
+ await userEvent.click(resetBudget);
await userEvent.click(await screen.findByText("Never resets"));
await waitFor(() => {
- expect(within(resetBudgetItem).getByText("Never resets")).toBeInTheDocument();
+ expect(resetBudget).toHaveTextContent("Never resets");
});
await userEvent.click(screen.getByRole("button", { name: /save changes/i }));
@@ -993,8 +1009,7 @@ describe("KeyEditView", () => {
/>,
);
- const resetBudgetItem = (await screen.findByText("Reset Budget")).closest(".ant-form-item") as HTMLElement;
- await userEvent.click(within(resetBudgetItem).getByRole("combobox"));
+ await userEvent.click(await screen.findByLabelText("Reset Budget"));
await userEvent.click(await screen.findByText("Never resets"));
await userEvent.click(screen.getByRole("button", { name: /save changes/i }));
@@ -1149,17 +1164,11 @@ describe("KeyEditView", () => {
});
// The selected key type label should show "AI APIs" (not "LLM API")
- const keyTypeSection = screen.getByText("Key Type").closest(".ant-form-item")!;
- expect(keyTypeSection).toBeInTheDocument();
-
- // Open the dropdown to see all options
- const selectElement = keyTypeSection.querySelector(".ant-select-selector")!;
- await userEvent.click(selectElement);
+ await userEvent.click(antdSelectorFor(screen.getByText("Key Type")));
await waitFor(() => {
// Verify "AI APIs" appears as an option label
- const options = document.querySelectorAll(".ant-select-item-option");
- const optionTexts = Array.from(options).map((el) => el.textContent);
+ const optionTexts = visibleOptions().map((el) => el.textContent);
const hasAIAPIs = optionTexts.some((text) => text?.includes("AI APIs"));
expect(hasAIAPIs).toBe(true);
@@ -1251,8 +1260,7 @@ describe("KeyEditView", () => {
expect(screen.getByText("Organization")).toBeInTheDocument();
});
- const orgFormItem = screen.getByText("Organization").closest(".ant-form-item") as HTMLElement;
- await userEvent.click(within(orgFormItem).getByRole("combobox"));
+ await userEvent.click(screen.getByLabelText("Organization"));
expect(screen.queryByText("Engineering")).not.toBeInTheDocument();
});
@@ -1274,8 +1282,7 @@ describe("KeyEditView", () => {
expect(screen.getByText("Organization")).toBeInTheDocument();
});
- const orgFormItem = screen.getByText("Organization").closest(".ant-form-item") as HTMLElement;
- await userEvent.click(within(orgFormItem).getByRole("combobox"));
+ await userEvent.click(screen.getByLabelText("Organization"));
expect(await screen.findByText("Engineering")).toBeInTheDocument();
});
@@ -1298,19 +1305,15 @@ describe("KeyEditView", () => {
/>,
);
- const orgFormItem = (await screen.findByText("Organization")).closest(".ant-form-item") as HTMLElement;
await waitFor(() => {
- expect(within(orgFormItem).getByRole("combobox")).toHaveValue("Engineering");
+ expect(screen.getByLabelText("Organization")).toHaveValue("Engineering");
});
});
});
describe("models dropdown team gating", () => {
const openModelsDropdown = () => {
- const modelsFormItem = screen.getByText("Models", { selector: "label" }).closest(".ant-form-item");
- const selector = modelsFormItem?.querySelector(".ant-select-selector");
- expect(selector).toBeTruthy();
- fireEvent.mouseDown(selector as Element);
+ fireEvent.mouseDown(antdSelectorFor(screen.getByText("Models", { selector: "label" })));
};
it("should offer all-proxy-models but not all-team-models for a teamless key", async () => {
@@ -1456,9 +1459,7 @@ describe("KeyEditView", () => {
const clickOption = async (label: string) => {
const option = await waitFor(() => {
- const match = Array.from(document.querySelectorAll(".ant-select-item-option")).find(
- (el) => el.querySelector(".ant-select-item-option-content")?.textContent === label,
- );
+ const match = optionByContent(label);
expect(match).toBeTruthy();
return match as HTMLElement;
});
@@ -1495,17 +1496,14 @@ describe("KeyEditView", () => {
openModelsDropdown();
- const findOption = (label: string) =>
- Array.from(document.querySelectorAll(".ant-select-item-option")).find(
- (el) => el.querySelector(".ant-select-item-option-content")?.textContent === label,
- ) as HTMLElement | undefined;
+ const findOption = (label: string) => optionByContent(label);
const gpt4Before = await waitFor(() => {
const match = findOption("gpt-4");
expect(match).toBeTruthy();
return match!;
});
- expect(gpt4Before.classList.contains("ant-select-item-option-disabled")).toBe(false);
+ expect(isOptionDisabled(gpt4Before)).toBe(false);
fireEvent.click(
await waitFor(() => {
@@ -1516,7 +1514,7 @@ describe("KeyEditView", () => {
);
await waitFor(() => {
- expect(findOption("gpt-4")?.classList.contains("ant-select-item-option-disabled")).toBe(true);
+ expect(isOptionDisabled(findOption("gpt-4")!)).toBe(true);
});
});
});