5
5
6
6
import { mock , when , anything , instance , verify , reset } from 'ts-mockito' ;
7
7
import { EventEmitter , Terminal , TerminalDataWriteEvent , Uri } from 'vscode' ;
8
- import { IApplicationShell } from '../../../client/common/application/types' ;
8
+ import { IApplicationEnvironment , IApplicationShell } from '../../../client/common/application/types' ;
9
9
import {
10
10
IBrowserService ,
11
11
IExperimentService ,
@@ -19,11 +19,13 @@ import { IInterpreterService } from '../../../client/interpreter/contracts';
19
19
import { PythonEnvironment } from '../../../client/pythonEnvironments/info' ;
20
20
import { TerminalDeactivateLimitationPrompt } from '../../../client/terminals/envCollectionActivation/deactivatePrompt' ;
21
21
import { PythonEnvType } from '../../../client/pythonEnvironments/base/info' ;
22
+ import { TerminalShellType } from '../../../client/common/terminal/types' ;
22
23
23
24
suite ( 'Terminal Deactivation Limitation Prompt' , ( ) => {
24
25
let shell : IApplicationShell ;
25
26
let experimentService : IExperimentService ;
26
27
let persistentStateFactory : IPersistentStateFactory ;
28
+ let appEnvironment : IApplicationEnvironment ;
27
29
let deactivatePrompt : TerminalDeactivateLimitationPrompt ;
28
30
let terminalWriteEvent : EventEmitter < TerminalDataWriteEvent > ;
29
31
let notificationEnabled : IPersistentState < boolean > ;
@@ -37,6 +39,8 @@ suite('Terminal Deactivation Limitation Prompt', () => {
37
39
interpreterService = mock < IInterpreterService > ( ) ;
38
40
experimentService = mock < IExperimentService > ( ) ;
39
41
persistentStateFactory = mock < IPersistentStateFactory > ( ) ;
42
+ appEnvironment = mock < IApplicationEnvironment > ( ) ;
43
+ when ( appEnvironment . shell ) . thenReturn ( 'bash' ) ;
40
44
browserService = mock < IBrowserService > ( ) ;
41
45
notificationEnabled = mock < IPersistentState < boolean > > ( ) ;
42
46
terminalWriteEvent = new EventEmitter < TerminalDataWriteEvent > ( ) ;
@@ -51,6 +55,7 @@ suite('Terminal Deactivation Limitation Prompt', () => {
51
55
[ ] ,
52
56
instance ( interpreterService ) ,
53
57
instance ( browserService ) ,
58
+ instance ( appEnvironment ) ,
54
59
instance ( experimentService ) ,
55
60
) ;
56
61
} ) ;
@@ -66,13 +71,35 @@ suite('Terminal Deactivation Limitation Prompt', () => {
66
71
when ( interpreterService . getActiveInterpreter ( anything ( ) ) ) . thenResolve ( ( {
67
72
type : PythonEnvType . Virtual ,
68
73
} as unknown ) as PythonEnvironment ) ;
69
- when ( shell . showInformationMessage ( expectedMessage , ...prompts ) ) . thenResolve ( undefined ) ;
74
+ when ( shell . showWarningMessage ( expectedMessage , ...prompts ) ) . thenResolve ( undefined ) ;
70
75
71
76
await deactivatePrompt . activate ( ) ;
72
77
terminalWriteEvent . fire ( { data : 'Please deactivate me' , terminal } ) ;
73
78
await sleep ( 1 ) ;
74
79
75
- verify ( shell . showInformationMessage ( expectedMessage , ...prompts ) ) . once ( ) ;
80
+ verify ( shell . showWarningMessage ( expectedMessage , ...prompts ) ) . once ( ) ;
81
+ } ) ;
82
+
83
+ test ( 'When using cmd, do not show notification for the same' , async ( ) => {
84
+ const resource = Uri . file ( 'a' ) ;
85
+ const terminal = ( {
86
+ creationOptions : {
87
+ cwd : resource ,
88
+ } ,
89
+ } as unknown ) as Terminal ;
90
+ reset ( appEnvironment ) ;
91
+ when ( appEnvironment . shell ) . thenReturn ( TerminalShellType . commandPrompt ) ;
92
+ when ( notificationEnabled . value ) . thenReturn ( true ) ;
93
+ when ( interpreterService . getActiveInterpreter ( anything ( ) ) ) . thenResolve ( ( {
94
+ type : PythonEnvType . Virtual ,
95
+ } as unknown ) as PythonEnvironment ) ;
96
+ when ( shell . showWarningMessage ( expectedMessage , ...prompts ) ) . thenResolve ( undefined ) ;
97
+
98
+ await deactivatePrompt . activate ( ) ;
99
+ terminalWriteEvent . fire ( { data : 'Please deactivate me' , terminal } ) ;
100
+ await sleep ( 1 ) ;
101
+
102
+ verify ( shell . showWarningMessage ( expectedMessage , ...prompts ) ) . once ( ) ;
76
103
} ) ;
77
104
78
105
test ( 'When not in experiment, do not show notification for the same' , async ( ) => {
@@ -88,13 +115,13 @@ suite('Terminal Deactivation Limitation Prompt', () => {
88
115
when ( interpreterService . getActiveInterpreter ( anything ( ) ) ) . thenResolve ( ( {
89
116
type : PythonEnvType . Virtual ,
90
117
} as unknown ) as PythonEnvironment ) ;
91
- when ( shell . showInformationMessage ( expectedMessage , ...prompts ) ) . thenResolve ( undefined ) ;
118
+ when ( shell . showWarningMessage ( expectedMessage , ...prompts ) ) . thenResolve ( undefined ) ;
92
119
93
120
await deactivatePrompt . activate ( ) ;
94
121
terminalWriteEvent . fire ( { data : 'Please deactivate me' , terminal } ) ;
95
122
await sleep ( 1 ) ;
96
123
97
- verify ( shell . showInformationMessage ( expectedMessage , ...prompts ) ) . never ( ) ;
124
+ verify ( shell . showWarningMessage ( expectedMessage , ...prompts ) ) . never ( ) ;
98
125
} ) ;
99
126
100
127
test ( 'Do not show notification if notification is disabled' , async ( ) => {
@@ -108,13 +135,13 @@ suite('Terminal Deactivation Limitation Prompt', () => {
108
135
when ( interpreterService . getActiveInterpreter ( anything ( ) ) ) . thenResolve ( ( {
109
136
type : PythonEnvType . Virtual ,
110
137
} as unknown ) as PythonEnvironment ) ;
111
- when ( shell . showInformationMessage ( expectedMessage , ...prompts ) ) . thenResolve ( undefined ) ;
138
+ when ( shell . showWarningMessage ( expectedMessage , ...prompts ) ) . thenResolve ( undefined ) ;
112
139
113
140
await deactivatePrompt . activate ( ) ;
114
141
terminalWriteEvent . fire ( { data : 'Please deactivate me' , terminal } ) ;
115
142
await sleep ( 1 ) ;
116
143
117
- verify ( shell . showInformationMessage ( expectedMessage , ...prompts ) ) . never ( ) ;
144
+ verify ( shell . showWarningMessage ( expectedMessage , ...prompts ) ) . never ( ) ;
118
145
} ) ;
119
146
120
147
test ( 'Do not show notification when virtual env is not activated for terminal' , async ( ) => {
@@ -128,13 +155,13 @@ suite('Terminal Deactivation Limitation Prompt', () => {
128
155
when ( interpreterService . getActiveInterpreter ( anything ( ) ) ) . thenResolve ( ( {
129
156
type : PythonEnvType . Conda ,
130
157
} as unknown ) as PythonEnvironment ) ;
131
- when ( shell . showInformationMessage ( expectedMessage , ...prompts ) ) . thenResolve ( undefined ) ;
158
+ when ( shell . showWarningMessage ( expectedMessage , ...prompts ) ) . thenResolve ( undefined ) ;
132
159
133
160
await deactivatePrompt . activate ( ) ;
134
161
terminalWriteEvent . fire ( { data : 'Please deactivate me' , terminal } ) ;
135
162
await sleep ( 1 ) ;
136
163
137
- verify ( shell . showInformationMessage ( expectedMessage , ...prompts ) ) . never ( ) ;
164
+ verify ( shell . showWarningMessage ( expectedMessage , ...prompts ) ) . never ( ) ;
138
165
} ) ;
139
166
140
167
test ( "Disable notification if `Don't show again` is clicked" , async ( ) => {
@@ -148,9 +175,7 @@ suite('Terminal Deactivation Limitation Prompt', () => {
148
175
when ( interpreterService . getActiveInterpreter ( anything ( ) ) ) . thenResolve ( ( {
149
176
type : PythonEnvType . Virtual ,
150
177
} as unknown ) as PythonEnvironment ) ;
151
- when ( shell . showInformationMessage ( expectedMessage , ...prompts ) ) . thenReturn (
152
- Promise . resolve ( Common . doNotShowAgain ) ,
153
- ) ;
178
+ when ( shell . showWarningMessage ( expectedMessage , ...prompts ) ) . thenReturn ( Promise . resolve ( Common . doNotShowAgain ) ) ;
154
179
155
180
await deactivatePrompt . activate ( ) ;
156
181
terminalWriteEvent . fire ( { data : 'Please deactivate me' , terminal } ) ;
@@ -170,15 +195,13 @@ suite('Terminal Deactivation Limitation Prompt', () => {
170
195
when ( interpreterService . getActiveInterpreter ( anything ( ) ) ) . thenResolve ( ( {
171
196
type : PythonEnvType . Virtual ,
172
197
} as unknown ) as PythonEnvironment ) ;
173
- when ( shell . showInformationMessage ( expectedMessage , ...prompts ) ) . thenReturn (
174
- Promise . resolve ( Common . seeInstructions ) ,
175
- ) ;
198
+ when ( shell . showWarningMessage ( expectedMessage , ...prompts ) ) . thenReturn ( Promise . resolve ( Common . seeInstructions ) ) ;
176
199
177
200
await deactivatePrompt . activate ( ) ;
178
201
terminalWriteEvent . fire ( { data : 'Please deactivate me' , terminal } ) ;
179
202
await sleep ( 1 ) ;
180
203
181
- verify ( shell . showInformationMessage ( expectedMessage , ...prompts ) ) . once ( ) ;
204
+ verify ( shell . showWarningMessage ( expectedMessage , ...prompts ) ) . once ( ) ;
182
205
verify ( browserService . launch ( anything ( ) ) ) . once ( ) ;
183
206
} ) ;
184
207
@@ -193,13 +216,13 @@ suite('Terminal Deactivation Limitation Prompt', () => {
193
216
when ( interpreterService . getActiveInterpreter ( anything ( ) ) ) . thenResolve ( ( {
194
217
type : PythonEnvType . Virtual ,
195
218
} as unknown ) as PythonEnvironment ) ;
196
- when ( shell . showInformationMessage ( expectedMessage , ...prompts ) ) . thenResolve ( undefined ) ;
219
+ when ( shell . showWarningMessage ( expectedMessage , ...prompts ) ) . thenResolve ( undefined ) ;
197
220
198
221
await deactivatePrompt . activate ( ) ;
199
222
terminalWriteEvent . fire ( { data : 'Please deactivate me' , terminal } ) ;
200
223
await sleep ( 1 ) ;
201
224
202
- verify ( shell . showInformationMessage ( expectedMessage , ...prompts ) ) . once ( ) ;
225
+ verify ( shell . showWarningMessage ( expectedMessage , ...prompts ) ) . once ( ) ;
203
226
verify ( notificationEnabled . updateValue ( false ) ) . never ( ) ;
204
227
verify ( browserService . launch ( anything ( ) ) ) . never ( ) ;
205
228
} ) ;
0 commit comments