|
1 | 1 | import { render, screen, waitFor } from "@testing-library/react"; |
2 | 2 | import userEvent from "@testing-library/user-event"; |
3 | | -import type { ComponentType } from "react"; |
| 3 | +import { useState, type ComponentType } from "react"; |
4 | 4 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
5 | 5 | import { getModelProviders } from "@/features/providers/providerCatalog"; |
6 | 6 | import { ModelProviderRow } from "../ModelProviderRow"; |
@@ -110,4 +110,59 @@ describe("ModelProviderRow", () => { |
110 | 110 |
|
111 | 111 | expect(screen.getByText(/model refresh failed/i)).toBeInTheDocument(); |
112 | 112 | }); |
| 113 | + |
| 114 | + it("switches from setup save to connected controls after first configuration", async () => { |
| 115 | + const user = userEvent.setup(); |
| 116 | + let saved = false; |
| 117 | + |
| 118 | + function SetupSaveRow() { |
| 119 | + const [status, setStatus] = useState<"connected" | "not_configured">( |
| 120 | + "not_configured", |
| 121 | + ); |
| 122 | + |
| 123 | + return ( |
| 124 | + <ModelProviderRow |
| 125 | + provider={modelProvider("google", status)} |
| 126 | + onGetConfig={async () => |
| 127 | + saved |
| 128 | + ? [ |
| 129 | + { |
| 130 | + key: "GOOGLE_API_KEY", |
| 131 | + value: null, |
| 132 | + isSet: true, |
| 133 | + isSecret: true, |
| 134 | + required: true, |
| 135 | + }, |
| 136 | + ] |
| 137 | + : [] |
| 138 | + } |
| 139 | + onSaveFields={async () => { |
| 140 | + saved = true; |
| 141 | + setStatus("connected"); |
| 142 | + }} |
| 143 | + onRemoveConfig={onRemoveConfig} |
| 144 | + onCompleteNativeSetup={onCompleteNativeSetup} |
| 145 | + /> |
| 146 | + ); |
| 147 | + } |
| 148 | + |
| 149 | + render(<SetupSaveRow />); |
| 150 | + |
| 151 | + await user.click(screen.getByRole("button", { name: /google gemini/i })); |
| 152 | + await user.type( |
| 153 | + await screen.findByPlaceholderText(/paste your api key/i), |
| 154 | + "google-token", |
| 155 | + ); |
| 156 | + await user.click(screen.getByRole("button", { name: /^save$/i })); |
| 157 | + |
| 158 | + await waitFor(() => |
| 159 | + expect( |
| 160 | + screen.getByRole("button", { name: /disconnect/i }), |
| 161 | + ).toBeInTheDocument(), |
| 162 | + ); |
| 163 | + expect(screen.getByRole("button", { name: /edit/i })).toBeInTheDocument(); |
| 164 | + expect( |
| 165 | + screen.queryByRole("button", { name: /saved/i }), |
| 166 | + ).not.toBeInTheDocument(); |
| 167 | + }); |
113 | 168 | }); |
0 commit comments