@@ -6,10 +6,10 @@ import { expect } from 'chai';
6
6
import { anything , instance , mock , verify , when } from 'ts-mockito' ;
7
7
import * as TypeMoq from 'typemoq' ;
8
8
import { Terminal , Uri } from 'vscode' ;
9
- import { DocumentManager } from '../../../client/common/application/documentManager' ;
9
+ import { ActiveResourceService } from '../../../client/activation/activeResource' ;
10
+ import { IActiveResourceService } from '../../../client/activation/types' ;
10
11
import { TerminalManager } from '../../../client/common/application/terminalManager' ;
11
- import { IDocumentManager , ITerminalManager , IWorkspaceService } from '../../../client/common/application/types' ;
12
- import { WorkspaceService } from '../../../client/common/application/workspace' ;
12
+ import { ITerminalManager } from '../../../client/common/application/types' ;
13
13
import { TerminalActivator } from '../../../client/common/terminal/activator' ;
14
14
import { ITerminalActivator } from '../../../client/common/terminal/types' ;
15
15
import { IDisposable } from '../../../client/common/types' ;
@@ -18,23 +18,21 @@ import { ITerminalAutoActivation } from '../../../client/terminals/types';
18
18
19
19
suite ( 'Terminal Auto Activation' , ( ) => {
20
20
let activator : ITerminalActivator ;
21
- let documentManager : IDocumentManager ;
22
21
let terminalManager : ITerminalManager ;
23
22
let terminalAutoActivation : ITerminalAutoActivation ;
24
- let workspaceService : IWorkspaceService ;
23
+ let activeResourceService : IActiveResourceService ;
24
+ const resource = Uri . parse ( 'a' ) ;
25
25
26
26
setup ( ( ) => {
27
27
terminalManager = mock ( TerminalManager ) ;
28
- documentManager = mock ( DocumentManager ) ;
29
28
activator = mock ( TerminalActivator ) ;
30
- workspaceService = mock ( WorkspaceService ) ;
29
+ activeResourceService = mock ( ActiveResourceService ) ;
31
30
32
31
terminalAutoActivation = new TerminalAutoActivation (
33
32
instance ( terminalManager ) ,
34
33
[ ] ,
35
- instance ( documentManager ) ,
36
34
instance ( activator ) ,
37
- instance ( workspaceService )
35
+ instance ( activeResourceService )
38
36
) ;
39
37
} ) ;
40
38
@@ -47,17 +45,17 @@ suite('Terminal Auto Activation', () => {
47
45
handler = cb ;
48
46
return handlerDisposable . object ;
49
47
} ;
48
+ when ( activeResourceService . getActiveResource ( ) ) . thenReturn ( resource ) ;
50
49
when ( terminalManager . onDidOpenTerminal ) . thenReturn ( onDidOpenTerminal ) ;
51
50
when ( activator . activateEnvironmentInTerminal ( anything ( ) , anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
52
- when ( workspaceService . hasWorkspaceFolders ) . thenReturn ( false ) ;
53
51
54
52
terminalAutoActivation . register ( ) ;
55
53
56
54
expect ( handler ) . not . to . be . an ( 'undefined' , 'event handler not initialized' ) ;
57
55
58
56
handler ! . bind ( terminalAutoActivation ) ( terminal . object ) ;
59
57
60
- verify ( activator . activateEnvironmentInTerminal ( terminal . object , undefined ) ) . once ( ) ;
58
+ verify ( activator . activateEnvironmentInTerminal ( terminal . object , resource ) ) . once ( ) ;
61
59
} ) ;
62
60
test ( 'New Terminals should be activated with resource of single workspace' , async ( ) => {
63
61
type EventHandler = ( e : Terminal ) => void ;
@@ -68,11 +66,9 @@ suite('Terminal Auto Activation', () => {
68
66
handler = cb ;
69
67
return handlerDisposable . object ;
70
68
} ;
71
- const resource = Uri . file ( __filename ) ;
69
+ when ( activeResourceService . getActiveResource ( ) ) . thenReturn ( resource ) ;
72
70
when ( terminalManager . onDidOpenTerminal ) . thenReturn ( onDidOpenTerminal ) ;
73
71
when ( activator . activateEnvironmentInTerminal ( anything ( ) , anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
74
- when ( workspaceService . hasWorkspaceFolders ) . thenReturn ( true ) ;
75
- when ( workspaceService . workspaceFolders ) . thenReturn ( [ { index : 0 , name : '' , uri : resource } ] ) ;
76
72
77
73
terminalAutoActivation . register ( ) ;
78
74
@@ -91,15 +87,9 @@ suite('Terminal Auto Activation', () => {
91
87
handler = cb ;
92
88
return handlerDisposable . object ;
93
89
} ;
94
- const resource = Uri . file ( __filename ) ;
90
+ when ( activeResourceService . getActiveResource ( ) ) . thenReturn ( resource ) ;
95
91
when ( terminalManager . onDidOpenTerminal ) . thenReturn ( onDidOpenTerminal ) ;
96
92
when ( activator . activateEnvironmentInTerminal ( anything ( ) , anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
97
- when ( workspaceService . hasWorkspaceFolders ) . thenReturn ( true ) ;
98
- when ( workspaceService . workspaceFolders ) . thenReturn ( [
99
- { index : 0 , name : '' , uri : resource } ,
100
- { index : 2 , name : '2' , uri : Uri . file ( '1234' ) }
101
- ] ) ;
102
-
103
93
terminalAutoActivation . register ( ) ;
104
94
105
95
expect ( handler ) . not . to . be . an ( 'undefined' , 'event handler not initialized' ) ;
0 commit comments