@@ -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 : / M o d u l e / 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 : / B y t e m p l a t e s / i } ) ;
177+ await user . click ( templatesTab ) ;
182178
183- const azureCloudInput = screen . getByLabelText ( "Azure Cloud" ) ;
179+ const azureCloudInput = await screen . findByLabelText ( / A z u r e C l o u d / 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 ( / A z u r e C l o u d E n d p o i n t T e m p l a t e i s i n v a l i d ./ 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 ( / I n p u t M i c r o s o f t E n t r a \( A A D \) a u t h S c o p e / ) ;
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 ( / I n p u t M i c r o s o f t E n t r a \( A A D \) a u t h S c o p e h e r e / 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