Skip to content

Commit d21f387

Browse files
refactor (wip): failing tests which co-pilot cannot fix
1 parent 9189028 commit d21f387

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

src/web/src/__tests__/WSEditorClientConfig.test.tsx

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ describe("WSEditorClientConfigDialog", () => {
7171
expect(screen.getByText("Setup Client Config")).toBeInTheDocument();
7272
});
7373

74-
// Wait for loading to complete
7574
await waitFor(() => {
7675
expect(screen.queryByRole("progressbar")).not.toBeInTheDocument();
7776
});
@@ -94,7 +93,6 @@ describe("WSEditorClientConfigDialog", () => {
9493
expect(screen.getByText("Modify Client Config")).toBeInTheDocument();
9594
});
9695

97-
// Wait for loading to complete
9896
await waitFor(() => {
9997
expect(screen.queryByRole("progressbar")).not.toBeInTheDocument();
10098
});
@@ -122,15 +120,15 @@ describe("WSEditorClientConfigDialog", () => {
122120
expect(screen.getByText("By templates")).toBeInTheDocument();
123121
});
124122

125-
// Wait for loading to complete
126123
await waitFor(() => {
127124
expect(screen.queryByRole("progressbar")).not.toBeInTheDocument();
128125
});
129126

130127
const resourceTab = screen.getByText("By resource property");
131128
await user.click(resourceTab);
132129

133-
expect(screen.getByLabelText("Module")).toBeInTheDocument();
130+
const moduleInput = await screen.findByRole("combobox", { name: /Module/i });
131+
expect(moduleInput).toBeInTheDocument();
134132
});
135133

136134
it("should show loading indicator when updating", async () => {
@@ -159,7 +157,6 @@ describe("WSEditorClientConfigDialog", () => {
159157
expect(screen.getByText("Setup Client Config")).toBeInTheDocument();
160158
});
161159

162-
// Wait for loading to complete
163160
await waitFor(() => {
164161
expect(screen.queryByRole("progressbar")).not.toBeInTheDocument();
165162
});
@@ -176,39 +173,50 @@ describe("WSEditorClientConfigDialog", () => {
176173
const user = userEvent.setup();
177174
render(<WSEditorClientConfigDialog workspaceUrl={mockWorkspaceUrl} open={true} onClose={mockOnClose} />);
178175

179-
await waitFor(() => {
180-
expect(screen.getByLabelText("Azure Cloud")).toBeInTheDocument();
181-
});
176+
const templatesTab = screen.getByRole("tab", { name: /By templates/i });
177+
await user.click(templatesTab);
182178

183-
const azureCloudInput = screen.getByLabelText("Azure Cloud");
179+
const azureCloudInput = await screen.findByLabelText(/Azure Cloud/i);
180+
181+
await user.clear(azureCloudInput);
184182
await user.type(azureCloudInput, "invalid-url");
185183

186184
const updateButton = screen.getByText("Update");
187185
await user.click(updateButton);
188186

189-
await waitFor(() => {
190-
expect(screen.getByText("Azure Cloud Endpoint Template is invalid.")).toBeInTheDocument();
191-
});
187+
const errorMessage = await screen.findByText(/Azure Cloud Endpoint Template is invalid./i);
188+
expect(errorMessage).toBeInTheDocument();
192189
});
193190

194-
it("should validate AAD scopes are required", async () => {
191+
it("shows error when AAD scopes are empty", async () => {
192+
// Use 404 error to trigger new config setup mode
193+
(workspaceApi.getClientConfig as any).mockRejectedValue(new Error("404"));
194+
(errorHandlerApi.isHttpError as any).mockReturnValue(true);
195+
195196
const user = userEvent.setup();
196197
render(<WSEditorClientConfigDialog workspaceUrl={mockWorkspaceUrl} open={true} onClose={mockOnClose} />);
197198

198199
await waitFor(() => {
199-
expect(screen.getByLabelText("Azure Cloud")).toBeInTheDocument();
200+
expect(screen.getByText("Setup Client Config")).toBeInTheDocument();
200201
});
201202

203+
await waitFor(() => {
204+
expect(screen.queryByRole("progressbar")).not.toBeInTheDocument();
205+
});
206+
207+
// Provide a minimal template to pass template validation
202208
const azureCloudInput = screen.getByLabelText("Azure Cloud");
203-
await user.type(azureCloudInput, "https://{vaultName}.vault.azure.net");
209+
await user.type(azureCloudInput, "https://management.azure.com");
204210

205-
// Clear the default AAD scope
206-
const aadScopeInput = screen.getByPlaceholderText(/Input Microsoft Entra\(AAD\) auth Scope/);
207-
await user.clear(aadScopeInput);
211+
// Clear the AAD scope input (it should be rendered with one empty scope by default)
212+
const aadInput = screen.getByPlaceholderText(/Input Microsoft Entra\(AAD\) auth Scope here/i);
213+
await user.clear(aadInput);
208214

215+
// Click Update to trigger validation
209216
const updateButton = screen.getByText("Update");
210217
await user.click(updateButton);
211218

219+
// Should get the AAD scopes validation error
212220
await waitFor(() => {
213221
expect(screen.getByText("MS Entra(AAD) Auth Scopes is required.")).toBeInTheDocument();
214222
});

0 commit comments

Comments
 (0)