From 7d83013ac85be712e9e32020d251df85a55b190c Mon Sep 17 00:00:00 2001 From: Ramya Achutha Rao Date: Tue, 24 Jul 2018 15:49:43 -0700 Subject: [PATCH] Other tests --- .../telemetry/common/telemetryService.ts | 20 ++++++++++++------- .../electron-browser/telemetryService.test.ts | 16 ++++++++++++++- .../extensionsTipsService.test.ts | 12 +++++++++++ .../extensionsWorkbenchService.test.ts | 7 +------ 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/vs/platform/telemetry/common/telemetryService.ts b/src/vs/platform/telemetry/common/telemetryService.ts index 6ad7486239759..4618cfcc89781 100644 --- a/src/vs/platform/telemetry/common/telemetryService.ts +++ b/src/vs/platform/telemetry/common/telemetryService.ts @@ -17,6 +17,15 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { cloneAndChange, mixin } from 'vs/base/common/objects'; import { Registry } from 'vs/platform/registry/common/platform'; +interface ITelemetryConfig { + telemetry: { + enableTelemetry?: boolean; + }; + workbench: { + enableOfflineMode?: boolean + }; +} + export interface ITelemetryServiceConfig { appender: ITelemetryAppender; commonProperties?: TPromise<{ [name: string]: any }>; @@ -67,12 +76,12 @@ export class TelemetryService implements ITelemetryService { } private _updateUserOptIn(): void { - if (this._configurationService.getValue('workbench.enableOfflineMode') === true) { + const config: ITelemetryConfig = this._configurationService.getValue(); + if (config.workbench.enableOfflineMode === true) { this._userOptIn = false; return; } - const config = this._configurationService.getValue(TELEMETRY_SECTION_ID); - this._userOptIn = config ? config.enableTelemetry : this._userOptIn; + this._userOptIn = config.telemetry.enableTelemetry === true; } get isOptedIn(): boolean { @@ -159,11 +168,8 @@ export class TelemetryService implements ITelemetryService { } } - -const TELEMETRY_SECTION_ID = 'telemetry'; - Registry.as(Extensions.Configuration).registerConfiguration({ - 'id': TELEMETRY_SECTION_ID, + 'id': 'telemetry', 'order': 110, 'type': 'object', 'title': localize('telemetryConfigurationTitle', "Telemetry"), diff --git a/src/vs/platform/telemetry/test/electron-browser/telemetryService.test.ts b/src/vs/platform/telemetry/test/electron-browser/telemetryService.test.ts index 8cd91f0803bf0..2473e61337143 100644 --- a/src/vs/platform/telemetry/test/electron-browser/telemetryService.test.ts +++ b/src/vs/platform/telemetry/test/electron-browser/telemetryService.test.ts @@ -730,6 +730,7 @@ suite('TelemetryService', () => { test('Telemetry Service checks with config service', function () { let enableTelemetry = false; + let enableOfflineMode = false; let emitter = new Emitter(); let testAppender = new TestTelemetryAppender(); @@ -739,7 +740,12 @@ suite('TelemetryService', () => { _serviceBrand: undefined, getValue() { return { - enableTelemetry: enableTelemetry + telemetry: { + enableTelemetry: enableTelemetry + }, + workbench: { + enableOfflineMode: enableOfflineMode + } } as any; }, updateValue(): TPromise { @@ -766,6 +772,14 @@ suite('TelemetryService', () => { emitter.fire({}); assert.equal(service.isOptedIn, true); + enableOfflineMode = true; + emitter.fire({}); + assert.equal(service.isOptedIn, false); + + enableOfflineMode = false; + emitter.fire({}); + assert.equal(service.isOptedIn, true); + enableTelemetry = false; emitter.fire({}); assert.equal(service.isOptedIn, false); diff --git a/src/vs/workbench/parts/extensions/test/electron-browser/extensionsTipsService.test.ts b/src/vs/workbench/parts/extensions/test/electron-browser/extensionsTipsService.test.ts index 89cbd28c3d693..a58939341f699 100644 --- a/src/vs/workbench/parts/extensions/test/electron-browser/extensionsTipsService.test.ts +++ b/src/vs/workbench/parts/extensions/test/electron-browser/extensionsTipsService.test.ts @@ -245,6 +245,7 @@ suite('ExtensionsTipsService Test', () => { instantiationService.stub(INotificationService, new TestNotificationService2()); testConfigurationService.setUserConfiguration(ConfigurationKey, { ignoreRecommendations: false, showRecommendationsOnlyOnDemand: false }); + testConfigurationService.setUserConfiguration('workbench', { enableOfflineMode: false }); instantiationService.stub(IStorageService, { get: (a, b, c) => c, getBoolean: (a, b, c) => c, store: () => { } }); instantiationService.stub(IModelService, { getModels(): any { return []; }, @@ -366,6 +367,17 @@ suite('ExtensionsTipsService Test', () => { }); }); + test('ExtensionTipsService: No Prompt for valid workspace recommendations if offline is set', () => { + testConfigurationService.setUserConfiguration('workbench', { enableOfflineMode: true }); + return setUpFolderWorkspace('myFolder', mockTestData.validRecommendedExtensions).then(() => { + testObject = instantiationService.createInstance(ExtensionTipsService); + return testObject.loadWorkspaceConfigPromise.then(() => { + assert.equal(Object.keys(testObject.getAllRecommendationsWithReason()).length, 0); + assert.ok(!prompted); + }); + }); + }); + test('ExtensionTipsService: No Prompt for valid workspace recommendations if ignoreRecommendations is set for current workspace', () => { instantiationService.stub(IStorageService, { get: (a, b, c) => c, getBoolean: (a, b, c) => a === 'extensionsAssistant/workspaceRecommendationsIgnore' || c }); return testNoPromptForValidRecommendations(mockTestData.validRecommendedExtensions); diff --git a/src/vs/workbench/parts/extensions/test/electron-browser/extensionsWorkbenchService.test.ts b/src/vs/workbench/parts/extensions/test/electron-browser/extensionsWorkbenchService.test.ts index 85f5eb1d13198..c8d72f917df38 100644 --- a/src/vs/workbench/parts/extensions/test/electron-browser/extensionsWorkbenchService.test.ts +++ b/src/vs/workbench/parts/extensions/test/electron-browser/extensionsWorkbenchService.test.ts @@ -70,12 +70,7 @@ suite('ExtensionsWorkbenchServiceTest', () => { onDidUpdateConfiguration: () => { }, onDidChangeConfiguration: () => { }, getConfiguration: () => ({}), - getValue: (s) => { - if (s === 'workbench.enableOfflineMode') { - return false; - } - return undefined; - } + getValue: () => { } }); instantiationService.stub(IExtensionManagementService, ExtensionManagementService);