2
2
// Licensed under the MIT License.
3
3
4
4
'use strict' ;
5
-
6
- import { expect } from 'chai ' ;
5
+ import { assert , expect } from 'chai' ;
6
+ import * as sinon from 'sinon ' ;
7
7
import * as typemoq from 'typemoq' ;
8
8
import { Extension } from 'vscode' ;
9
9
import { LanguageServerType } from '../../../client/activation/types' ;
@@ -24,6 +24,8 @@ import {
24
24
ProposeLSStateKeys ,
25
25
ProposePylanceBanner
26
26
} from '../../../client/languageServices/proposeLanguageServerBanner' ;
27
+ import * as Telemetry from '../../../client/telemetry' ;
28
+ import { EventName } from '../../../client/telemetry/constants' ;
27
29
28
30
interface IExperimentLsCombination {
29
31
inExperiment : boolean ;
@@ -46,6 +48,8 @@ suite('Propose Pylance Banner', () => {
46
48
let appShell : typemoq . IMock < IApplicationShell > ;
47
49
let appEnv : typemoq . IMock < IApplicationEnvironment > ;
48
50
let settings : typemoq . IMock < IPythonSettings > ;
51
+ let sendTelemetryStub : sinon . SinonStub ;
52
+ let telemetryEvent : { eventName : EventName ; properties : { userAction : string } } | undefined ;
49
53
50
54
const message = Pylance . proposePylanceMessage ( ) ;
51
55
const yes = Pylance . tryItNow ( ) ;
@@ -59,7 +63,23 @@ suite('Propose Pylance Banner', () => {
59
63
appShell = typemoq . Mock . ofType < IApplicationShell > ( ) ;
60
64
appEnv = typemoq . Mock . ofType < IApplicationEnvironment > ( ) ;
61
65
appEnv . setup ( ( x ) => x . uriScheme ) . returns ( ( ) => 'scheme' ) ;
66
+
67
+ sendTelemetryStub = sinon
68
+ . stub ( Telemetry , 'sendTelemetryEvent' )
69
+ . callsFake ( ( eventName : EventName , _ , properties : { userAction : string } ) => {
70
+ telemetryEvent = {
71
+ eventName,
72
+ properties
73
+ } ;
74
+ } ) ;
75
+ } ) ;
76
+
77
+ teardown ( ( ) => {
78
+ telemetryEvent = undefined ;
79
+ sinon . restore ( ) ;
80
+ Telemetry . _resetSharedProperties ( ) ;
62
81
} ) ;
82
+
63
83
testData . forEach ( ( t ) => {
64
84
test ( `${ t . inExperiment ? 'In' : 'Not in' } experiment and "python.languageServer": "${ t . lsType } " should ${
65
85
t . shouldShowBanner ? 'show' : 'not show'
@@ -109,8 +129,15 @@ suite('Propose Pylance Banner', () => {
109
129
110
130
const testBanner = preparePopup ( true , appShell . object , appEnv . object , config . object , true , false ) ;
111
131
await testBanner . showBanner ( ) ;
132
+
112
133
expect ( testBanner . enabled ) . to . be . equal ( false , 'Banner should be permanently disabled when user clicked No' ) ;
113
134
appShell . verifyAll ( ) ;
135
+
136
+ sinon . assert . calledOnce ( sendTelemetryStub ) ;
137
+ assert . deepEqual ( telemetryEvent , {
138
+ eventName : EventName . LANGUAGE_SERVER_TRY_PYLANCE ,
139
+ properties : { userAction : 'no' }
140
+ } ) ;
114
141
} ) ;
115
142
test ( 'Clicking Later should disable banner in session' , async ( ) => {
116
143
appShell
@@ -128,11 +155,20 @@ suite('Propose Pylance Banner', () => {
128
155
129
156
const testBanner = preparePopup ( true , appShell . object , appEnv . object , config . object , true , false ) ;
130
157
await testBanner . showBanner ( ) ;
158
+
131
159
expect ( testBanner . enabled ) . to . be . equal (
132
160
true ,
133
161
'Banner should not be permanently disabled when user clicked Later'
134
162
) ;
135
163
appShell . verifyAll ( ) ;
164
+
165
+ sinon . assert . calledOnce ( sendTelemetryStub ) ;
166
+ assert . deepEqual ( telemetryEvent , {
167
+ eventName : EventName . LANGUAGE_SERVER_TRY_PYLANCE ,
168
+ properties : {
169
+ userAction : 'later'
170
+ }
171
+ } ) ;
136
172
} ) ;
137
173
test ( 'Clicking Yes opens the extension marketplace entry' , async ( ) => {
138
174
appShell
@@ -150,8 +186,17 @@ suite('Propose Pylance Banner', () => {
150
186
151
187
const testBanner = preparePopup ( true , appShell . object , appEnv . object , config . object , true , false ) ;
152
188
await testBanner . showBanner ( ) ;
189
+
153
190
expect ( testBanner . enabled ) . to . be . equal ( false , 'Banner should be permanently disabled after opening store URL' ) ;
154
191
appShell . verifyAll ( ) ;
192
+
193
+ sinon . assert . calledOnce ( sendTelemetryStub ) ;
194
+ assert . deepEqual ( telemetryEvent , {
195
+ eventName : EventName . LANGUAGE_SERVER_TRY_PYLANCE ,
196
+ properties : {
197
+ userAction : 'yes'
198
+ }
199
+ } ) ;
155
200
} ) ;
156
201
} ) ;
157
202
0 commit comments