@@ -219,18 +219,18 @@ describe('App: Runs', { viewportWidth: 1200 }, () => {
219219 cy . remoteGraphQLIntercept ( async ( obj ) => {
220220 // Currently, all remote requests go through here, we want to use this to modify the
221221 // remote request before it's used and avoid touching the login query
222+ if ( obj . result . data ?. cloudProjectBySlug && obj . variables . _v0_slug === 'abcdef42' ) {
223+ const proj = obj . result . data . cloudProjectBySlug
222224
223- if ( obj . result . data ?. cloudProjectsBySlugs && obj . variables . _v0_slugs . includes ( 'abcdef42' ) ) {
224- for ( const proj of obj . result . data . cloudProjectsBySlugs ) {
225- proj . __typename = 'CloudProjectNotFound'
226- proj . message = 'Cloud Project Not Found'
227- }
225+ proj . __typename = 'CloudProjectNotFound'
226+ proj . message = 'Cloud Project Not Found'
228227 }
229228
230229 if ( obj . result . data ?. cloudViewer ?. organizations ?. nodes ) {
231230 const projectNodes = obj . result . data ?. cloudViewer . organizations . nodes [ 0 ] . projects . nodes
232231
233232 projectNodes . push ( {
233+ __typename : 'CloudProject' ,
234234 id : '1' ,
235235 slug : 'ghijkl' ,
236236 name : 'Mock Project' ,
@@ -270,12 +270,12 @@ describe('App: Runs', { viewportWidth: 1200 }, () => {
270270
271271 it ( 'if project Id is specified in config file that is not accessible, shows call to action' , ( ) => {
272272 cy . remoteGraphQLIntercept ( async ( obj ) => {
273- if ( obj . result . data ?. cloudProjectsBySlugs ) {
274- for ( const proj of obj . result . data . cloudProjectsBySlugs ) {
275- proj . __typename = 'CloudProjectUnauthorized'
276- proj . message = 'Cloud Project Unauthorized '
277- proj . hasRequestedAccess = false
278- }
273+ if ( obj . result . data ?. cloudProjectBySlug ) {
274+ const proj = obj . result . data . cloudProjectBySlug
275+
276+ proj . __typename = 'CloudProjectUnauthorized '
277+ proj . message = 'Cloud Project Unauthorized'
278+ proj . hasRequestedAccess = false
279279 }
280280
281281 return obj . result
@@ -299,12 +299,12 @@ describe('App: Runs', { viewportWidth: 1200 }, () => {
299299 return obj . result
300300 }
301301
302- if ( obj . result . data ?. cloudProjectsBySlugs ) {
303- for ( const proj of obj . result . data . cloudProjectsBySlugs ) {
304- proj . __typename = 'CloudProjectUnauthorized'
305- proj . message = 'Cloud Project Unauthorized '
306- proj . hasRequestedAccess = false
307- }
302+ if ( obj . result . data ?. cloudProjectBySlug ) {
303+ const proj = obj . result . data . cloudProjectBySlug
304+
305+ proj . __typename = 'CloudProjectUnauthorized '
306+ proj . message = 'Cloud Project Unauthorized'
307+ proj . hasRequestedAccess = false
308308 }
309309
310310 return obj . result
@@ -321,13 +321,13 @@ describe('App: Runs', { viewportWidth: 1200 }, () => {
321321
322322 it ( 'updates the button text when the request access button is clicked' , ( ) => {
323323 cy . remoteGraphQLIntercept ( async ( obj , testState ) => {
324- if ( obj . operationName === 'Runs_currentProject_cloudProject_batched ' ) {
325- for ( const proj of obj ! . result ! . data ! . cloudProjectsBySlugs ) {
326- proj . __typename = 'CloudProjectUnauthorized'
327- proj . message = 'Cloud Project Unauthorized '
328- proj . hasRequestedAccess = false
329- testState . project = proj
330- }
324+ if ( obj . operationName === 'Runs_currentProject_cloudProject_cloudProjectBySlug ' ) {
325+ const proj = obj ! . result ! . data ! . cloudProjectBySlug
326+
327+ proj . __typename = 'CloudProjectUnauthorized '
328+ proj . message = 'Cloud Project Unauthorized'
329+ proj . hasRequestedAccess = false
330+ testState . project = proj
331331 } else if ( obj . operationName === 'RunsErrorRenderer_RequestAccess_cloudProjectRequestAccess' ) {
332332 obj ! . result ! . data ! . cloudProjectRequestAccess = {
333333 ...testState . project ,
@@ -355,12 +355,12 @@ describe('App: Runs', { viewportWidth: 1200 }, () => {
355355 // Currently, all remote requests go through here, we want to use this to modify the
356356 // remote request before it's used and avoid touching the login query
357357
358- if ( obj . result . data ?. cloudProjectsBySlugs ) {
359- for ( const proj of obj . result . data . cloudProjectsBySlugs ) {
360- proj . __typename = 'CloudProjectUnauthorized'
361- proj . message = 'Cloud Project Unauthorized '
362- proj . hasRequestedAccess = true
363- }
358+ if ( obj . result . data ?. cloudProjectBySlug ) {
359+ const proj = obj . result . data . cloudProjectBySlug
360+
361+ proj . __typename = 'CloudProjectUnauthorized '
362+ proj . message = 'Cloud Project Unauthorized'
363+ proj . hasRequestedAccess = true
364364 }
365365
366366 return obj . result
@@ -386,12 +386,8 @@ describe('App: Runs', { viewportWidth: 1200 }, () => {
386386 cy . remoteGraphQLIntercept ( async ( obj ) => {
387387 // Currently, all remote requests go through here, we want to use this to modify the
388388 // remote request before it's used and avoid touching the login query
389- if ( obj . result . data ?. cloudProjectsBySlugs ) {
390- for ( const proj of obj . result . data . cloudProjectsBySlugs ) {
391- if ( proj . runs ?. nodes ) {
392- proj . runs . nodes = [ ]
393- }
394- }
389+ if ( obj . result . data ?. cloudProjectBySlug ?. runs ?. nodes ) {
390+ obj . result . data . cloudProjectBySlug . runs . nodes = [ ]
395391 }
396392
397393 return obj . result
@@ -409,12 +405,8 @@ describe('App: Runs', { viewportWidth: 1200 }, () => {
409405
410406 cy . loginUser ( )
411407 cy . remoteGraphQLIntercept ( async ( obj ) => {
412- if ( obj . result . data ?. cloudProjectsBySlugs ) {
413- for ( const proj of obj . result . data . cloudProjectsBySlugs ) {
414- if ( proj . runs ?. nodes ) {
415- proj . runs . nodes = [ ]
416- }
417- }
408+ if ( obj . result . data ?. cloudProjectBySlug ?. runs ?. nodes ) {
409+ obj . result . data . cloudProjectBySlug . runs . nodes = [ ]
418410 }
419411
420412 return obj . result
@@ -438,12 +430,8 @@ describe('App: Runs', { viewportWidth: 1200 }, () => {
438430
439431 cy . loginUser ( )
440432 cy . remoteGraphQLIntercept ( async ( obj ) => {
441- if ( obj . result . data ?. cloudProjectsBySlugs ) {
442- for ( const proj of obj . result . data . cloudProjectsBySlugs ) {
443- if ( proj . runs ?. nodes ) {
444- proj . runs . nodes = [ ]
445- }
446- }
433+ if ( obj . result . data ?. cloudProjectBySlug ?. runs ?. nodes ) {
434+ obj . result . data . cloudProjectBySlug . runs . nodes = [ ]
447435 }
448436
449437 return obj . result
@@ -480,17 +468,17 @@ describe('App: Runs', { viewportWidth: 1200 }, () => {
480468
481469 cy . get ( '[href="http://dummy.cypress.io/runs/0"]' ) . first ( ) . within ( ( ) => {
482470 cy . findByText ( 'fix: make gql work CANCELLED' )
483- cy . get ( '[data-cy="run-card-icon"]' )
471+ cy . get ( '[data-cy="run-card-icon-CANCELLED "]' )
484472 } )
485473
486474 cy . get ( '[href="http://dummy.cypress.io/runs/1"]' ) . first ( ) . within ( ( ) => {
487475 cy . findByText ( 'fix: make gql work ERRORED' )
488- cy . get ( '[data-cy="run-card-icon"]' )
476+ cy . get ( '[data-cy="run-card-icon-ERRORED "]' )
489477 } )
490478
491479 cy . get ( '[href="http://dummy.cypress.io/runs/2"]' ) . first ( ) . within ( ( ) => {
492480 cy . findByText ( 'fix: make gql work FAILED' )
493- cy . get ( '[data-cy="run-card-icon"]' )
481+ cy . get ( '[data-cy="run-card-icon-FAILED "]' )
494482 } )
495483
496484 cy . get ( '[href="http://dummy.cypress.io/runs/0"]' ) . first ( ) . as ( 'firstRun' )
@@ -565,4 +553,110 @@ describe('App: Runs', { viewportWidth: 1200 }, () => {
565553 cy . get ( '[data-cy=warning-alert]' ) . should ( 'not.exist' )
566554 } )
567555 } )
556+
557+ describe ( 'refetching' , ( ) => {
558+ let obj : { toCall ?: Function } = { }
559+ const RUNNING_COUNT = 3
560+
561+ beforeEach ( ( ) => {
562+ cy . scaffoldProject ( 'component-tests' )
563+ cy . openProject ( 'component-tests' )
564+ cy . startAppServer ( 'component' )
565+ cy . loginUser ( )
566+ cy . remoteGraphQLIntercept ( ( obj , testState ) => {
567+ if ( obj . result . data ?. cloudProjectBySlug ?. runs ?. nodes . length ) {
568+ obj . result . data . cloudProjectBySlug . runs . nodes . map ( ( run ) => {
569+ run . status = 'RUNNING'
570+ } )
571+
572+ obj . result . data . cloudProjectBySlug . runs . nodes = obj . result . data . cloudProjectBySlug . runs . nodes . slice ( 0 , 3 )
573+ }
574+
575+ return obj . result
576+ } )
577+
578+ cy . visitApp ( '/runs' , {
579+ onBeforeLoad ( win ) {
580+ const setTimeout = win . setTimeout
581+
582+ // @ts -expect-error
583+ win . setTimeout = function ( fn , time ) {
584+ if ( fn . name === 'fetchNewerRuns' ) {
585+ obj . toCall = fn
586+ } else {
587+ setTimeout ( fn , time )
588+ }
589+ }
590+ } ,
591+ } )
592+ } )
593+
594+ it ( 'should re-query for executing runs' , ( ) => {
595+ cy . get ( '[data-cy="run-card-icon-RUNNING"]' ) . should ( 'have.length' , RUNNING_COUNT ) . should ( 'be.visible' )
596+
597+ cy . remoteGraphQLIntercept ( async ( obj ) => {
598+ await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) )
599+
600+ if ( obj . result . data ?. cloudNode ?. newerRuns ?. nodes ) {
601+ obj . result . data . cloudNode . newerRuns . nodes = [ ]
602+ }
603+
604+ if ( obj . result . data ?. cloudNodesByIds ) {
605+ obj . result . data ?. cloudNodesByIds . map ( ( node ) => {
606+ node . status = 'RUNNING'
607+ } )
608+
609+ obj . result . data . cloudNodesByIds [ 0 ] . status = 'PASSED'
610+ }
611+
612+ return obj . result
613+ } )
614+
615+ function completeNext ( passed ) {
616+ cy . wrap ( obj ) . invoke ( 'toCall' ) . then ( ( ) => {
617+ cy . get ( '[data-cy="run-card-icon-PASSED"]' ) . should ( 'have.length' , passed ) . should ( 'be.visible' )
618+ if ( passed < RUNNING_COUNT ) {
619+ completeNext ( passed + 1 )
620+ }
621+ } )
622+ }
623+
624+ completeNext ( 1 )
625+ } )
626+
627+ it ( 'should fetch newer runs and maintain them when navigating' , ( ) => {
628+ cy . get ( '[data-cy="run-card-icon-RUNNING"]' ) . should ( 'have.length' , RUNNING_COUNT ) . should ( 'be.visible' )
629+
630+ cy . remoteGraphQLIntercept ( async ( obj ) => {
631+ await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) )
632+
633+ if ( obj . result . data ?. cloudNodesByIds ) {
634+ obj . result . data ?. cloudNodesByIds . map ( ( node ) => {
635+ node . status = 'PASSED'
636+ node . totalPassed = 100
637+ } )
638+ }
639+
640+ return obj . result
641+ } )
642+
643+ cy . get ( '[data-cy="run-card-icon-RUNNING"]' ) . should ( 'have.length' , 3 ) . should ( 'be.visible' )
644+ cy . wrap ( obj ) . invoke ( 'toCall' )
645+
646+ cy . get ( '[data-cy="run-card-icon-PASSED"]' ) . should ( 'have.length' , 3 ) . should ( 'be.visible' ) . within ( ( ) => {
647+ cy . get ( '[data-cy="runResults-passed-count"]' ) . should ( 'contain' , 100 )
648+ } )
649+
650+ cy . get ( '[data-cy="run-card-icon-RUNNING"]' ) . should ( 'have.length' , 2 ) . should ( 'be.visible' )
651+
652+ // If we navigate away & back, we should see the same runs
653+ cy . get ( '[href="#/settings"]' ) . click ( )
654+ cy . remoteGraphQLIntercept ( ( obj ) => obj . result )
655+
656+ cy . get ( '[href="#/runs"]' ) . click ( )
657+
658+ cy . get ( '[data-cy="run-card-icon-PASSED"]' ) . should ( 'have.length' , 3 ) . should ( 'be.visible' )
659+ cy . get ( '[data-cy="run-card-icon-RUNNING"]' ) . should ( 'have.length' , 2 ) . should ( 'be.visible' )
660+ } )
661+ } )
568662} )
0 commit comments