mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
address greptile review feedback (greploop iteration 1)
- Replace document.querySelector/querySelectorAll with screen.getByRole - Replace raw dispatchEvent with userEvent.selectOptions
This commit is contained in:
parent
0e8b5616d6
commit
1fb5c496c8
4 changed files with 11 additions and 18 deletions
|
|
@ -47,8 +47,7 @@ describe("LatencyBasedConfiguration", () => {
|
|||
const args = { ttl: { nested: true } };
|
||||
render(<LatencyBasedConfiguration routingStrategyArgs={args} />);
|
||||
// HTML input type=text strips newlines, so check that the key/value appears
|
||||
const input = document.querySelector('input[name="ttl"]') as HTMLInputElement;
|
||||
expect(input).not.toBeNull();
|
||||
const input = screen.getByRole("textbox", { name: /ttl/i }) as HTMLInputElement;
|
||||
expect(input.value).toContain('"nested"');
|
||||
expect(input.value).toContain('true');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -67,8 +67,7 @@ describe("ReliabilityRetriesSection", () => {
|
|||
const settings = { retry_policy: { "rate-limited": 2 } };
|
||||
render(<ReliabilityRetriesSection routerSettings={settings} routerFieldsMetadata={{}} />);
|
||||
// HTML input type=text strips newlines, so check that the key/value appears
|
||||
const input = document.querySelector('input[name="retry_policy"]') as HTMLInputElement;
|
||||
expect(input).not.toBeNull();
|
||||
const input = screen.getByRole("textbox", { name: /retry_policy/i }) as HTMLInputElement;
|
||||
expect(input.value).toContain('"rate-limited"');
|
||||
expect(input.value).toContain('2');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -97,8 +97,9 @@ describe("RouterSettingsForm", () => {
|
|||
expect(screen.getByText("Latency-Based Configuration")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should call onChange with the updated strategy when the selector changes", () => {
|
||||
it("should call onChange with the updated strategy when the selector changes", async () => {
|
||||
const onChange = vi.fn();
|
||||
const user = userEvent.setup();
|
||||
const props = {
|
||||
...baseProps,
|
||||
onChange,
|
||||
|
|
@ -106,9 +107,7 @@ describe("RouterSettingsForm", () => {
|
|||
};
|
||||
render(<RouterSettingsForm {...props} />);
|
||||
|
||||
const select = screen.getByTestId("strategy-select") as HTMLSelectElement;
|
||||
select.value = "latency-based-routing";
|
||||
select.dispatchEvent(new Event("change", { bubbles: true }));
|
||||
await user.selectOptions(screen.getByTestId("strategy-select"), "latency-based-routing");
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ selectedStrategy: "latency-based-routing" })
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { describe, it, expect, vi } from "vitest";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import RoutingStrategySelector from "./RoutingStrategySelector";
|
||||
|
||||
// Ant Design's Select is complex to drive in JSDOM; swap it for a plain
|
||||
|
|
@ -77,21 +78,16 @@ describe("RoutingStrategySelector", () => {
|
|||
|
||||
it("should not render a description for a strategy that has none", () => {
|
||||
render(<RoutingStrategySelector {...baseProps} />);
|
||||
// "least-busy" has no entry in routingStrategyDescriptions
|
||||
const select = screen.getByTestId("strategy-select");
|
||||
const leastBusyOption = Array.from(select.querySelectorAll("option")).find(
|
||||
(o) => o.value === "least-busy"
|
||||
);
|
||||
expect(leastBusyOption).toBeInTheDocument();
|
||||
// "least-busy" has no entry in routingStrategyDescriptions — it still renders without crashing
|
||||
expect(screen.getByText("least-busy")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should call onStrategyChange with the selected strategy value", () => {
|
||||
it("should call onStrategyChange with the selected strategy value", async () => {
|
||||
const onStrategyChange = vi.fn();
|
||||
const user = userEvent.setup();
|
||||
render(<RoutingStrategySelector {...baseProps} onStrategyChange={onStrategyChange} />);
|
||||
|
||||
const select = screen.getByTestId("strategy-select") as HTMLSelectElement;
|
||||
select.value = "latency-based-routing";
|
||||
select.dispatchEvent(new Event("change", { bubbles: true }));
|
||||
await user.selectOptions(screen.getByTestId("strategy-select"), "latency-based-routing");
|
||||
|
||||
expect(onStrategyChange).toHaveBeenCalledWith("latency-based-routing");
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue