5
5
6
6
import * as assert from 'assert' ;
7
7
import * as sinon from 'sinon' ;
8
+ import { timeout } from 'vs/base/common/async' ;
8
9
import { VSBuffer } from 'vs/base/common/buffer' ;
9
10
import { CancellationTokenSource } from 'vs/base/common/cancellation' ;
10
11
import { Event } from 'vs/base/common/event' ;
@@ -85,11 +86,14 @@ suite('ExtHost Testing', () => {
85
86
const ds = ensureNoDisposablesAreLeakedInTestSuite ( ) ;
86
87
87
88
let single : TestExtHostTestItemCollection ;
89
+ let resolveCalls : ( string | undefined ) [ ] = [ ] ;
88
90
setup ( ( ) => {
91
+ resolveCalls = [ ] ;
89
92
single = ds . add ( new TestExtHostTestItemCollection ( 'ctrlId' , 'root' , {
90
93
getDocument : ( ) => undefined ,
91
94
} as Partial < ExtHostDocumentsAndEditors > as ExtHostDocumentsAndEditors ) ) ;
92
95
single . resolveHandler = item => {
96
+ resolveCalls . push ( item ?. id ) ;
93
97
if ( item === undefined ) {
94
98
const a = new TestItemImpl ( 'ctrlId' , 'id-a' , 'a' , URI . file ( '/' ) ) ;
95
99
a . canResolveChildren = true ;
@@ -305,7 +309,7 @@ suite('ExtHost Testing', () => {
305
309
assert . deepStrictEqual ( single . collectDiff ( ) , [
306
310
{
307
311
op : TestDiffOpType . Update ,
308
- item : { extId : new TestId ( [ 'ctrlId' , 'id-a' ] ) . toString ( ) , expand : TestItemExpandState . Expanded , item : { label : 'Hello world' } } ,
312
+ item : { extId : new TestId ( [ 'ctrlId' , 'id-a' ] ) . toString ( ) , item : { label : 'Hello world' } } ,
309
313
} ,
310
314
{
311
315
op : TestDiffOpType . DocumentSynced ,
@@ -326,6 +330,40 @@ suite('ExtHost Testing', () => {
326
330
assert . deepStrictEqual ( single . collectDiff ( ) , [ ] ) ;
327
331
} ) ;
328
332
333
+ suite ( 'expandibility restoration' , ( ) => {
334
+ const doReplace = async ( canResolveChildren = true ) => {
335
+ const uri = single . root . children . get ( 'id-a' ) ! . uri ;
336
+ const newA = new TestItemImpl ( 'ctrlId' , 'id-a' , 'Hello world' , uri ) ;
337
+ newA . canResolveChildren = canResolveChildren ;
338
+ single . root . children . replace ( [
339
+ newA ,
340
+ new TestItemImpl ( 'ctrlId' , 'id-b' , single . root . children . get ( 'id-b' ) ! . label , uri ) ,
341
+ ] ) ;
342
+ await timeout ( 0 ) ; // drain microtasks
343
+ } ;
344
+
345
+ test ( 'does not restore an unexpanded state' , async ( ) => {
346
+ await single . expand ( single . root . id , 0 ) ;
347
+ assert . deepStrictEqual ( resolveCalls , [ undefined ] ) ;
348
+ await doReplace ( ) ;
349
+ assert . deepStrictEqual ( resolveCalls , [ undefined ] ) ;
350
+ } ) ;
351
+
352
+ test ( 'restores resolve state on replacement' , async ( ) => {
353
+ await single . expand ( single . root . id , Infinity ) ;
354
+ assert . deepStrictEqual ( resolveCalls , [ undefined , 'id-a' ] ) ;
355
+ await doReplace ( ) ;
356
+ assert . deepStrictEqual ( resolveCalls , [ undefined , 'id-a' , 'id-a' ] ) ;
357
+ } ) ;
358
+
359
+ test ( 'does not expand if new child is not expandable' , async ( ) => {
360
+ await single . expand ( single . root . id , Infinity ) ;
361
+ assert . deepStrictEqual ( resolveCalls , [ undefined , 'id-a' ] ) ;
362
+ await doReplace ( false ) ;
363
+ assert . deepStrictEqual ( resolveCalls , [ undefined , 'id-a' ] ) ;
364
+ } ) ;
365
+ } ) ;
366
+
329
367
test ( 'treats in-place replacement as mutation deeply' , ( ) => {
330
368
single . expand ( single . root . id , Infinity ) ;
331
369
single . collectDiff ( ) ;
@@ -340,10 +378,6 @@ suite('ExtHost Testing', () => {
340
378
single . root . children . replace ( [ newA , single . root . children . get ( 'id-b' ) ! ] ) ;
341
379
342
380
assert . deepStrictEqual ( single . collectDiff ( ) , [
343
- {
344
- op : TestDiffOpType . Update ,
345
- item : { extId : new TestId ( [ 'ctrlId' , 'id-a' ] ) . toString ( ) , expand : TestItemExpandState . Expanded } ,
346
- } ,
347
381
{
348
382
op : TestDiffOpType . Update ,
349
383
item : { extId : TestId . fromExtHostTestItem ( oldAB , 'ctrlId' ) . toString ( ) , item : { label : 'Hello world' } } ,
0 commit comments