@@ -35,6 +35,7 @@ describe('SolutionOutlineView', () => {
3535 let visibilityChangeEmitter : vscode . EventEmitter < Event > ;
3636 let globalStateProvider : GlobalState < CsolutionGlobalState > ;
3737 let configurationProvider : MockConfigurationProvider ;
38+ let executeCommandSpy : jest . SpyInstance ;
3839
3940 beforeEach ( async ( ) => {
4041 visibilityChangeEmitter = new vscode . EventEmitter ( ) ;
@@ -54,6 +55,11 @@ describe('SolutionOutlineView', () => {
5455
5556 globalStateProvider = globalStateFactory ( ) ;
5657 configurationProvider = configurationProviderFactory ( ) ;
58+ executeCommandSpy = jest . spyOn ( vscode . commands , 'executeCommand' ) . mockResolvedValue ( undefined ) ;
59+ } ) ;
60+
61+ afterEach ( ( ) => {
62+ executeCommandSpy . mockRestore ( ) ;
5763 } ) ;
5864
5965
@@ -214,7 +220,6 @@ describe('SolutionOutlineView', () => {
214220 } ) ;
215221
216222 it ( 'reveals the solution outline when a new solution is loaded and auto reveal is enabled' , async ( ) => {
217- const executeCommandSpy = jest . spyOn ( vscode . commands , 'executeCommand' ) . mockResolvedValue ( undefined ) ;
218223 const solutionLoadedState = activeSolutionLoadStateFactory ( ) ;
219224 const mockSolutionManager = solutionManagerFactory ( {
220225 loadState : solutionLoadedState ,
@@ -237,11 +242,9 @@ describe('SolutionOutlineView', () => {
237242
238243 expect ( executeCommandSpy ) . toHaveBeenCalledWith ( `${ SolutionOutlineView . treeViewId } .open` , { preserveFocus : true } ) ;
239244
240- executeCommandSpy . mockRestore ( ) ;
241245 } ) ;
242246
243247 it ( 'does not reveal the solution outline when auto reveal is disabled' , async ( ) => {
244- const executeCommandSpy = jest . spyOn ( vscode . commands , 'executeCommand' ) . mockResolvedValue ( undefined ) ;
245248 const solutionLoadedState = activeSolutionLoadStateFactory ( ) ;
246249 const mockSolutionManager = solutionManagerFactory ( {
247250 loadState : solutionLoadedState ,
@@ -267,7 +270,60 @@ describe('SolutionOutlineView', () => {
267270
268271 expect ( executeCommandSpy ) . not . toHaveBeenCalledWith ( `${ SolutionOutlineView . treeViewId } .open` , { preserveFocus : true } ) ;
269272
270- executeCommandSpy . mockRestore ( ) ;
273+ } ) ;
274+
275+ it ( 'refreshes the tree on compilation database update when a West project exists' , async ( ) => {
276+ const solutionLoadedState = activeSolutionLoadStateFactory ( ) ;
277+ const mockCsolution = csolutionFactory ( ) ;
278+ mockCsolution . hasWestProject = jest . fn ( ) . mockReturnValue ( true ) ;
279+
280+ const mockSolutionManager = solutionManagerFactory ( {
281+ loadState : solutionLoadedState ,
282+ getCsolution : jest . fn ( ) . mockReturnValue ( mockCsolution ) ,
283+ } ) ;
284+
285+ const view = new SolutionOutlineView (
286+ mockSolutionManager ,
287+ mockTreeViewProvider ,
288+ globalStateProvider ,
289+ mockTreeViewFileDecorationProvider ,
290+ configurationProvider
291+ ) ;
292+
293+ await view . activate ( extensionContextFactory ( ) ) ;
294+ mockSolutionManager . onUpdatedCompileCommandsEmitter . fire ( ) ;
295+ await waitForPromises ( ) ;
296+
297+ expect ( mockTreeViewProvider . updateTree ) . toHaveBeenCalled ( ) ;
298+ } ) ;
299+
300+ it ( 'does not refresh the tree on compilation database update when no West project exists' , async ( ) => {
301+ const solutionLoadedState = activeSolutionLoadStateFactory ( ) ;
302+ const mockCsolution = csolutionFactory ( ) ;
303+ mockCsolution . hasWestProject = jest . fn ( ) . mockReturnValue ( false ) ;
304+
305+ const mockSolutionManager = solutionManagerFactory ( {
306+ loadState : solutionLoadedState ,
307+ getCsolution : jest . fn ( ) . mockReturnValue ( mockCsolution ) ,
308+ } ) ;
309+
310+ const view = new SolutionOutlineView (
311+ mockSolutionManager ,
312+ mockTreeViewProvider ,
313+ globalStateProvider ,
314+ mockTreeViewFileDecorationProvider ,
315+ configurationProvider
316+ ) ;
317+
318+ await view . activate ( extensionContextFactory ( ) ) ;
319+
320+ // Reset the mock to ensure it wasn't called during activation
321+ ( mockTreeViewProvider . updateTree as jest . Mock ) . mockClear ( ) ;
322+
323+ mockSolutionManager . onUpdatedCompileCommandsEmitter . fire ( ) ;
324+ await waitForPromises ( ) ;
325+
326+ expect ( mockTreeViewProvider . updateTree ) . not . toHaveBeenCalled ( ) ;
271327 } ) ;
272328
273329} ) ;
0 commit comments