66import  {  expect  }  from  'chai' ; 
77import  {  instance ,  mock ,  verify ,  when  }  from  'ts-mockito' ; 
88import  *  as  typemoq  from  'typemoq' ; 
9- import  {  Uri  }  from  'vscode' ; 
9+ import  {  TreeItemCollapsibleState ,   Uri  }  from  'vscode' ; 
1010import  {  CommandManager  }  from  '../../../client/common/application/commandManager' ; 
1111import  {  WorkspaceService  }  from  '../../../client/common/application/workspace' ; 
1212import  {  Commands  }  from  '../../../client/common/constants' ; 
@@ -15,7 +15,7 @@ import { CommandSource } from '../../../client/unittests/common/constants';
1515import  {  TestCollectionStorageService  }  from  '../../../client/unittests/common/services/storageService' ; 
1616import  {  getTestType  }  from  '../../../client/unittests/common/testUtils' ; 
1717import  { 
18-  ITestCollectionStorageService ,  TestStatus ,  TestType 
18+  ITestCollectionStorageService ,  TestFile ,   TestFolder ,   TestStatus ,  TestType 
1919}  from  '../../../client/unittests/common/types' ; 
2020import  {  TestTreeItem  }  from  '../../../client/unittests/explorer/testTreeViewItem' ; 
2121import  {  TestTreeViewProvider  }  from  '../../../client/unittests/explorer/testTreeViewProvider' ; 
@@ -611,4 +611,93 @@ suite('Unit Tests Test Explorer TestTreeViewProvider', () => {
611611 verify ( commandManager . executeCommand ( Commands . Tests_Discover ,  testWorkspaceFolder ,  CommandSource . testExplorer ,  undefined ) ) . once ( ) ; 
612612 } ) ; 
613613 } ) ; 
614+  test ( 'Expand tree item if it does not have any parent' ,  async  ( )  =>  { 
615+  const  commandManager  =  mock ( CommandManager ) ; 
616+  const  testStore  =  mock ( TestCollectionStorageService ) ; 
617+  const  testWorkspaceFolder  =  new  TestWorkspaceFolder ( {  uri : Uri . file ( __filename ) ,  name : '' ,  index : 0  } ) ; 
618+  when ( testStore . getTests ( testWorkspaceFolder . workspaceFolder . uri ) ) . thenReturn ( ) ; 
619+  when ( testStore . onDidChange ) . thenReturn ( noop  as  any ) ; 
620+  const  testTreeProvider  =  createMockTestTreeProvider ( instance ( testStore ) ,  undefined ,  undefined ,  undefined ,  instance ( commandManager ) ) ; 
621+ 
622+  // No parent 
623+  testTreeProvider . getParent  =  ( )  =>  Promise . resolve ( undefined ) ; 
624+ 
625+  const  element : TestFile  =  { 
626+  fullPath : __filename , 
627+  functions : [ ] , 
628+  suites : [ ] , 
629+  name : 'name' , 
630+  time : 0 , 
631+  resource : Uri . file ( __filename ) , 
632+  xmlName : '' , 
633+  nameToRun : '' 
634+  } ; 
635+ 
636+  const  node  =  await  testTreeProvider . getTreeItem ( element ) ; 
637+ 
638+  expect ( node . collapsibleState ) . to . equal ( TreeItemCollapsibleState . Expanded ) ; 
639+  } ) ; 
640+  test ( 'Expand tree item if the parent is the Workspace Folder in a multiroot scenario' ,  async  ( )  =>  { 
641+  const  commandManager  =  mock ( CommandManager ) ; 
642+  const  testStore  =  mock ( TestCollectionStorageService ) ; 
643+  const  testWorkspaceFolder  =  new  TestWorkspaceFolder ( {  uri : Uri . file ( __filename ) ,  name : '' ,  index : 0  } ) ; 
644+  when ( testStore . getTests ( testWorkspaceFolder . workspaceFolder . uri ) ) . thenReturn ( ) ; 
645+  when ( testStore . onDidChange ) . thenReturn ( noop  as  any ) ; 
646+  const  testTreeProvider  =  createMockTestTreeProvider ( instance ( testStore ) ,  undefined ,  undefined ,  undefined ,  instance ( commandManager ) ) ; 
647+ 
648+  // Has a workspace folder as parent. 
649+  const  parentFolder  =  new  TestWorkspaceFolder ( {  name : '' ,  index : 0 ,  uri : Uri . file ( __filename )  } ) ; 
650+ 
651+  testTreeProvider . getParent  =  ( )  =>  Promise . resolve ( parentFolder ) ; 
652+ 
653+  const  element : TestFile  =  { 
654+  fullPath : __filename , 
655+  functions : [ ] , 
656+  suites : [ ] , 
657+  name : 'name' , 
658+  time : 0 , 
659+  resource : Uri . file ( __filename ) , 
660+  xmlName : '' , 
661+  nameToRun : '' 
662+  } ; 
663+ 
664+  const  node  =  await  testTreeProvider . getTreeItem ( element ) ; 
665+ 
666+  expect ( node . collapsibleState ) . to . equal ( TreeItemCollapsibleState . Expanded ) ; 
667+  } ) ; 
668+  test ( 'Do not expand tree item if it does not have any parent' ,  async  ( )  =>  { 
669+  const  commandManager  =  mock ( CommandManager ) ; 
670+  const  testStore  =  mock ( TestCollectionStorageService ) ; 
671+  const  testWorkspaceFolder  =  new  TestWorkspaceFolder ( {  uri : Uri . file ( __filename ) ,  name : '' ,  index : 0  } ) ; 
672+  when ( testStore . getTests ( testWorkspaceFolder . workspaceFolder . uri ) ) . thenReturn ( ) ; 
673+  when ( testStore . onDidChange ) . thenReturn ( noop  as  any ) ; 
674+  const  testTreeProvider  =  createMockTestTreeProvider ( instance ( testStore ) ,  undefined ,  undefined ,  undefined ,  instance ( commandManager ) ) ; 
675+ 
676+  // Has a parent folder 
677+  const  parentFolder : TestFolder  =  { 
678+  name : '' , 
679+  nameToRun : '' , 
680+  resource : Uri . file ( __filename ) , 
681+  time : 0 , 
682+  testFiles : [ ] , 
683+  folders : [ ] 
684+  } ; 
685+ 
686+  testTreeProvider . getParent  =  ( )  =>  Promise . resolve ( parentFolder ) ; 
687+ 
688+  const  element : TestFile  =  { 
689+  fullPath : __filename , 
690+  functions : [ ] , 
691+  suites : [ ] , 
692+  name : 'name' , 
693+  time : 0 , 
694+  resource : Uri . file ( __filename ) , 
695+  xmlName : '' , 
696+  nameToRun : '' 
697+  } ; 
698+ 
699+  const  node  =  await  testTreeProvider . getTreeItem ( element ) ; 
700+ 
701+  expect ( node . collapsibleState ) . to . not . equal ( TreeItemCollapsibleState . Expanded ) ; 
702+  } ) ; 
614703} ) ; 
0 commit comments