Skip to content
Merged
Prev Previous commit
Next Next commit
updating tests to pass.
adding experimentName to old tryPlance test telemetry
  • Loading branch information
bschnurr committed Nov 13, 2020
commit 836ce7c7d6aaa13b83279a9a94def1113eb93d7e
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ suite('Propose Pylance Banner', () => {
let appEnv: typemoq.IMock<IApplicationEnvironment>;
let settings: typemoq.IMock<IPythonSettings>;
let sendTelemetryStub: sinon.SinonStub;
let telemetryEvent: { eventName: EventName; properties: { userAction: string } } | undefined;
let telemetryEvent:
| { eventName: EventName; properties: { userAction: string; experimentName: string } }
| undefined;

const message = Pylance.proposePylanceMessage();
const yes = Pylance.tryItNow();
Expand All @@ -66,7 +68,7 @@ suite('Propose Pylance Banner', () => {

sendTelemetryStub = sinon
.stub(Telemetry, 'sendTelemetryEvent')
.callsFake((eventName: EventName, _, properties: { userAction: string }) => {
.callsFake((eventName: EventName, _, properties: { userAction: string; experimentName: string }) => {
telemetryEvent = {
eventName,
properties
Expand Down Expand Up @@ -136,7 +138,7 @@ suite('Propose Pylance Banner', () => {
sinon.assert.calledOnce(sendTelemetryStub);
assert.deepEqual(telemetryEvent, {
eventName: EventName.LANGUAGE_SERVER_TRY_PYLANCE,
properties: { userAction: 'no' }
properties: { userAction: 'no', experimentName: TryPylance.experiment }
});
});
test('Clicking Later should disable banner in session', async () => {
Expand Down Expand Up @@ -166,7 +168,7 @@ suite('Propose Pylance Banner', () => {
assert.deepEqual(telemetryEvent, {
eventName: EventName.LANGUAGE_SERVER_TRY_PYLANCE,
properties: {
userAction: 'later'
userAction: 'later', experimentName: TryPylance.experiment
}
});
});
Expand Down Expand Up @@ -194,7 +196,8 @@ suite('Propose Pylance Banner', () => {
assert.deepEqual(telemetryEvent, {
eventName: EventName.LANGUAGE_SERVER_TRY_PYLANCE,
properties: {
userAction: 'yes'
userAction: 'yes',
experimentName: TryPylance.experiment
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import { assert, expect } from 'chai';
import * as sinon from 'sinon';
import { anything } from 'ts-mockito';
import * as typemoq from 'typemoq';
import { Extension } from 'vscode';
import { LanguageServerType } from '../../../client/activation/types';
Expand All @@ -31,22 +30,23 @@ import * as Telemetry from '../../../client/telemetry';
import { EventName } from '../../../client/telemetry/constants';

interface IExperimentLsCombination {
experiment: TryPylance;
experiment: TryPylance ;
lsType: LanguageServerType;
shouldShowBanner: boolean;
}
const testData: IExperimentLsCombination[] = [
{ experiment: TryPylance.jediPrompt1, lsType: LanguageServerType.None, shouldShowBanner: true },
{ experiment: TryPylance.jediPrompt1, lsType: LanguageServerType.Microsoft, shouldShowBanner: true },
// Expected Result is shouldShowBanner
{ experiment: TryPylance.jediPrompt1, lsType: LanguageServerType.None, shouldShowBanner: false },
{ experiment: TryPylance.jediPrompt1, lsType: LanguageServerType.Microsoft, shouldShowBanner: false },
{ experiment: TryPylance.jediPrompt1, lsType: LanguageServerType.Node, shouldShowBanner: false },
{ experiment: TryPylance.jediPrompt1, lsType: LanguageServerType.Jedi, shouldShowBanner: false },
{ experiment: TryPylance.jediPrompt1, lsType: LanguageServerType.Jedi, shouldShowBanner: true },
{ experiment: TryPylance.jediPrompt2, lsType: LanguageServerType.None, shouldShowBanner: false },
{ experiment: TryPylance.jediPrompt2, lsType: LanguageServerType.Microsoft, shouldShowBanner: false },
{ experiment: TryPylance.jediPrompt2, lsType: LanguageServerType.Node, shouldShowBanner: false },
{ experiment: TryPylance.jediPrompt2, lsType: LanguageServerType.Jedi, shouldShowBanner: false }
{ experiment: TryPylance.jediPrompt2, lsType: LanguageServerType.Jedi, shouldShowBanner: true }
];

suite('Propose Pylance Banner To Jedi', () => {
suite('Jedi Propose Pylance Banner', () => {
let config: typemoq.IMock<IConfigurationService>;
let appShell: typemoq.IMock<IApplicationShell>;
let appEnv: typemoq.IMock<IApplicationEnvironment>;
Expand All @@ -56,6 +56,7 @@ suite('Propose Pylance Banner To Jedi', () => {
| { eventName: EventName; properties: { userAction: string; experimentName: string } }
| undefined;

const message = 'Sample value1';
const yes = Pylance.tryItNow();
const no = Common.bannerLabelNo();
const later = Pylance.remindMeLater();
Expand Down Expand Up @@ -106,7 +107,7 @@ suite('Propose Pylance Banner To Jedi', () => {
appShell
.setup((a) =>
a.showInformationMessage(
anything(),
typemoq.It.isValue(message),
typemoq.It.isValue(yes),
typemoq.It.isValue(no),
typemoq.It.isValue(later)
Expand All @@ -128,7 +129,7 @@ suite('Propose Pylance Banner To Jedi', () => {
appShell
.setup((a) =>
a.showInformationMessage(
anything(),
typemoq.It.isValue(message),
typemoq.It.isValue(yes),
typemoq.It.isValue(no),
typemoq.It.isValue(later)
Expand All @@ -138,6 +139,8 @@ suite('Propose Pylance Banner To Jedi', () => {
.verifiable(typemoq.Times.once());
appShell.setup((a) => a.openUrl(getPylanceExtensionUri(appEnv.object))).verifiable(typemoq.Times.never());

settings.setup((x) => x.languageServer).returns(() => LanguageServerType.Jedi);

const testBanner = preparePopup(
true,
appShell.object,
Expand All @@ -161,7 +164,7 @@ suite('Propose Pylance Banner To Jedi', () => {
appShell
.setup((a) =>
a.showInformationMessage(
anything(),
typemoq.It.isValue(message),
typemoq.It.isValue(yes),
typemoq.It.isValue(no),
typemoq.It.isValue(later)
Expand All @@ -171,6 +174,8 @@ suite('Propose Pylance Banner To Jedi', () => {
.verifiable(typemoq.Times.once());
appShell.setup((a) => a.openUrl(getPylanceExtensionUri(appEnv.object))).verifiable(typemoq.Times.never());

settings.setup((x) => x.languageServer).returns(() => LanguageServerType.Jedi);

const testBanner = preparePopup(
true,
appShell.object,
Expand All @@ -189,7 +194,7 @@ suite('Propose Pylance Banner To Jedi', () => {

sinon.assert.calledOnce(sendTelemetryStub);
assert.deepEqual(telemetryEvent, {
eventName: EventName.BANNER_NAME_PROPOSE_LS_FOR_JEDI_USERS,
eventName: EventName.LANGUAGE_SERVER_TRY_PYLANCE,
properties: {
userAction: 'later',
experimentName: TryPylance.jediPrompt1
Expand All @@ -200,7 +205,7 @@ suite('Propose Pylance Banner To Jedi', () => {
appShell
.setup((a) =>
a.showInformationMessage(
anything(),
typemoq.It.isValue(message),
typemoq.It.isValue(yes),
typemoq.It.isValue(no),
typemoq.It.isValue(later)
Expand All @@ -210,6 +215,8 @@ suite('Propose Pylance Banner To Jedi', () => {
.verifiable(typemoq.Times.once());
appShell.setup((a) => a.openUrl(getPylanceExtensionUri(appEnv.object))).verifiable(typemoq.Times.once());

settings.setup((x) => x.languageServer).returns(() => LanguageServerType.Jedi);

const testBanner = preparePopup(
true,
appShell.object,
Expand All @@ -225,7 +232,7 @@ suite('Propose Pylance Banner To Jedi', () => {

sinon.assert.calledOnce(sendTelemetryStub);
assert.deepEqual(telemetryEvent, {
eventName: EventName.BANNER_NAME_PROPOSE_LS_FOR_JEDI_USERS,
eventName: EventName.LANGUAGE_SERVER_TRY_PYLANCE,
properties: {
userAction: 'yes',
experimentName: TryPylance.jediPrompt1
Expand Down