-
Notifications
You must be signed in to change notification settings - Fork 29.5k
/
extensionsViews.test.ts
584 lines (511 loc) · 31.8 KB
/
extensionsViews.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { generateUuid } from 'vs/base/common/uuid';
import { ExtensionsListView } from 'vs/workbench/contrib/extensions/browser/extensionsViews';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { IExtensionsWorkbenchService } from 'vs/workbench/contrib/extensions/common/extensions';
import { ExtensionsWorkbenchService } from 'vs/workbench/contrib/extensions/browser/extensionsWorkbenchService';
import {
IExtensionManagementService, IExtensionGalleryService, ILocalExtension, IGalleryExtension, IQueryOptions,
DidUninstallExtensionEvent, InstallExtensionEvent, InstallExtensionResult, getTargetPlatform, IExtensionInfo, UninstallExtensionEvent, SortBy
} from 'vs/platform/extensionManagement/common/extensionManagement';
import { IWorkbenchExtensionEnablementService, EnablementState, IExtensionManagementServerService, IExtensionManagementServer, IProfileAwareExtensionManagementService, IWorkbenchExtensionManagementService } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
import { IExtensionRecommendationsService, ExtensionRecommendationReason } from 'vs/workbench/services/extensionRecommendations/common/extensionRecommendations';
import { getGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { TestExtensionEnablementService } from 'vs/workbench/services/extensionManagement/test/browser/extensionEnablementService.test';
import { ExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionGalleryService';
import { IURLService } from 'vs/platform/url/common/url';
import { Emitter, Event } from 'vs/base/common/event';
import { IPager } from 'vs/base/common/paging';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { IExtensionService, toExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { TestMenuService } from 'vs/workbench/test/browser/workbenchTestServices';
import { TestSharedProcessService } from 'vs/workbench/test/electron-sandbox/workbenchTestServices';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ILogService, NullLogService } from 'vs/platform/log/common/log';
import { NativeURLService } from 'vs/platform/url/common/urlService';
import { URI } from 'vs/base/common/uri';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { SinonStub } from 'sinon';
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
import { RemoteAgentService } from 'vs/workbench/services/remote/electron-sandbox/remoteAgentService';
import { ExtensionType, IExtension } from 'vs/platform/extensions/common/extensions';
import { ISharedProcessService } from 'vs/platform/ipc/electron-sandbox/services';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
import { IMenuService } from 'vs/platform/actions/common/actions';
import { TestContextService } from 'vs/workbench/test/common/workbenchTestServices';
import { IViewDescriptorService, ViewContainerLocation } from 'vs/workbench/common/views';
import { Schemas } from 'vs/base/common/network';
import { platform } from 'vs/base/common/platform';
import { arch } from 'vs/base/common/process';
import { IProductService } from 'vs/platform/product/common/productService';
import { CancellationToken } from 'vs/base/common/cancellation';
suite('ExtensionsViews Tests', () => {
let instantiationService: TestInstantiationService;
let testableView: ExtensionsListView;
let installEvent: Emitter<InstallExtensionEvent>,
didInstallEvent: Emitter<readonly InstallExtensionResult[]>,
uninstallEvent: Emitter<UninstallExtensionEvent>,
didUninstallEvent: Emitter<DidUninstallExtensionEvent>;
const localEnabledTheme = aLocalExtension('first-enabled-extension', { categories: ['Themes', 'random'] }, { installedTimestamp: 123456 });
const localEnabledLanguage = aLocalExtension('second-enabled-extension', { categories: ['Programming languages'], version: '1.0.0' }, { installedTimestamp: Date.now(), updated: false });
const localDisabledTheme = aLocalExtension('first-disabled-extension', { categories: ['themes'] }, { installedTimestamp: 234567 });
const localDisabledLanguage = aLocalExtension('second-disabled-extension', { categories: ['programming languages'] }, { installedTimestamp: Date.now() - 50000, updated: true });
const localRandom = aLocalExtension('random-enabled-extension', { categories: ['random'] }, { installedTimestamp: 345678 });
const builtInTheme = aLocalExtension('my-theme', { contributes: { themes: ['my-theme'] } }, { type: ExtensionType.System, installedTimestamp: 222 });
const builtInBasic = aLocalExtension('my-lang', { contributes: { grammars: [{ language: 'my-language' }] } }, { type: ExtensionType.System, installedTimestamp: 666666 });
const galleryEnabledLanguage = aGalleryExtension(localEnabledLanguage.manifest.name, { ...localEnabledLanguage.manifest, version: '1.0.1', identifier: localDisabledLanguage.identifier });
const workspaceRecommendationA = aGalleryExtension('workspace-recommendation-A');
const workspaceRecommendationB = aGalleryExtension('workspace-recommendation-B');
const configBasedRecommendationA = aGalleryExtension('configbased-recommendation-A');
const configBasedRecommendationB = aGalleryExtension('configbased-recommendation-B');
const fileBasedRecommendationA = aGalleryExtension('filebased-recommendation-A');
const fileBasedRecommendationB = aGalleryExtension('filebased-recommendation-B');
const otherRecommendationA = aGalleryExtension('other-recommendation-A');
suiteSetup(() => {
installEvent = new Emitter<InstallExtensionEvent>();
didInstallEvent = new Emitter<readonly InstallExtensionResult[]>();
uninstallEvent = new Emitter<UninstallExtensionEvent>();
didUninstallEvent = new Emitter<DidUninstallExtensionEvent>();
instantiationService = new TestInstantiationService();
instantiationService.stub(ITelemetryService, NullTelemetryService);
instantiationService.stub(ILogService, NullLogService);
instantiationService.stub(IProductService, {});
instantiationService.stub(IWorkspaceContextService, new TestContextService());
instantiationService.stub(IConfigurationService, new TestConfigurationService());
instantiationService.stub(IExtensionGalleryService, ExtensionGalleryService);
instantiationService.stub(ISharedProcessService, TestSharedProcessService);
instantiationService.stub(IExtensionManagementService, <Partial<IExtensionManagementService>>{
onInstallExtension: installEvent.event,
onDidInstallExtensions: didInstallEvent.event,
onUninstallExtension: uninstallEvent.event,
onDidUninstallExtension: didUninstallEvent.event,
onDidChangeProfile: Event.None,
onDidUpdateExtensionMetadata: Event.None,
async getInstalled() { return []; },
async canInstall() { return true; },
async getExtensionsControlManifest() { return { malicious: [], deprecated: {}, search: [] }; },
async getTargetPlatform() { return getTargetPlatform(platform, arch); },
async updateMetadata(local) { return local; }
});
instantiationService.stub(IRemoteAgentService, RemoteAgentService);
instantiationService.stub(IContextKeyService, new MockContextKeyService());
instantiationService.stub(IMenuService, new TestMenuService());
const localExtensionManagementServer = { extensionManagementService: instantiationService.get(IExtensionManagementService) as IProfileAwareExtensionManagementService, label: 'local', id: 'vscode-local' };
instantiationService.stub(IExtensionManagementServerService, <Partial<IExtensionManagementServerService>>{
get localExtensionManagementServer(): IExtensionManagementServer {
return localExtensionManagementServer;
},
getExtensionManagementServer(extension: IExtension): IExtensionManagementServer | null {
if (extension.location.scheme === Schemas.file) {
return localExtensionManagementServer;
}
throw new Error(`Invalid Extension ${extension.location}`);
}
});
instantiationService.stub(IWorkbenchExtensionEnablementService, new TestExtensionEnablementService(instantiationService));
const reasons: { [key: string]: any } = {};
reasons[workspaceRecommendationA.identifier.id] = { reasonId: ExtensionRecommendationReason.Workspace };
reasons[workspaceRecommendationB.identifier.id] = { reasonId: ExtensionRecommendationReason.Workspace };
reasons[fileBasedRecommendationA.identifier.id] = { reasonId: ExtensionRecommendationReason.File };
reasons[fileBasedRecommendationB.identifier.id] = { reasonId: ExtensionRecommendationReason.File };
reasons[otherRecommendationA.identifier.id] = { reasonId: ExtensionRecommendationReason.Executable };
reasons[configBasedRecommendationA.identifier.id] = { reasonId: ExtensionRecommendationReason.WorkspaceConfig };
instantiationService.stub(IExtensionRecommendationsService, <Partial<IExtensionRecommendationsService>>{
getWorkspaceRecommendations() {
return Promise.resolve([
workspaceRecommendationA.identifier.id,
workspaceRecommendationB.identifier.id]);
},
getConfigBasedRecommendations() {
return Promise.resolve({
important: [configBasedRecommendationA.identifier.id],
others: [configBasedRecommendationB.identifier.id],
});
},
getImportantRecommendations(): Promise<string[]> {
return Promise.resolve([]);
},
getFileBasedRecommendations() {
return [
fileBasedRecommendationA.identifier.id,
fileBasedRecommendationB.identifier.id
];
},
getOtherRecommendations() {
return Promise.resolve([
configBasedRecommendationB.identifier.id,
otherRecommendationA.identifier.id
]);
},
getAllRecommendationsWithReason() {
return reasons;
}
});
instantiationService.stub(IURLService, NativeURLService);
});
setup(async () => {
instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [localEnabledTheme, localEnabledLanguage, localRandom, localDisabledTheme, localDisabledLanguage, builtInTheme, builtInBasic]);
instantiationService.stubPromise(IExtensionManagementService, 'getExtensgetExtensionsControlManifestionsReport', {});
instantiationService.stub(IExtensionGalleryService, 'isEnabled', true);
instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(galleryEnabledLanguage));
instantiationService.stubPromise(IExtensionGalleryService, 'getCompatibleExtension', galleryEnabledLanguage);
instantiationService.stubPromise(IExtensionGalleryService, 'getExtensions', [galleryEnabledLanguage]);
instantiationService.stub(IViewDescriptorService, {
getViewLocationById(): ViewContainerLocation {
return ViewContainerLocation.Sidebar;
},
onDidChangeLocation: Event.None
});
instantiationService.stub(IExtensionService, <Partial<IExtensionService>>{
onDidChangeExtensions: Event.None,
extensions: [
toExtensionDescription(localEnabledTheme),
toExtensionDescription(localEnabledLanguage),
toExtensionDescription(localRandom),
toExtensionDescription(builtInTheme),
toExtensionDescription(builtInBasic)
],
canAddExtension: (extension) => true,
whenInstalledExtensionsRegistered: () => Promise.resolve(true)
});
await (<TestExtensionEnablementService>instantiationService.get(IWorkbenchExtensionEnablementService)).setEnablement([localDisabledTheme], EnablementState.DisabledGlobally);
await (<TestExtensionEnablementService>instantiationService.get(IWorkbenchExtensionEnablementService)).setEnablement([localDisabledLanguage], EnablementState.DisabledGlobally);
instantiationService.set(IExtensionsWorkbenchService, instantiationService.createInstance(ExtensionsWorkbenchService));
testableView = instantiationService.createInstance(ExtensionsListView, {}, { id: '', title: '' });
});
teardown(() => {
(<ExtensionsWorkbenchService>instantiationService.get(IExtensionsWorkbenchService)).dispose();
testableView.dispose();
});
suiteTeardown(() => {
instantiationService.dispose();
});
test('Test query types', () => {
assert.strictEqual(ExtensionsListView.isBuiltInExtensionsQuery('@builtin'), true);
assert.strictEqual(ExtensionsListView.isLocalExtensionsQuery('@installed'), true);
assert.strictEqual(ExtensionsListView.isLocalExtensionsQuery('@enabled'), true);
assert.strictEqual(ExtensionsListView.isLocalExtensionsQuery('@disabled'), true);
assert.strictEqual(ExtensionsListView.isLocalExtensionsQuery('@outdated'), true);
assert.strictEqual(ExtensionsListView.isLocalExtensionsQuery('@updates'), true);
assert.strictEqual(ExtensionsListView.isLocalExtensionsQuery('@sort:name'), true);
assert.strictEqual(ExtensionsListView.isLocalExtensionsQuery('@sort:updateDate'), true);
assert.strictEqual(ExtensionsListView.isLocalExtensionsQuery('@installed searchText'), true);
assert.strictEqual(ExtensionsListView.isLocalExtensionsQuery('@enabled searchText'), true);
assert.strictEqual(ExtensionsListView.isLocalExtensionsQuery('@disabled searchText'), true);
assert.strictEqual(ExtensionsListView.isLocalExtensionsQuery('@outdated searchText'), true);
assert.strictEqual(ExtensionsListView.isLocalExtensionsQuery('@updates searchText'), true);
});
test('Test empty query equates to sort by install count', () => {
const target = <SinonStub>instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage());
return testableView.show('').then(() => {
assert.ok(target.calledOnce);
const options: IQueryOptions = target.args[0][0];
assert.strictEqual(options.sortBy, SortBy.InstallCount);
});
});
test('Test non empty query without sort doesnt use sortBy', () => {
const target = <SinonStub>instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage());
return testableView.show('some extension').then(() => {
assert.ok(target.calledOnce);
const options: IQueryOptions = target.args[0][0];
assert.strictEqual(options.sortBy, undefined);
});
});
test('Test query with sort uses sortBy', () => {
const target = <SinonStub>instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage());
return testableView.show('some extension @sort:rating').then(() => {
assert.ok(target.calledOnce);
const options: IQueryOptions = target.args[0][0];
assert.strictEqual(options.sortBy, SortBy.WeightedRating);
});
});
test('Test default view actions required sorting', async () => {
const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
const extension = (await workbenchService.queryLocal()).find(ex => ex.identifier === localEnabledLanguage.identifier);
await new Promise<void>(c => {
const disposable = workbenchService.onChange(() => {
if (extension?.outdated) {
disposable.dispose();
c();
}
});
instantiationService.get(IExtensionsWorkbenchService).queryGallery(CancellationToken.None);
});
const result = await testableView.show('@installed');
assert.strictEqual(result.length, 5, 'Unexpected number of results for @installed query');
const actual = [result.get(0).name, result.get(1).name, result.get(2).name, result.get(3).name, result.get(4).name];
const expected = [localEnabledLanguage.manifest.name, localEnabledTheme.manifest.name, localRandom.manifest.name, localDisabledTheme.manifest.name, localDisabledLanguage.manifest.name];
for (let i = 0; i < result.length; i++) {
assert.strictEqual(actual[i], expected[i], 'Unexpected extension for @installed query with outadted extension.');
}
});
test('Test installed query results', async () => {
await testableView.show('@installed').then(result => {
assert.strictEqual(result.length, 5, 'Unexpected number of results for @installed query');
const actual = [result.get(0).name, result.get(1).name, result.get(2).name, result.get(3).name, result.get(4).name].sort();
const expected = [localDisabledTheme.manifest.name, localEnabledTheme.manifest.name, localRandom.manifest.name, localDisabledLanguage.manifest.name, localEnabledLanguage.manifest.name];
for (let i = 0; i < result.length; i++) {
assert.strictEqual(actual[i], expected[i], 'Unexpected extension for @installed query.');
}
});
await testableView.show('@installed first').then(result => {
assert.strictEqual(result.length, 2, 'Unexpected number of results for @installed query');
assert.strictEqual(result.get(0).name, localEnabledTheme.manifest.name, 'Unexpected extension for @installed query with search text.');
assert.strictEqual(result.get(1).name, localDisabledTheme.manifest.name, 'Unexpected extension for @installed query with search text.');
});
await testableView.show('@disabled').then(result => {
assert.strictEqual(result.length, 2, 'Unexpected number of results for @disabled query');
assert.strictEqual(result.get(0).name, localDisabledTheme.manifest.name, 'Unexpected extension for @disabled query.');
assert.strictEqual(result.get(1).name, localDisabledLanguage.manifest.name, 'Unexpected extension for @disabled query.');
});
await testableView.show('@enabled').then(result => {
assert.strictEqual(result.length, 3, 'Unexpected number of results for @enabled query');
assert.strictEqual(result.get(0).name, localEnabledTheme.manifest.name, 'Unexpected extension for @enabled query.');
assert.strictEqual(result.get(1).name, localRandom.manifest.name, 'Unexpected extension for @enabled query.');
assert.strictEqual(result.get(2).name, localEnabledLanguage.manifest.name, 'Unexpected extension for @enabled query.');
});
await testableView.show('@builtin:themes').then(result => {
assert.strictEqual(result.length, 1, 'Unexpected number of results for @builtin:themes query');
assert.strictEqual(result.get(0).name, builtInTheme.manifest.name, 'Unexpected extension for @builtin:themes query.');
});
await testableView.show('@builtin:basics').then(result => {
assert.strictEqual(result.length, 1, 'Unexpected number of results for @builtin:basics query');
assert.strictEqual(result.get(0).name, builtInBasic.manifest.name, 'Unexpected extension for @builtin:basics query.');
});
await testableView.show('@builtin').then(result => {
assert.strictEqual(result.length, 2, 'Unexpected number of results for @builtin query');
assert.strictEqual(result.get(0).name, builtInBasic.manifest.name, 'Unexpected extension for @builtin query.');
assert.strictEqual(result.get(1).name, builtInTheme.manifest.name, 'Unexpected extension for @builtin query.');
});
await testableView.show('@builtin my-theme').then(result => {
assert.strictEqual(result.length, 1, 'Unexpected number of results for @builtin query');
assert.strictEqual(result.get(0).name, builtInTheme.manifest.name, 'Unexpected extension for @builtin query.');
});
});
test('Test installed query with category', async () => {
await testableView.show('@installed category:themes').then(result => {
assert.strictEqual(result.length, 2, 'Unexpected number of results for @installed query with category');
assert.strictEqual(result.get(0).name, localEnabledTheme.manifest.name, 'Unexpected extension for @installed query with category.');
assert.strictEqual(result.get(1).name, localDisabledTheme.manifest.name, 'Unexpected extension for @installed query with category.');
});
await testableView.show('@installed category:"themes"').then(result => {
assert.strictEqual(result.length, 2, 'Unexpected number of results for @installed query with quoted category');
assert.strictEqual(result.get(0).name, localEnabledTheme.manifest.name, 'Unexpected extension for @installed query with quoted category.');
assert.strictEqual(result.get(1).name, localDisabledTheme.manifest.name, 'Unexpected extension for @installed query with quoted category.');
});
await testableView.show('@installed category:"programming languages"').then(result => {
assert.strictEqual(result.length, 2, 'Unexpected number of results for @installed query with quoted category including space');
assert.strictEqual(result.get(0).name, localEnabledLanguage.manifest.name, 'Unexpected extension for @installed query with quoted category including space.');
assert.strictEqual(result.get(1).name, localDisabledLanguage.manifest.name, 'Unexpected extension for @installed query with quoted category inlcuding space.');
});
await testableView.show('@installed category:themes category:random').then(result => {
assert.strictEqual(result.length, 3, 'Unexpected number of results for @installed query with multiple category');
assert.strictEqual(result.get(0).name, localEnabledTheme.manifest.name, 'Unexpected extension for @installed query with multiple category.');
assert.strictEqual(result.get(1).name, localRandom.manifest.name, 'Unexpected extension for @installed query with multiple category.');
assert.strictEqual(result.get(2).name, localDisabledTheme.manifest.name, 'Unexpected extension for @installed query with multiple category.');
});
await testableView.show('@enabled category:themes').then(result => {
assert.strictEqual(result.length, 1, 'Unexpected number of results for @enabled query with category');
assert.strictEqual(result.get(0).name, localEnabledTheme.manifest.name, 'Unexpected extension for @enabled query with category.');
});
await testableView.show('@enabled category:"themes"').then(result => {
assert.strictEqual(result.length, 1, 'Unexpected number of results for @enabled query with quoted category');
assert.strictEqual(result.get(0).name, localEnabledTheme.manifest.name, 'Unexpected extension for @enabled query with quoted category.');
});
await testableView.show('@enabled category:"programming languages"').then(result => {
assert.strictEqual(result.length, 1, 'Unexpected number of results for @enabled query with quoted category inlcuding space');
assert.strictEqual(result.get(0).name, localEnabledLanguage.manifest.name, 'Unexpected extension for @enabled query with quoted category including space.');
});
await testableView.show('@disabled category:themes').then(result => {
assert.strictEqual(result.length, 1, 'Unexpected number of results for @disabled query with category');
assert.strictEqual(result.get(0).name, localDisabledTheme.manifest.name, 'Unexpected extension for @disabled query with category.');
});
await testableView.show('@disabled category:"themes"').then(result => {
assert.strictEqual(result.length, 1, 'Unexpected number of results for @disabled query with quoted category');
assert.strictEqual(result.get(0).name, localDisabledTheme.manifest.name, 'Unexpected extension for @disabled query with quoted category.');
});
await testableView.show('@disabled category:"programming languages"').then(result => {
assert.strictEqual(result.length, 1, 'Unexpected number of results for @disabled query with quoted category inlcuding space');
assert.strictEqual(result.get(0).name, localDisabledLanguage.manifest.name, 'Unexpected extension for @disabled query with quoted category including space.');
});
});
test('Test local query with sorting order', async () => {
await testableView.show('@recentlyUpdated').then(result => {
assert.strictEqual(result.length, 1, 'Unexpected number of results for @recentlyUpdated');
assert.strictEqual(result.get(0).name, localDisabledLanguage.manifest.name, 'Unexpected default sort order of extensions for @recentlyUpdate query');
});
await testableView.show('@installed @sort:updateDate').then(result => {
assert.strictEqual(result.length, 5, 'Unexpected number of results for @sort:updateDate. Expected all localy installed Extension which are not builtin');
const actual = [result.get(0).local?.installedTimestamp, result.get(1).local?.installedTimestamp, result.get(2).local?.installedTimestamp, result.get(3).local?.installedTimestamp, result.get(4).local?.installedTimestamp];
const expected = [localEnabledLanguage.installedTimestamp, localDisabledLanguage.installedTimestamp, localRandom.installedTimestamp, localDisabledTheme.installedTimestamp, localEnabledTheme.installedTimestamp];
for (let i = 0; i < result.length; i++) {
assert.strictEqual(actual[i], expected[i], 'Unexpected extension sorting for @sort:updateDate query.');
}
});
});
test('Test @recommended:workspace query', () => {
const workspaceRecommendedExtensions = [
workspaceRecommendationA,
workspaceRecommendationB,
configBasedRecommendationA,
];
const target = <SinonStub>instantiationService.stubPromise(IExtensionGalleryService, 'getExtensions', workspaceRecommendedExtensions);
return testableView.show('@recommended:workspace').then(result => {
const extensionInfos: IExtensionInfo[] = target.args[0][0];
assert.strictEqual(extensionInfos.length, workspaceRecommendedExtensions.length);
assert.strictEqual(result.length, workspaceRecommendedExtensions.length);
for (let i = 0; i < workspaceRecommendedExtensions.length; i++) {
assert.strictEqual(extensionInfos[i].id, workspaceRecommendedExtensions[i].identifier.id);
assert.strictEqual(result.get(i).identifier.id, workspaceRecommendedExtensions[i].identifier.id);
}
});
});
test('Test @recommended query', () => {
const allRecommendedExtensions = [
fileBasedRecommendationA,
fileBasedRecommendationB,
configBasedRecommendationB,
otherRecommendationA
];
const target = <SinonStub>instantiationService.stubPromise(IExtensionGalleryService, 'getExtensions', allRecommendedExtensions);
return testableView.show('@recommended').then(result => {
const extensionInfos: IExtensionInfo[] = target.args[0][0];
assert.strictEqual(extensionInfos.length, allRecommendedExtensions.length);
assert.strictEqual(result.length, allRecommendedExtensions.length);
for (let i = 0; i < allRecommendedExtensions.length; i++) {
assert.strictEqual(extensionInfos[i].id, allRecommendedExtensions[i].identifier.id);
assert.strictEqual(result.get(i).identifier.id, allRecommendedExtensions[i].identifier.id);
}
});
});
test('Test @recommended:all query', () => {
const allRecommendedExtensions = [
workspaceRecommendationA,
workspaceRecommendationB,
configBasedRecommendationA,
fileBasedRecommendationA,
fileBasedRecommendationB,
configBasedRecommendationB,
otherRecommendationA,
];
const target = <SinonStub>instantiationService.stubPromise(IExtensionGalleryService, 'getExtensions', allRecommendedExtensions);
return testableView.show('@recommended:all').then(result => {
const extensionInfos: IExtensionInfo[] = target.args[0][0];
assert.strictEqual(extensionInfos.length, allRecommendedExtensions.length);
assert.strictEqual(result.length, allRecommendedExtensions.length);
for (let i = 0; i < allRecommendedExtensions.length; i++) {
assert.strictEqual(extensionInfos[i].id, allRecommendedExtensions[i].identifier.id);
assert.strictEqual(result.get(i).identifier.id, allRecommendedExtensions[i].identifier.id);
}
});
});
test('Test search', () => {
const searchText = 'search-me';
const results = [
fileBasedRecommendationA,
workspaceRecommendationA,
otherRecommendationA,
workspaceRecommendationB
];
const queryTarget = <SinonStub>instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(...results));
return testableView.show('search-me').then(result => {
const options: IQueryOptions = queryTarget.args[0][0];
assert.ok(queryTarget.calledOnce);
assert.strictEqual(options.text, searchText);
assert.strictEqual(result.length, results.length);
for (let i = 0; i < results.length; i++) {
assert.strictEqual(result.get(i).identifier.id, results[i].identifier.id);
}
});
});
test('Test preferred search experiment', () => {
const searchText = 'search-me';
const actual = [
fileBasedRecommendationA,
workspaceRecommendationA,
otherRecommendationA,
workspaceRecommendationB
];
const expected = [
workspaceRecommendationA,
workspaceRecommendationB,
fileBasedRecommendationA,
otherRecommendationA
];
const queryTarget = <SinonStub>instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(...actual));
const experimentTarget = <SinonStub>instantiationService.stubPromise(IWorkbenchExtensionManagementService, 'getExtensionsControlManifest', {
malicious: [], deprecated: {},
search: [{
query: 'search-me',
preferredResults: [
workspaceRecommendationA.identifier.id,
'something-that-wasnt-in-first-page',
workspaceRecommendationB.identifier.id
]
}]
});
testableView.dispose();
testableView = instantiationService.createInstance(ExtensionsListView, {}, { id: '', title: '' });
return testableView.show('search-me').then(result => {
const options: IQueryOptions = queryTarget.args[0][0];
assert.ok(experimentTarget.calledTwice);
assert.ok(queryTarget.calledOnce);
assert.strictEqual(options.text, searchText);
assert.strictEqual(result.length, expected.length);
for (let i = 0; i < expected.length; i++) {
assert.strictEqual(result.get(i).identifier.id, expected[i].identifier.id);
}
});
});
test('Skip preferred search experiment when user defines sort order', () => {
const searchText = 'search-me';
const realResults = [
fileBasedRecommendationA,
workspaceRecommendationA,
otherRecommendationA,
workspaceRecommendationB
];
const queryTarget = <SinonStub>instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(...realResults));
testableView.dispose();
testableView = instantiationService.createInstance(ExtensionsListView, {}, { id: '', title: '' });
return testableView.show('search-me @sort:installs').then(result => {
const options: IQueryOptions = queryTarget.args[0][0];
assert.ok(queryTarget.calledOnce);
assert.strictEqual(options.text, searchText);
assert.strictEqual(result.length, realResults.length);
for (let i = 0; i < realResults.length; i++) {
assert.strictEqual(result.get(i).identifier.id, realResults[i].identifier.id);
}
});
});
function aLocalExtension(name: string = 'someext', manifest: any = {}, properties: any = {}): ILocalExtension {
manifest = { name, publisher: 'pub', version: '1.0.0', ...manifest };
properties = {
type: ExtensionType.User,
location: URI.file(`pub.${name}`),
identifier: { id: getGalleryExtensionId(manifest.publisher, manifest.name) },
metadata: { id: getGalleryExtensionId(manifest.publisher, manifest.name), publisherId: manifest.publisher, publisherDisplayName: 'somename' },
...properties
};
properties.isBuiltin = properties.type === ExtensionType.System;
return <ILocalExtension>Object.create({ manifest, ...properties });
}
function aGalleryExtension(name: string, properties: any = {}, galleryExtensionProperties: any = {}, assets: any = {}): IGalleryExtension {
const targetPlatform = getTargetPlatform(platform, arch);
const galleryExtension = <IGalleryExtension>Object.create({ name, publisher: 'pub', version: '1.0.0', allTargetPlatforms: [targetPlatform], properties: {}, assets: {}, ...properties });
galleryExtension.properties = { ...galleryExtension.properties, dependencies: [], targetPlatform, ...galleryExtensionProperties };
galleryExtension.assets = { ...galleryExtension.assets, ...assets };
galleryExtension.identifier = { id: getGalleryExtensionId(galleryExtension.publisher, galleryExtension.name), uuid: generateUuid() };
return <IGalleryExtension>galleryExtension;
}
function aPage<T>(...objects: T[]): IPager<T> {
return { firstPage: objects, total: objects.length, pageSize: objects.length, getPage: () => null! };
}
});