Skip to content

Commit

Permalink
Other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Jul 24, 2018
1 parent 23f3391 commit 7d83013
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
20 changes: 13 additions & 7 deletions src/vs/platform/telemetry/common/telemetryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }>;
Expand Down Expand Up @@ -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<any>(TELEMETRY_SECTION_ID);
this._userOptIn = config ? config.enableTelemetry : this._userOptIn;
this._userOptIn = config.telemetry.enableTelemetry === true;
}

get isOptedIn(): boolean {
Expand Down Expand Up @@ -159,11 +168,8 @@ export class TelemetryService implements ITelemetryService {
}
}


const TELEMETRY_SECTION_ID = 'telemetry';

Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfiguration({
'id': TELEMETRY_SECTION_ID,
'id': 'telemetry',
'order': 110,
'type': 'object',
'title': localize('telemetryConfigurationTitle', "Telemetry"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ suite('TelemetryService', () => {
test('Telemetry Service checks with config service', function () {

let enableTelemetry = false;
let enableOfflineMode = false;
let emitter = new Emitter<any>();

let testAppender = new TestTelemetryAppender();
Expand All @@ -739,7 +740,12 @@ suite('TelemetryService', () => {
_serviceBrand: undefined,
getValue() {
return {
enableTelemetry: enableTelemetry
telemetry: {
enableTelemetry: enableTelemetry
},
workbench: {
enableOfflineMode: enableOfflineMode
}
} as any;
},
updateValue(): TPromise<void> {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, <IModelService>{
getModels(): any { return []; },
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,7 @@ suite('ExtensionsWorkbenchServiceTest', () => {
onDidUpdateConfiguration: () => { },
onDidChangeConfiguration: () => { },
getConfiguration: () => ({}),
getValue: (s) => {
if (s === 'workbench.enableOfflineMode') {
return false;
}
return undefined;
}
getValue: () => { }
});

instantiationService.stub(IExtensionManagementService, ExtensionManagementService);
Expand Down

0 comments on commit 7d83013

Please sign in to comment.