mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-03 02:22:24 +00:00
chore(ui): repair failing vitest tests after shadcn migration (batch B)
Co-authored-by: yuneng-jiang <yuneng-berri@users.noreply.github.com>
This commit is contained in:
parent
664e3ff98f
commit
88ca3562a9
6 changed files with 43 additions and 44 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { render, screen, fireEvent } from "@testing-library/react";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import GuardrailsPanel from "./guardrails";
|
||||
import { getGuardrailsList } from "./networking";
|
||||
|
|
@ -101,10 +102,13 @@ describe("GuardrailsPanel", () => {
|
|||
});
|
||||
|
||||
it("should render the component", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<GuardrailsPanel {...defaultProps} />);
|
||||
expect(screen.getByText("Guardrails")).toBeInTheDocument();
|
||||
expect(screen.getByRole("tab", { name: "Guardrails" })).toBeInTheDocument();
|
||||
// Activate the Guardrails tab so its content (including the Add button) is rendered
|
||||
fireEvent.click(screen.getByText("Guardrails"));
|
||||
expect(screen.getByText("+ Add New Guardrail")).toBeInTheDocument();
|
||||
await user.click(screen.getByRole("tab", { name: "Guardrails" }));
|
||||
expect(
|
||||
await screen.findByRole("button", { name: /\+ Add New Guardrail/i }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -120,8 +120,8 @@ describe("Guardrail Info", () => {
|
|||
expect(getByText("Guardrail Settings")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
// Find the info icon and hover over it
|
||||
const infoIcon = container.querySelector(".anticon-info-circle");
|
||||
// Find the info icon (lucide Info svg) and hover over it
|
||||
const infoIcon = container.querySelector(".lucide-info");
|
||||
expect(infoIcon).toBeInTheDocument();
|
||||
|
||||
if (infoIcon) {
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ describe("TeamMembersComponent", () => {
|
|||
renderWithProviders(
|
||||
<TeamMembersComponent
|
||||
teamData={createMockTeamData()}
|
||||
canEditTeam={false}
|
||||
canEditTeam={true}
|
||||
handleMemberDelete={mockHandleMemberDelete}
|
||||
setSelectedEditMember={mockSetSelectedEditMember}
|
||||
setIsEditMemberModalVisible={mockSetIsEditMemberModalVisible}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import * as networking from "@/components/networking";
|
||||
import { act, fireEvent, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { renderWithProviders } from "../../../tests/test-utils";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import MemberPermissions from "./member_permissions";
|
||||
|
|
@ -69,32 +70,30 @@ describe("MemberPermissions", () => {
|
|||
expect(screen.getByText("Member Permissions")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
const user = userEvent.setup();
|
||||
const checkboxes = screen.getAllByRole("checkbox");
|
||||
const unselectedCheckbox = checkboxes.find((cb) => !(cb as HTMLInputElement).checked);
|
||||
const unselectedCheckbox = checkboxes.find(
|
||||
(cb) => cb.getAttribute("aria-checked") === "false",
|
||||
);
|
||||
expect(unselectedCheckbox).toBeDefined();
|
||||
|
||||
if (unselectedCheckbox) {
|
||||
await act(async () => {
|
||||
fireEvent.click(unselectedCheckbox);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
const saveButton = screen.getByRole("button", { name: /save changes/i });
|
||||
expect(saveButton).toBeInTheDocument();
|
||||
});
|
||||
await user.click(unselectedCheckbox!);
|
||||
|
||||
await waitFor(() => {
|
||||
const saveButton = screen.getByRole("button", { name: /save changes/i });
|
||||
await act(async () => {
|
||||
fireEvent.click(saveButton);
|
||||
});
|
||||
expect(saveButton).toBeInTheDocument();
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(networking.teamPermissionsUpdateCall).toHaveBeenCalledWith(
|
||||
"token-123",
|
||||
"team-123",
|
||||
expect.arrayContaining(["/key/generate", "/key/list"]),
|
||||
);
|
||||
});
|
||||
}
|
||||
const saveButton = screen.getByRole("button", { name: /save changes/i });
|
||||
await user.click(saveButton);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(networking.teamPermissionsUpdateCall).toHaveBeenCalledWith(
|
||||
"token-123",
|
||||
"team-123",
|
||||
expect.arrayContaining(["/key/generate", "/key/list"]),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("should render team daily activity permission with correct method and description", async () => {
|
||||
|
|
|
|||
|
|
@ -112,10 +112,9 @@ describe("InputCard", () => {
|
|||
render(<InputCard messages={messages} />);
|
||||
|
||||
const copyButtons = screen.getAllByRole("button");
|
||||
const copyButton = copyButtons.find((button) => {
|
||||
const icon = button.querySelector('[aria-label="copy"]');
|
||||
return icon !== null;
|
||||
});
|
||||
const copyButton = copyButtons.find((button) =>
|
||||
button.querySelector(".lucide-copy"),
|
||||
);
|
||||
|
||||
expect(copyButton).toBeInTheDocument();
|
||||
|
||||
|
|
@ -210,10 +209,9 @@ describe("InputCard", () => {
|
|||
];
|
||||
render(<InputCard messages={messages} />);
|
||||
const copyButtons = screen.getAllByRole("button");
|
||||
const copyButton = copyButtons.find((button) => {
|
||||
const icon = button.querySelector('[aria-label="copy"]');
|
||||
return icon !== null;
|
||||
});
|
||||
const copyButton = copyButtons.find((button) =>
|
||||
button.querySelector(".lucide-copy"),
|
||||
);
|
||||
expect(copyButton).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -67,10 +67,9 @@ describe("OutputCard", () => {
|
|||
render(<OutputCard message={mockMessage} />);
|
||||
|
||||
const copyButtons = screen.getAllByRole("button");
|
||||
const copyButton = copyButtons.find((button) => {
|
||||
const icon = button.querySelector('[aria-label="copy"]');
|
||||
return icon !== null;
|
||||
});
|
||||
const copyButton = copyButtons.find((button) =>
|
||||
button.querySelector(".lucide-copy"),
|
||||
);
|
||||
|
||||
expect(copyButton).toBeInTheDocument();
|
||||
|
||||
|
|
@ -89,10 +88,9 @@ describe("OutputCard", () => {
|
|||
render(<OutputCard message={null} />);
|
||||
|
||||
const copyButtons = screen.getAllByRole("button");
|
||||
const copyButton = copyButtons.find((button) => {
|
||||
const icon = button.querySelector('[aria-label="copy"]');
|
||||
return icon !== null;
|
||||
});
|
||||
const copyButton = copyButtons.find((button) =>
|
||||
button.querySelector(".lucide-copy"),
|
||||
);
|
||||
|
||||
expect(copyButton).toBeInTheDocument();
|
||||
await user.click(copyButton!);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue