diff --git a/tests/integration/App.test.tsx b/tests/integration/App.test.tsx index 14f8439da..76fd3c253 100644 --- a/tests/integration/App.test.tsx +++ b/tests/integration/App.test.tsx @@ -2,7 +2,11 @@ import { Suspense, type ComponentType } from "react"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { render, screen, waitFor, fireEvent } from "@testing-library/react"; import { describe, it, expect, beforeEach, vi } from "vitest"; -import { resetProviderState } from "../msw/state"; +import { + resetProviderState, + setCurrentProviderId, + setProviders, +} from "../msw/state"; import { emitTauriEvent } from "../msw/tauriMocks"; const toastSuccessMock = vi.fn(); @@ -75,8 +79,11 @@ vi.mock("@/components/providers/EditProviderDialog", () => ({ + ), })); @@ -230,4 +238,46 @@ describe("App integration with MSW", () => { expect(toastErrorMock).toHaveBeenCalled(); }); }); + + it("duplicates openclaw providers with a generated provider key", async () => { + setProviders("openclaw", { + deepseek: { + id: "deepseek", + name: "DeepSeek", + settingsConfig: { + baseUrl: "https://api.deepseek.com", + apiKey: "test-key", + api: "openai-completions", + models: [], + }, + category: "custom", + sortIndex: 0, + createdAt: Date.now(), + }, + }); + setCurrentProviderId("openclaw", "deepseek"); + + const { default: App } = await import("@/App"); + renderApp(App); + + fireEvent.click(screen.getByText("switch-openclaw")); + + await waitFor(() => + expect(screen.getByTestId("provider-list").textContent).toContain( + "deepseek", + ), + ); + + fireEvent.click(screen.getByText("duplicate")); + + await waitFor(() => { + const providerList = screen.getByTestId("provider-list").textContent; + expect(providerList).toContain("deepseek-copy"); + expect(providerList).toContain("DeepSeek copy"); + }); + + expect(toastErrorMock).not.toHaveBeenCalledWith( + expect.stringContaining("Provider key is required for openclaw"), + ); + }); }); diff --git a/tests/msw/handlers.ts b/tests/msw/handlers.ts index 5867b1edf..3bd410bc3 100644 --- a/tests/msw/handlers.ts +++ b/tests/msw/handlers.ts @@ -67,6 +67,16 @@ export const handlers = [ http.post(`${TAURI_ENDPOINT}/update_tray_menu`, () => success(true)), + http.post(`${TAURI_ENDPOINT}/get_openclaw_live_provider_ids`, () => + success([]), + ), + + http.post(`${TAURI_ENDPOINT}/get_openclaw_default_model`, () => + success({ primary: null, fallback: [] }), + ), + + http.post(`${TAURI_ENDPOINT}/scan_openclaw_config_health`, () => success([])), + http.post(`${TAURI_ENDPOINT}/switch_provider`, async ({ request }) => { const { id, app } = await withJson<{ id: string; app: AppId }>(request); const providers = listProviders(app); @@ -174,6 +184,8 @@ export const handlers = [ http.post(`${TAURI_ENDPOINT}/get_settings`, () => success(getSettings())), + http.post(`${TAURI_ENDPOINT}/check_env_conflicts`, () => success([])), + http.post(`${TAURI_ENDPOINT}/save_settings`, async ({ request }) => { const { settings } = await withJson<{ settings: Settings }>(request); setSettings(settings);