@@ -12,6 +12,7 @@ import { IAsyncDataSource, ITreeNode } from '../../../../browser/ui/tree/tree.js
12
12
import { timeout } from '../../../../common/async.js' ;
13
13
import { Iterable } from '../../../../common/iterator.js' ;
14
14
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../common/utils.js' ;
15
+ import { runWithFakedTimers } from '../../../common/timeTravelScheduler.js' ;
15
16
16
17
interface Element {
17
18
id : string ;
@@ -465,45 +466,47 @@ suite('AsyncDataTree', function () {
465
466
} ) ;
466
467
467
468
test ( 'issue #80098 - first expand should call getChildren' , async ( ) => {
468
- const container = document . createElement ( 'div' ) ;
469
+ return runWithFakedTimers ( { useFakeTimers : true } , async ( ) => {
470
+ const container = document . createElement ( 'div' ) ;
469
471
470
- const calls : Function [ ] = [ ] ;
471
- const dataSource = new class implements IAsyncDataSource < Element , Element > {
472
- hasChildren ( element : Element ) : boolean {
473
- return ! ! element . children && element . children . length > 0 ;
474
- }
475
- getChildren ( element : Element ) : Promise < Element [ ] > {
476
- return new Promise ( c => calls . push ( ( ) => c ( element . children || [ ] ) ) ) ;
477
- }
478
- } ;
472
+ const calls : Function [ ] = [ ] ;
473
+ const dataSource = new class implements IAsyncDataSource < Element , Element > {
474
+ hasChildren ( element : Element ) : boolean {
475
+ return ! ! element . children && element . children . length > 0 ;
476
+ }
477
+ getChildren ( element : Element ) : Promise < Element [ ] > {
478
+ return new Promise ( c => calls . push ( ( ) => c ( element . children || [ ] ) ) ) ;
479
+ }
480
+ } ;
479
481
480
- const model = new Model ( {
481
- id : 'root' ,
482
- children : [ {
483
- id : 'a' , children : [ {
484
- id : 'aa'
482
+ const model = new Model ( {
483
+ id : 'root' ,
484
+ children : [ {
485
+ id : 'a' , children : [ {
486
+ id : 'aa'
487
+ } ]
485
488
} ]
486
- } ]
487
- } ) ;
489
+ } ) ;
488
490
489
- const tree = store . add ( new AsyncDataTree < Element , Element > ( 'test' , container , new VirtualDelegate ( ) , [ new Renderer ( ) ] , dataSource , { identityProvider : new IdentityProvider ( ) } ) ) ;
490
- tree . layout ( 200 ) ;
491
+ const tree = store . add ( new AsyncDataTree < Element , Element > ( 'test' , container , new VirtualDelegate ( ) , [ new Renderer ( ) ] , dataSource , { identityProvider : new IdentityProvider ( ) } ) ) ;
492
+ tree . layout ( 200 ) ;
491
493
492
- const pSetInput = tree . setInput ( model . root ) ;
493
- calls . pop ( ) ! ( ) ; // resolve getChildren(root)
494
- await pSetInput ;
494
+ const pSetInput = tree . setInput ( model . root ) ;
495
+ calls . pop ( ) ! ( ) ; // resolve getChildren(root)
496
+ await pSetInput ;
495
497
496
- const pExpandA = tree . expand ( model . get ( 'a' ) ) ;
497
- assert . strictEqual ( calls . length , 1 , 'expand(a) should\'ve called getChildren(a)' ) ;
498
+ const pExpandA = tree . expand ( model . get ( 'a' ) ) ;
499
+ assert . strictEqual ( calls . length , 1 , 'expand(a) should\'ve called getChildren(a)' ) ;
498
500
499
- let race = await Promise . race ( [ pExpandA . then ( ( ) => 'expand' ) , timeout ( 1 ) . then ( ( ) => 'timeout' ) ] ) ;
500
- assert . strictEqual ( race , 'timeout' , 'expand(a) should not be yet done' ) ;
501
+ let race = await Promise . race ( [ pExpandA . then ( ( ) => 'expand' ) , timeout ( 1 ) . then ( ( ) => 'timeout' ) ] ) ;
502
+ assert . strictEqual ( race , 'timeout' , 'expand(a) should not be yet done' ) ;
501
503
502
- calls . pop ( ) ! ( ) ;
503
- assert . strictEqual ( calls . length , 0 , 'no pending getChildren calls' ) ;
504
+ calls . pop ( ) ! ( ) ;
505
+ assert . strictEqual ( calls . length , 0 , 'no pending getChildren calls' ) ;
504
506
505
- race = await Promise . race ( [ pExpandA . then ( ( ) => 'expand' ) , timeout ( 1 ) . then ( ( ) => 'timeout' ) ] ) ;
506
- assert . strictEqual ( race , 'expand' , 'expand(a) should now be done' ) ;
507
+ race = await Promise . race ( [ pExpandA . then ( ( ) => 'expand' ) , timeout ( 1 ) . then ( ( ) => 'timeout' ) ] ) ;
508
+ assert . strictEqual ( race , 'expand' , 'expand(a) should now be done' ) ;
509
+ } ) ;
507
510
} ) ;
508
511
509
512
test ( 'issue #78388 - tree should react to hasChildren toggles' , async ( ) => {
0 commit comments