mirror of
https://github.com/BerriAI/litellm.git
synced 2026-08-28 05:25:59 +00:00
test(ui): cover the loading state while a newer user search is in flight
This commit is contained in:
parent
4606ea3f12
commit
81c975cff8
2 changed files with 53 additions and 0 deletions
|
|
@ -271,4 +271,25 @@ describe("UserSearchModal out-of-order search results", () => {
|
|||
expect(screen.queryByRole("option")).not.toBeInTheDocument();
|
||||
expect(screen.getByText("No results")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps loading while a newer search is still in flight", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<UserSearchModal isVisible onCancel={vi.fn()} onSubmit={vi.fn()} accessToken="sk-test" />);
|
||||
|
||||
const input = getEmailSearchInput();
|
||||
await user.click(input);
|
||||
await user.type(input, "ali");
|
||||
await waitFor(() => expect(answers.has("ali")).toBe(true), { timeout: 3000 });
|
||||
|
||||
await user.type(input, "ce.smith@example.com");
|
||||
await waitFor(() => expect(answers.has("alice.smith@example.com")).toBe(true), { timeout: 3000 });
|
||||
|
||||
await answerFor("ali", []);
|
||||
|
||||
expect(screen.getByText("Loading...")).toBeInTheDocument();
|
||||
expect(screen.queryByText("No results")).not.toBeInTheDocument();
|
||||
|
||||
await answerFor("alice.smith@example.com", [{ user_id: "u-smith", user_email: "alice.smith@example.com" }]);
|
||||
await screen.findByRole("option", { name: "alice.smith@example.com" });
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -863,6 +863,38 @@ describe("CreateKey", () => {
|
|||
expect(screen.queryByTitle("alice.jones@example.com (u-jones)")).not.toBeInTheDocument();
|
||||
expect(screen.getByText("No users found")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps searching while a newer search is still in flight", async () => {
|
||||
const answers = new Map<string, (users: { user_id: string; user_email: string }[]) => void>();
|
||||
vi.mocked(userFilterUICall).mockImplementation(
|
||||
(_accessToken, params) =>
|
||||
new Promise((resolve) => {
|
||||
answers.set(params.get("user_email") ?? "", resolve);
|
||||
}) as never,
|
||||
);
|
||||
|
||||
const user = userEvent.setup();
|
||||
renderCreateKey({ autoOpenCreate: true, prefillData: { owned_by: "another_user" } });
|
||||
const search = antdSearchInput(await screen.findByText("Type email to search for users"));
|
||||
|
||||
await user.type(search, "ali");
|
||||
await waitFor(() => expect(answers.has("ali")).toBe(true), { timeout: 3000 });
|
||||
|
||||
await user.type(search, "ce.smith@example.com");
|
||||
await waitFor(() => expect(answers.has("alice.smith@example.com")).toBe(true), { timeout: 3000 });
|
||||
|
||||
await act(async () => {
|
||||
answers.get("ali")?.([]);
|
||||
});
|
||||
|
||||
expect(screen.getByText("Searching...")).toBeInTheDocument();
|
||||
expect(screen.queryByText("No users found")).not.toBeInTheDocument();
|
||||
|
||||
await act(async () => {
|
||||
answers.get("alice.smith@example.com")?.([{ user_id: "u-smith", user_email: "alice.smith@example.com" }]);
|
||||
});
|
||||
await screen.findByTitle("alice.smith@example.com (u-smith)");
|
||||
});
|
||||
});
|
||||
|
||||
describe("created key display", () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue