mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-11 03:38:38 +00:00
test(ui): cover user rate limit seed and saved state
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
7b238d79c3
commit
88195a49ce
2 changed files with 50 additions and 4 deletions
|
|
@ -464,7 +464,7 @@ describe("UserEditView", () => {
|
|||
user_info: {
|
||||
...MOCK_USER_DATA.user_info,
|
||||
tpm_limit: 100000,
|
||||
rpm_limit: null,
|
||||
rpm_limit: 50,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -472,7 +472,30 @@ describe("UserEditView", () => {
|
|||
renderWithProviders(<UserEditView {...defaultProps} userData={userDataWithRateLimits()} />);
|
||||
|
||||
expect(await screen.findByRole("spinbutton", { name: /tpm limit/i })).toHaveValue(100000);
|
||||
expect(await screen.findByRole("spinbutton", { name: /rpm limit/i })).toHaveValue(50);
|
||||
});
|
||||
|
||||
it("keeps unset rate limits empty and omits them from an untouched save", async () => {
|
||||
const onSubmit = vi.fn();
|
||||
const userDataWithNullRateLimits = {
|
||||
...MOCK_USER_DATA,
|
||||
user_info: {
|
||||
...MOCK_USER_DATA.user_info,
|
||||
tpm_limit: null,
|
||||
rpm_limit: null,
|
||||
},
|
||||
};
|
||||
renderWithProviders(<UserEditView {...defaultProps} userData={userDataWithNullRateLimits} onSubmit={onSubmit} />);
|
||||
|
||||
expect(await screen.findByRole("spinbutton", { name: /tpm limit/i })).toHaveValue(null);
|
||||
expect(await screen.findByRole("spinbutton", { name: /rpm limit/i })).toHaveValue(null);
|
||||
await userEvent.click(screen.getByRole("button", { name: /save changes/i }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(onSubmit).toHaveBeenCalled();
|
||||
});
|
||||
expect(onSubmit.mock.calls[0][0]).not.toHaveProperty("tpm_limit");
|
||||
expect(onSubmit.mock.calls[0][0]).not.toHaveProperty("rpm_limit");
|
||||
});
|
||||
|
||||
it("omits unchanged rate limits from the submit payload", async () => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { render, screen, waitFor, within } from "@testing-library/react";
|
||||
import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, expect, it, vi, beforeEach } from "vitest";
|
||||
import UserInfoView from "./user_info_view";
|
||||
|
|
@ -134,13 +134,36 @@ describe("UserInfoView", () => {
|
|||
mockUserGetInfoV2.mockResolvedValue({
|
||||
...MOCK_USER_DATA,
|
||||
tpm_limit: 100000,
|
||||
rpm_limit: null,
|
||||
rpm_limit: 50,
|
||||
});
|
||||
|
||||
render(<UserInfoView {...defaultProps} userRole="proxy_admin" initialTab={1} startInEditMode />);
|
||||
|
||||
expect(await screen.findByRole("spinbutton", { name: /tpm limit/i })).toHaveValue(100000);
|
||||
expect(await screen.findByRole("spinbutton", { name: /rpm limit/i })).toHaveValue(null);
|
||||
expect(await screen.findByRole("spinbutton", { name: /rpm limit/i })).toHaveValue(50);
|
||||
});
|
||||
|
||||
it("keeps the updated TPM and stored RPM when reopening the edit form", async () => {
|
||||
mockUserGetInfoV2.mockResolvedValue({
|
||||
...MOCK_USER_DATA,
|
||||
tpm_limit: 100000,
|
||||
rpm_limit: 50,
|
||||
});
|
||||
|
||||
render(<UserInfoView {...defaultProps} userRole="proxy_admin" initialTab={1} startInEditMode />);
|
||||
|
||||
fireEvent.change(await screen.findByRole("spinbutton", { name: /tpm limit/i }), {
|
||||
target: { value: "" },
|
||||
});
|
||||
await userEvent.click(screen.getByRole("button", { name: /save changes/i }));
|
||||
await waitFor(() => {
|
||||
expect(mockUserUpdateUserCall).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
await userEvent.click(await screen.findByRole("button", { name: /edit settings/i }));
|
||||
|
||||
expect(await screen.findByRole("spinbutton", { name: /tpm limit/i })).toHaveValue(null);
|
||||
expect(await screen.findByRole("spinbutton", { name: /rpm limit/i })).toHaveValue(50);
|
||||
});
|
||||
|
||||
it("should render overview spend and budget with two decimal places", async () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue