mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-25 01:02:15 +00:00
test(ui): address review feedback
This commit is contained in:
parent
372a36aa75
commit
eb831d956c
4 changed files with 26 additions and 46 deletions
|
|
@ -46,11 +46,26 @@ export async function runWithCleanup(
|
|||
try {
|
||||
if (outcome.status === "failure") throw outcome.error;
|
||||
} finally {
|
||||
const cleanupSucceeded = await Promise.resolve()
|
||||
const cleanupOutcome = await Promise.resolve()
|
||||
.then(cleanup)
|
||||
.catch(() => false);
|
||||
if (outcome.status === "success" && !cleanupSucceeded) {
|
||||
throw new Error("Failed to clean up UI E2E resource");
|
||||
.then(
|
||||
(succeeded) =>
|
||||
succeeded
|
||||
? { status: "success" as const }
|
||||
: {
|
||||
status: "failure" as const,
|
||||
error: new Error("Failed to clean up UI E2E resource"),
|
||||
},
|
||||
(error: unknown) => ({ status: "failure" as const, error }),
|
||||
);
|
||||
if (cleanupOutcome.status === "failure") {
|
||||
if (outcome.status === "failure") {
|
||||
throw new AggregateError(
|
||||
[outcome.error, cleanupOutcome.error],
|
||||
"Action and cleanup failed",
|
||||
);
|
||||
}
|
||||
throw cleanupOutcome.error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ test.describe("Prompt upload form", () => {
|
|||
name: "e2e.prompt",
|
||||
mimeType: "text/plain",
|
||||
buffer: Buffer.from(
|
||||
`model: fake-openai-gpt-4\ntemplate: "${promptContent}"\n`,
|
||||
`---\nmodel: fake-openai-gpt-4\n---\n${promptContent}\n`,
|
||||
),
|
||||
});
|
||||
await expect(page.getByText("Selected: e2e.prompt")).toBeVisible();
|
||||
|
|
@ -58,7 +58,7 @@ test.describe("Prompt upload form", () => {
|
|||
};
|
||||
return promptInfo.raw_prompt_template?.content;
|
||||
})
|
||||
.toContain(promptContent);
|
||||
.toBe(promptContent);
|
||||
await expect(page.getByText(promptId, { exact: true })).toBeVisible();
|
||||
},
|
||||
async () => {
|
||||
|
|
|
|||
|
|
@ -31,10 +31,11 @@ test.describe("Tag management", () => {
|
|||
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const response = await readBack<
|
||||
Record<string, Record<string, unknown>>
|
||||
>(page, "/tag/list");
|
||||
return Object.values(response).some((tag) => tag.name === tagName);
|
||||
const response = await readBack<Array<{ name: string }>>(
|
||||
page,
|
||||
"/tag/list",
|
||||
);
|
||||
return response.some((tag) => tag.name === tagName);
|
||||
})
|
||||
.toBe(true);
|
||||
await expect(page.getByText(tagName, { exact: true })).toBeVisible();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { fireEvent, renderWithProviders as render, screen, waitFor } from "../../../tests/test-utils";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useState } from "react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
|
|
@ -407,39 +406,4 @@ describe("PaginatedSearchSelect", () => {
|
|||
expect(input).toHaveValue("aliasalpha");
|
||||
await waitFor(() => expect(onSearchChange).toHaveBeenLastCalledWith("aliasalpha"));
|
||||
});
|
||||
|
||||
it("keeps the latest query results when an earlier response resolves last", async () => {
|
||||
const pending = new Map<string, (options: SearchSelectOption[]) => void>();
|
||||
|
||||
function QueryBackedSelect() {
|
||||
const [query, setQuery] = useState("");
|
||||
const result = useQuery({
|
||||
queryKey: ["paginated-select-race", query],
|
||||
queryFn: () =>
|
||||
new Promise<SearchSelectOption[]>((resolve) => {
|
||||
pending.set(query, resolve);
|
||||
}),
|
||||
enabled: query.length > 0,
|
||||
});
|
||||
return <PaginatedSearchSelect options={result.data ?? []} onValueChange={vi.fn()} onSearchChange={setQuery} />;
|
||||
}
|
||||
|
||||
const user = userEvent.setup();
|
||||
render(<QueryBackedSelect />);
|
||||
const input = screen.getByRole("combobox");
|
||||
await user.click(input);
|
||||
await user.type(input, "A");
|
||||
await waitFor(() => expect(pending.has("A")).toBe(true));
|
||||
await user.clear(input);
|
||||
await user.type(input, "B");
|
||||
await waitFor(() => expect(pending.has("B")).toBe(true));
|
||||
|
||||
pending.get("B")?.([{ label: "B result", value: "b" }]);
|
||||
await user.click(screen.getByRole("combobox"));
|
||||
expect(await screen.findByText("B result")).toBeInTheDocument();
|
||||
|
||||
pending.get("A")?.([{ label: "A result", value: "a" }]);
|
||||
await waitFor(() => expect(screen.queryByText("A result")).not.toBeInTheDocument());
|
||||
expect(screen.getByText("B result")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue