The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
feat: extract OnboardingFormBody component with tests
yuneng-jiang087349427035
diff --git a/ui/litellm-dashboard/src/app/onboarding/OnboardingFormBody.test.tsx b/ui/litellm-dashboard/src/app/onboarding/OnboardingFormBody.test.tsxnew file mode 100644index 00000000000..40201aab3aa--- /dev/null+++ b/ui/litellm-dashboard/src/app/onboarding/OnboardingFormBody.test.tsx@@ -0,0 +1,89 @@+import React from "react";+import { render, screen, waitFor } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import { describe, it, expect, vi, beforeEach } from "vitest";+import { OnboardingFormBody } from "./OnboardingFormBody";++const defaultProps = {+ variant: "signup" as const,+ userEmail: "[email protected]",+ isPending: false,+ claimError: null,+ onSubmit: vi.fn(),+};++describe("OnboardingFormBody", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ });++ it("shows 'Sign Up' heading for signup variant", () => {+ render(<OnboardingFormBody {...defaultProps} />);+ expect(screen.getByRole("heading", { name: "Sign Up" })).toBeInTheDocument();+ });++ it("shows 'Reset Password' heading for reset_password variant", () => {+ render(<OnboardingFormBody {...defaultProps} variant="reset_password" />);+ expect(screen.getByRole("heading", { name: "Reset Password" })).toBeInTheDocument();+ });++ it("shows SSO alert for signup variant", () => {+ render(<OnboardingFormBody {...defaultProps} />);+ expect(screen.getByText("SSO")).toBeInTheDocument();+ });++ it("hides SSO alert for reset_password variant", () => {+ render(<OnboardingFormBody {...defaultProps} variant="reset_password" />);+ expect(screen.queryByText("SSO")).not.toBeInTheDocument();+ });++ it("pre-fills the email field with userEmail", async () => {+ render(<OnboardingFormBody {...defaultProps} userEmail="[email protected]" />);+ await waitFor(() => {+ expect(screen.getByLabelText("Email Address")).toHaveValue("[email protected]");+ });+ });++ it("disables the email field", () => {+ render(<OnboardingFormBody {...defaultProps} />);+ expect(screen.getByLabelText("Email Address")).toBeDisabled();+ });++ it("shows claimError message when claimError is set", () => {+ render(<OnboardingFormBody {...defaultProps} claimError="Something went wrong" />);+ expect(screen.getByText("Something went wrong")).toBeInTheDocument();+ });++ it("does not show claimError message when claimError is null", () => {+ render(<OnboardingFormBody {...defaultProps} claimError={null} />);+ expect(screen.queryByText("Something went wrong")).not.toBeInTheDocument();+ });++ it("shows a loading indicator on the submit button when isPending is true", () => {+ render(<OnboardingFormBody {...defaultProps} isPending={true} />);+ // antd Button with loading={true} adds .ant-btn-loading class+ expect(document.querySelector(".ant-btn-loading")).toBeInTheDocument();+ });++ it("calls onSubmit with the typed password on form submit", async () => {+ const user = userEvent.setup();+ const onSubmit = vi.fn();+ render(<OnboardingFormBody {...defaultProps} onSubmit={onSubmit} />);++ await user.type(screen.getByLabelText("Password"), "mypassword");+ await user.click(screen.getByRole("button", { name: /sign up/i }));++ await waitFor(() => {+ expect(onSubmit).toHaveBeenCalledWith(+ expect.objectContaining({ password: "mypassword" })+ );+ });+ });++ it("shows 'Reset Password' on the submit button for reset_password variant", () => {+ render(<OnboardingFormBody {...defaultProps} variant="reset_password" />);+ expect(+ screen.getByRole("button", { name: /reset password/i })+ ).toBeInTheDocument();+ });+});diff --git a/ui/litellm-dashboard/src/app/onboarding/OnboardingFormBody.tsx b/ui/litellm-dashboard/src/app/onboarding/OnboardingFormBody.tsxnew file mode 100644index 00000000000..69abe4ffbf3--- /dev/null+++ b/ui/litellm-dashboard/src/app/onboarding/OnboardingFormBody.tsx@@ -0,0 +1,93 @@+import React from "react";+import { Alert, Button, Card, Form, Input, Typography } from "antd";++type OnboardingFormBodyProps = {+ variant: "signup" | "reset_password";+ userEmail: string;+ isPending: boolean;+ claimError: string | null;+ onSubmit: (values: { password: string }) => void;+};++export function OnboardingFormBody({+ variant,+ userEmail,+ isPending,+ claimError,+ onSubmit,+}: OnboardingFormBodyProps) {+ const [form] = Form.useForm();++ React.useEffect(() => {+ if (userEmail) form.setFieldValue("user_email", userEmail);+ }, [userEmail, form]);++ return (+ <div className="mx-auto w-full max-w-md mt-10">+ <Card>+ <Typography.Title level={5} className="text-center mb-5">+ 🚅 LiteLLM+ </Typography.Title>+ <Typography.Title level={3}>+ {variant === "reset_password" ? "Reset Password" : "Sign Up"}+ </Typography.Title>+ <Typography.Text>+ {variant === "reset_password"+ ? "Reset your password to access Admin UI."+ : "Claim your user account to login to Admin UI."}+ </Typography.Text>++ {variant === "signup" && (+ <Alert+ className="mt-4"+ type="info"+ message="SSO"+ description={+ <div className="flex justify-between items-center">+ <span>SSO is under the Enterprise Tier.</span>+ <Button+ type="primary"+ size="small"+ href="https://forms.gle/W3U4PZpJGFHWtHyA9"+ target="_blank"+ >+ Get Free Trial+ </Button>+ </div>+ }+ showIcon+ />+ )}++ <Form className="mt-10 mb-5" layout="vertical" form={form} onFinish={onSubmit}>+ <Form.Item label="Email Address" name="user_email">+ <Input type="email" disabled />+ </Form.Item>++ <Form.Item+ label="Password"+ name="password"+ rules={[{ required: true, message: "password required to sign up" }]}+ help={+ variant === "reset_password"+ ? "Enter your new password"+ : "Create a password for your account"+ }+ >+ <Input.Password />+ </Form.Item>++ {claimError && (+ <Alert type="error" message={claimError} showIcon className="mb-4" />+ )}++ <div className="mt-10">+ <Button htmlType="submit" loading={isPending}>+ {variant === "reset_password" ? "Reset Password" : "Sign Up"}+ </Button>+ </div>+ </Form>+ </Card>+ </div>+ );+}