|
| 1 | +import React from "react" |
| 2 | + |
| 3 | +import { render, screen, fireEvent } from "@/utils/test-utils" |
| 4 | +import type { ProviderSettings } from "@roo-code/types" |
| 5 | + |
| 6 | +import { Novita } from "../Novita" |
| 7 | + |
| 8 | +vi.mock("@vscode/webview-ui-toolkit/react", () => ({ |
| 9 | + VSCodeTextField: ({ children, value, onInput, placeholder, type, className }: any) => ( |
| 10 | + <label className={className}> |
| 11 | + {children} |
| 12 | + <input |
| 13 | + type={type ?? "text"} |
| 14 | + value={value} |
| 15 | + onChange={(event) => onInput?.(event)} |
| 16 | + placeholder={placeholder} |
| 17 | + /> |
| 18 | + </label> |
| 19 | + ), |
| 20 | +})) |
| 21 | + |
| 22 | +vi.mock("@src/i18n/TranslationContext", () => ({ |
| 23 | + useAppTranslation: () => ({ |
| 24 | + t: (key: string) => key, |
| 25 | + }), |
| 26 | +})) |
| 27 | + |
| 28 | +vi.mock("@src/components/common/VSCodeButtonLink", () => ({ |
| 29 | + VSCodeButtonLink: ({ children, href }: any) => <a href={href}>{children}</a>, |
| 30 | +})) |
| 31 | + |
| 32 | +describe("Novita provider settings", () => { |
| 33 | + it("renders defaults and API key link when no key is configured", () => { |
| 34 | + render(<Novita apiConfiguration={{} as ProviderSettings} setApiConfigurationField={vi.fn()} />) |
| 35 | + |
| 36 | + expect(screen.getByLabelText("settings:providers.novitaBaseUrl")).toHaveValue("https://api.novita.ai/openai") |
| 37 | + expect(screen.getByLabelText("settings:providers.novitaApiKey")).toHaveValue("") |
| 38 | + expect(screen.getByRole("link", { name: "settings:providers.getNovitaApiKey" })).toHaveAttribute( |
| 39 | + "href", |
| 40 | + "https://novita.ai/settings/key-management", |
| 41 | + ) |
| 42 | + }) |
| 43 | + |
| 44 | + it("updates Novita provider fields", () => { |
| 45 | + const setApiConfigurationField = vi.fn() |
| 46 | + |
| 47 | + render( |
| 48 | + <Novita |
| 49 | + apiConfiguration={ |
| 50 | + { |
| 51 | + novitaBaseUrl: "https://api.novita.ai/openai", |
| 52 | + novitaApiKey: "existing-key", |
| 53 | + } as ProviderSettings |
| 54 | + } |
| 55 | + setApiConfigurationField={setApiConfigurationField} |
| 56 | + />, |
| 57 | + ) |
| 58 | + |
| 59 | + fireEvent.change(screen.getByLabelText("settings:providers.novitaBaseUrl"), { |
| 60 | + target: { value: "https://example.test/openai" }, |
| 61 | + }) |
| 62 | + fireEvent.change(screen.getByLabelText("settings:providers.novitaApiKey"), { |
| 63 | + target: { value: "new-key" }, |
| 64 | + }) |
| 65 | + |
| 66 | + expect(setApiConfigurationField).toHaveBeenCalledWith("novitaBaseUrl", "https://example.test/openai") |
| 67 | + expect(setApiConfigurationField).toHaveBeenCalledWith("novitaApiKey", "new-key") |
| 68 | + expect(screen.queryByRole("link", { name: "settings:providers.getNovitaApiKey" })).not.toBeInTheDocument() |
| 69 | + }) |
| 70 | +}) |
0 commit comments