@@ -13,6 +13,7 @@ import {
1313 InputBox ,
1414 NotificationType ,
1515 SideBarView ,
16+ ViewSection ,
1617 VSBrowser ,
1718 WelcomeContentButton ,
1819 Workbench
@@ -30,6 +31,7 @@ import {
3031 RegistryWebViewDevfileWindow ,
3132 RegistryWebViewEditor ,
3233} from '../common/ui/webview/registryWebViewEditor' ;
34+ import { step , waitForItem } from '../common/utils' ;
3335
3436//TODO: Add more checks for different elements
3537export function testCreateComponent ( path : string ) {
@@ -82,15 +84,15 @@ export function testCreateComponent(path: string) {
8284
8385 componentName = 'node-js-runtime' ;
8486
85- const item = await waitForItem ( componentName ) ;
87+ const item = await waitForItem ( getSection , componentName ) ;
8688 expect ( item ) . to . be . not . undefined ;
8789
8890 dlt = false ;
8991 } ) ;
9092
9193 it ( 'Create component from local folder' , async function test ( ) {
9294 this . timeout ( 25_000 ) ;
93- const component = await waitForItem ( componentName ) ;
95+ const component = await waitForItem ( getSection , componentName ) ;
9496 const contextMenu = await component . openContextMenu ( ) ;
9597 await contextMenu . select ( MENUS . deleteConfiguration ) ;
9698
@@ -115,20 +117,42 @@ export function testCreateComponent(path: string) {
115117
116118 const localCodeBasePage = new LocalCodeBasePage ( ) ;
117119 await localCodeBasePage . initializeEditor ( ) ;
118- await localCodeBasePage . insertComponentName ( componentName ) ;
119- await localCodeBasePage . clickSelectFolderButton ( ) ;
120120
121- const input = await InputBox . create ( ) ;
122- await input . setText ( pth . join ( path , componentName ) ) ;
123- await input . confirm ( ) ;
121+ await step ( 'Insert component name' , async ( ) => {
122+ await localCodeBasePage . insertComponentName ( componentName ) ;
123+ } ) ;
124124
125- await localCodeBasePage . clickNextButton ( ) ;
126- await new Promise ( ( res ) => {
127- setTimeout ( res , 500 ) ;
125+ await step ( 'Click Select Folder button' , async ( ) => {
126+ await localCodeBasePage . clickSelectFolderButton ( ) ;
127+ } ) ;
128+
129+ await step ( 'Input component path' , async ( ) => {
130+ const input = await InputBox . create ( ) ;
131+ await input . setText ( pth . join ( path , componentName ) ) ;
132+ await input . confirm ( ) ;
133+ // critical: wait until InputBox is gone
134+ await VSBrowser . instance . driver . wait ( async ( ) => {
135+ try {
136+ await InputBox . create ( ) ;
137+ return false ;
138+ } catch {
139+ return true ;
140+ }
141+ } , 10000 ) ;
142+ } ) ;
143+
144+ await step ( 'Click Next button' , async ( ) => {
145+ await localCodeBasePage . clickNextButton ( ) ;
146+ await new Promise ( ( res ) => {
147+ setTimeout ( res , 500 ) ;
148+ } ) ;
149+ } ) ;
150+
151+ await step ( 'Click Create Component button' , async ( ) => {
152+ await localCodeBasePage . clickCreateComponent ( ) ;
128153 } ) ;
129- await localCodeBasePage . clickCreateComponent ( ) ;
130154
131- const item = await waitForItem ( componentName ) ;
155+ const item = await waitForItem ( getSection , componentName ) ;
132156 expect ( item ) . to . be . not . undefined ;
133157
134158 dlt = true ;
@@ -162,7 +186,7 @@ export function testCreateComponent(path: string) {
162186
163187 //check if component is in component view
164188 componentName = 'nodejs-starter' ;
165- const item = await waitForItem ( componentName ) ;
189+ const item = await waitForItem ( getSection , componentName ) ;
166190 expect ( item ) . to . be . not . undefined ;
167191
168192 dlt = false ;
@@ -172,7 +196,7 @@ export function testCreateComponent(path: string) {
172196 afterEach ( async function context ( ) {
173197 this . timeout ( 30_000 ) ;
174198 if ( componentName && dlt ) {
175- const component = await waitForItem ( componentName ) ;
199+ const component = await waitForItem ( getSection , componentName ) ;
176200 const contextMenu = await component . openContextMenu ( ) ;
177201 await contextMenu . select ( MENUS . deleteSourceCodeFolder ) ;
178202 const notification = await notificationExists (
@@ -253,25 +277,8 @@ export function testCreateComponent(path: string) {
253277 } , 10_000 ) ;
254278 }
255279
256- async function waitForItem ( label , timeout = 15000 ) {
257- const section = await view . getContent ( ) . getSection ( VIEWS . components ) ;
258-
259- const start = Date . now ( ) ;
260-
261- while ( Date . now ( ) - start < timeout ) {
262- try {
263- const item = await section . findItem ( label ) ;
264- if ( item ) {
265- return item ;
266- }
267- } catch {
268- // ignore transient errors
269- }
270-
271- await new Promise ( res => setTimeout ( res , 500 ) ) ;
272- }
273-
274- throw new Error ( `Item "${ label } " not found in section within ${ timeout } ms` ) ;
280+ async function getSection ( ) : Promise < ViewSection > {
281+ return await view . getContent ( ) . getSection ( VIEWS . components ) ;
275282 }
276283 } ) ;
277284}
0 commit comments