1313/* eslint-disable @typescript-eslint/no-non-null-assertion */
1414
1515import { FACTORY_LINK_ATTR } from '@eclipse-che/common' ;
16- import { AlertVariant } from '@patternfly/react-core' ;
1716import { cleanup , screen , waitFor } from '@testing-library/react' ;
1817import userEvent , { UserEvent } from '@testing-library/user-event' ;
1918import React from 'react' ;
@@ -346,7 +345,7 @@ describe('Creating steps, fetching a devfile', () => {
346345 } ) ;
347346 } ) ;
348347
349- describe ( 'unsupported git provider error ' , ( ) => {
348+ describe ( 'unsupported git provider' , ( ) => {
350349 let emptyStore : Store ;
351350 const rejectReason = 'Failed to fetch devfile' ;
352351
@@ -355,110 +354,13 @@ describe('Creating steps, fetching a devfile', () => {
355354 mockRequestFactoryResolver . mockRejectedValueOnce ( rejectReason ) ;
356355 } ) ;
357356
358- test ( 'alert title ' , async ( ) => {
357+ test ( 'should continue with the default devfile ' , async ( ) => {
359358 renderComponent ( emptyStore , searchParams ) ;
360359
361360 await jest . advanceTimersByTimeAsync ( MIN_STEP_DURATION_MS ) ;
362361
363- const expectAlertItem = expect . objectContaining ( {
364- title : 'Warning' ,
365- actionCallbacks : [
366- expect . objectContaining ( {
367- title : 'Continue with default devfile' ,
368- callback : expect . any ( Function ) ,
369- } ) ,
370- expect . objectContaining ( {
371- title : 'Reload' ,
372- callback : expect . any ( Function ) ,
373- } ) ,
374- ] ,
375- } ) ;
376- await waitFor ( ( ) => expect ( mockOnError ) . toHaveBeenCalledWith ( expectAlertItem ) ) ;
377-
378- expect ( mockOnNextStep ) . not . toHaveBeenCalled ( ) ;
379- } ) ;
380-
381- test ( 'action "Continue with default devfile"' , async ( ) => {
382- // this deferred object will help run the callback at the right time
383- const deferred = getDefer ( ) ;
384-
385- const actionTitle = 'Continue with default devfile' ;
386- mockOnError . mockImplementationOnce ( ( alertItem : AlertItem ) => {
387- const action = alertItem . actionCallbacks ?. find ( _action =>
388- _action . title . startsWith ( actionTitle ) ,
389- ) ;
390- expect ( action ) . toBeDefined ( ) ;
391-
392- if ( action ) {
393- deferred . promise . then ( action . callback ) ;
394- } else {
395- throw new Error ( 'Action not found' ) ;
396- }
397- } ) ;
398-
399- renderComponent ( emptyStore , searchParams ) ;
400- await jest . runAllTimersAsync ( ) ;
401-
402- await waitFor ( ( ) => expect ( mockOnError ) . toHaveBeenCalled ( ) ) ;
403- expect ( mockOnRestart ) . not . toHaveBeenCalled ( ) ;
404- expect ( mockOnNextStep ) . not . toHaveBeenCalled ( ) ;
405-
406- mockOnError . mockClear ( ) ;
407-
408- /* test the action */
409- await jest . runOnlyPendingTimersAsync ( ) ;
410-
411- // resolve deferred to trigger the callback
412- deferred . resolve ( ) ;
413-
414- await waitFor ( ( ) => expect ( mockOnNextStep ) . toHaveBeenCalled ( ) ) ;
415- expect ( mockOnRestart ) . not . toHaveBeenCalled ( ) ;
416- expect ( mockOnError ) . not . toHaveBeenCalled ( ) ;
417- } ) ;
418-
419- test ( 'action "Reload"' , async ( ) => {
420- // this deferred object will help run the callback at the right time
421- const deferred = getDefer ( ) ;
422-
423- const actionTitle = 'Reload' ;
424- mockOnError . mockImplementationOnce ( async ( alertItem : AlertItem ) => {
425- const action = alertItem . actionCallbacks ?. find ( _action =>
426- _action . title . startsWith ( actionTitle ) ,
427- ) ;
428- expect ( action ) . toBeDefined ( ) ;
429-
430- if ( action ) {
431- deferred . promise . then ( action . callback ) ;
432- } else {
433- throw new Error ( 'Action not found' ) ;
434- }
435- } ) ;
436-
437- renderComponent ( emptyStore , searchParams ) ;
438- await jest . runAllTimersAsync ( ) ;
439-
440- await waitFor ( ( ) => expect ( mockOnError ) . toHaveBeenCalled ( ) ) ;
441- expect ( mockOnRestart ) . not . toHaveBeenCalled ( ) ;
442- expect ( mockOnNextStep ) . not . toHaveBeenCalled ( ) ;
443-
444- // first call resolves with error
445- expect ( mockRequestFactoryResolver ) . toHaveBeenCalledTimes ( 1 ) ;
446-
447- mockOnError . mockClear ( ) ;
448-
449- /* test the action */
450-
451- await jest . runAllTimersAsync ( ) ;
452-
453- // resolve deferred to trigger the callback
454- deferred . resolve ( ) ;
455-
456- await waitFor ( ( ) => expect ( mockOnRestart ) . toHaveBeenCalled ( ) ) ;
457- expect ( mockOnNextStep ) . not . toHaveBeenCalled ( ) ;
458- expect ( mockOnError ) . not . toHaveBeenCalled ( ) ;
459-
460- // should request the factory resolver for the second time
461- await waitFor ( ( ) => expect ( mockRequestFactoryResolver ) . toHaveBeenCalledTimes ( 2 ) ) ;
362+ await waitFor ( ( ) => expect ( mockOnError ) . not . toHaveBeenCalled ( ) ) ;
363+ expect ( mockOnNextStep ) . toHaveBeenCalled ( ) ;
462364 } ) ;
463365 } ) ;
464366
@@ -695,31 +597,6 @@ describe('Creating steps, fetching a devfile', () => {
695597 const protocol = 'http://' ;
696598 const factoryUrl = 'git@github.com:user/repository-name.git' ;
697599 const emptyStore = new MockStoreBuilder ( ) . build ( ) ;
698- const sshPrivateRepoAllertItem = expect . objectContaining ( {
699- title : 'Warning' ,
700- variant : AlertVariant . warning ,
701- children : (
702- < ExpandableWarning
703- textBefore = "Devfile resolve from a privatre repositry via an SSH url is not supported."
704- errorMessage = "Could not reach devfile"
705- textAfter = "Apply a Personal Access Token to fetch the devfile.yaml content."
706- />
707- ) ,
708- actionCallbacks : [
709- expect . objectContaining ( {
710- title : 'Continue with default devfile' ,
711- callback : expect . any ( Function ) ,
712- } ) ,
713- expect . objectContaining ( {
714- title : 'Reload' ,
715- callback : expect . any ( Function ) ,
716- } ) ,
717- expect . objectContaining ( {
718- title : 'Open Documentation page' ,
719- callback : expect . any ( Function ) ,
720- } ) ,
721- ] ,
722- } ) ;
723600
724601 let spyWindowLocation : jest . SpyInstance ;
725602 let location : Location ;
@@ -771,32 +648,32 @@ describe('Creating steps, fetching a devfile', () => {
771648 expect ( mockOnError ) . not . toHaveBeenCalled ( ) ;
772649 } ) ;
773650
774- it ( 'should show warning on SSH url' , async ( ) => {
651+ it ( 'should use default devfile on private SSH url' , async ( ) => {
775652 searchParams = new URLSearchParams ( {
776653 [ FACTORY_URL_ATTR ] : 'git@github.com:user/repository.git' ,
777654 } ) ;
778655
779656 renderComponent ( emptyStore , searchParams , location ) ;
780657
781658 await jest . advanceTimersByTimeAsync ( MIN_STEP_DURATION_MS ) ;
782- await waitFor ( ( ) => expect ( mockOnNextStep ) . not . toHaveBeenCalled ) ;
659+ await waitFor ( ( ) => expect ( mockOnNextStep ) . toHaveBeenCalled ( ) ) ;
783660
784661 expect ( mockOpenOAuthPage ) . not . toHaveBeenCalled ( ) ;
785- expect ( mockOnError ) . toHaveBeenCalledWith ( sshPrivateRepoAllertItem ) ;
662+ expect ( mockOnError ) . not . toHaveBeenCalled ( ) ;
786663 } ) ;
787664
788- it ( 'should show warning on bitbucket-server SSH url' , async ( ) => {
665+ it ( 'should use default devfile on bitbucket-server SSH url' , async ( ) => {
789666 searchParams = new URLSearchParams ( {
790667 [ FACTORY_URL_ATTR ] : 'ssh://git@bitbucket-server.com/~user/repository.git' ,
791668 } ) ;
792669
793670 renderComponent ( emptyStore , searchParams , location ) ;
794671
795672 await jest . advanceTimersByTimeAsync ( MIN_STEP_DURATION_MS ) ;
796- await waitFor ( ( ) => expect ( mockOnNextStep ) . not . toHaveBeenCalled ) ;
673+ await waitFor ( ( ) => expect ( mockOnNextStep ) . toHaveBeenCalled ) ;
797674
798675 expect ( mockOpenOAuthPage ) . not . toHaveBeenCalled ( ) ;
799- expect ( mockOnError ) . toHaveBeenCalledWith ( sshPrivateRepoAllertItem ) ;
676+ expect ( mockOnError ) . not . toHaveBeenCalled ( ) ;
800677 } ) ;
801678 } ) ;
802679} ) ;
0 commit comments