@@ -35,6 +35,7 @@ import { AlertItem } from '@/services/helpers/types';
35
35
import { AppThunk } from '@/store' ;
36
36
import { MockStoreBuilder } from '@/store/__mocks__/mockStore' ;
37
37
import { factoryResolverActionCreators , OAuthResponse } from '@/store/FactoryResolver' ;
38
+ import { prepareDevfile } from '@/components/WorkspaceProgress/CreatingSteps/Apply/Devfile/prepareDevfile' ;
38
39
39
40
jest . mock ( '@/components/WorkspaceProgress/TimeLimit' ) ;
40
41
@@ -345,7 +346,7 @@ describe('Creating steps, fetching a devfile', () => {
345
346
} ) ;
346
347
} ) ;
347
348
348
- describe ( 'unsupported git provider error ' , ( ) => {
349
+ describe ( 'unsupported git provider' , ( ) => {
349
350
let emptyStore : Store ;
350
351
const rejectReason = 'Failed to fetch devfile' ;
351
352
@@ -354,110 +355,13 @@ describe('Creating steps, fetching a devfile', () => {
354
355
mockRequestFactoryResolver . mockRejectedValueOnce ( rejectReason ) ;
355
356
} ) ;
356
357
357
- test ( 'alert title ' , async ( ) => {
358
+ test ( 'should continue with the default devfile ' , async ( ) => {
358
359
renderComponent ( emptyStore , searchParams ) ;
359
360
360
361
await jest . advanceTimersByTimeAsync ( MIN_STEP_DURATION_MS ) ;
361
362
362
- const expectAlertItem = expect . objectContaining ( {
363
- title : 'Warning' ,
364
- actionCallbacks : [
365
- expect . objectContaining ( {
366
- title : 'Continue with default devfile' ,
367
- callback : expect . any ( Function ) ,
368
- } ) ,
369
- expect . objectContaining ( {
370
- title : 'Reload' ,
371
- callback : expect . any ( Function ) ,
372
- } ) ,
373
- ] ,
374
- } ) ;
375
- await waitFor ( ( ) => expect ( mockOnError ) . toHaveBeenCalledWith ( expectAlertItem ) ) ;
376
-
377
- expect ( mockOnNextStep ) . not . toHaveBeenCalled ( ) ;
378
- } ) ;
379
-
380
- test ( 'action "Continue with default devfile"' , async ( ) => {
381
- // this deferred object will help run the callback at the right time
382
- const deferred = getDefer ( ) ;
383
-
384
- const actionTitle = 'Continue with default devfile' ;
385
- mockOnError . mockImplementationOnce ( ( alertItem : AlertItem ) => {
386
- const action = alertItem . actionCallbacks ?. find ( _action =>
387
- _action . title . startsWith ( actionTitle ) ,
388
- ) ;
389
- expect ( action ) . toBeDefined ( ) ;
390
-
391
- if ( action ) {
392
- deferred . promise . then ( action . callback ) ;
393
- } else {
394
- throw new Error ( 'Action not found' ) ;
395
- }
396
- } ) ;
397
-
398
- renderComponent ( emptyStore , searchParams ) ;
399
- await jest . runAllTimersAsync ( ) ;
400
-
401
- await waitFor ( ( ) => expect ( mockOnError ) . toHaveBeenCalled ( ) ) ;
402
- expect ( mockOnRestart ) . not . toHaveBeenCalled ( ) ;
403
- expect ( mockOnNextStep ) . not . toHaveBeenCalled ( ) ;
404
-
405
- mockOnError . mockClear ( ) ;
406
-
407
- /* test the action */
408
- await jest . runOnlyPendingTimersAsync ( ) ;
409
-
410
- // resolve deferred to trigger the callback
411
- deferred . resolve ( ) ;
412
-
413
- await waitFor ( ( ) => expect ( mockOnNextStep ) . toHaveBeenCalled ( ) ) ;
414
- expect ( mockOnRestart ) . not . toHaveBeenCalled ( ) ;
415
- expect ( mockOnError ) . not . toHaveBeenCalled ( ) ;
416
- } ) ;
417
-
418
- test ( 'action "Reload"' , async ( ) => {
419
- // this deferred object will help run the callback at the right time
420
- const deferred = getDefer ( ) ;
421
-
422
- const actionTitle = 'Reload' ;
423
- mockOnError . mockImplementationOnce ( async ( alertItem : AlertItem ) => {
424
- const action = alertItem . actionCallbacks ?. find ( _action =>
425
- _action . title . startsWith ( actionTitle ) ,
426
- ) ;
427
- expect ( action ) . toBeDefined ( ) ;
428
-
429
- if ( action ) {
430
- deferred . promise . then ( action . callback ) ;
431
- } else {
432
- throw new Error ( 'Action not found' ) ;
433
- }
434
- } ) ;
435
-
436
- renderComponent ( emptyStore , searchParams ) ;
437
- await jest . runAllTimersAsync ( ) ;
438
-
439
- await waitFor ( ( ) => expect ( mockOnError ) . toHaveBeenCalled ( ) ) ;
440
- expect ( mockOnRestart ) . not . toHaveBeenCalled ( ) ;
441
- expect ( mockOnNextStep ) . not . toHaveBeenCalled ( ) ;
442
-
443
- // first call resolves with error
444
- expect ( mockRequestFactoryResolver ) . toHaveBeenCalledTimes ( 1 ) ;
445
-
446
- mockOnError . mockClear ( ) ;
447
-
448
- /* test the action */
449
-
450
- await jest . runAllTimersAsync ( ) ;
451
-
452
- // resolve deferred to trigger the callback
453
- deferred . resolve ( ) ;
454
-
455
- await waitFor ( ( ) => expect ( mockOnRestart ) . toHaveBeenCalled ( ) ) ;
456
- expect ( mockOnNextStep ) . not . toHaveBeenCalled ( ) ;
457
- expect ( mockOnError ) . not . toHaveBeenCalled ( ) ;
458
-
459
- // should request the factory resolver for the second time
460
- await waitFor ( ( ) => expect ( mockRequestFactoryResolver ) . toHaveBeenCalledTimes ( 2 ) ) ;
363
+ await waitFor ( ( ) => expect ( mockOnError ) . not . toHaveBeenCalled ( ) ) ;
364
+ expect ( mockOnNextStep ) . toHaveBeenCalled ( ) ;
461
365
} ) ;
462
366
} ) ;
463
367
0 commit comments