forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainThreadTreeViews.test.ts
More file actions
95 lines (81 loc) · 5.13 KB
/
mainThreadTreeViews.test.ts
File metadata and controls
95 lines (81 loc) · 5.13 KB
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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import * as assert from 'assert';
import { mock } from 'vs/base/test/common/mock';
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { NullLogService } from 'vs/platform/log/common/log';
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
import { Registry } from 'vs/platform/registry/common/platform';
import { MainThreadTreeViews } from 'vs/workbench/api/browser/mainThreadTreeViews';
import { ExtHostTreeViewsShape } from 'vs/workbench/api/common/extHost.protocol';
import { CustomTreeView } from 'vs/workbench/browser/parts/views/treeView';
import { Extensions, ITreeItem, ITreeView, ITreeViewDescriptor, IViewContainersRegistry, IViewDescriptorService, IViewsRegistry, TreeItemCollapsibleState, ViewContainer, ViewContainerLocation } from 'vs/workbench/common/views';
import { IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers';
import { ExtensionHostKind } from 'vs/workbench/services/extensions/common/extensionHostKind';
import { ViewDescriptorService } from 'vs/workbench/services/views/browser/viewDescriptorService';
import { TestViewsService, workbenchInstantiationService } from 'vs/workbench/test/browser/workbenchTestServices';
import { TestExtensionService } from 'vs/workbench/test/common/workbenchTestServices';
suite('MainThreadHostTreeView', function () {
const testTreeViewId = 'testTreeView';
const customValue = 'customValue';
const ViewsRegistry = Registry.as<IViewsRegistry>(Extensions.ViewsRegistry);
interface CustomTreeItem extends ITreeItem {
customProp: string;
}
class MockExtHostTreeViewsShape extends mock<ExtHostTreeViewsShape>() {
override async $getChildren(treeViewId: string, treeItemHandle?: string): Promise<ITreeItem[]> {
return [<CustomTreeItem>{ handle: 'testItem1', collapsibleState: TreeItemCollapsibleState.Expanded, customProp: customValue }];
}
override async $hasResolve(): Promise<boolean> {
return false;
}
override $setVisible(): void { }
}
let container: ViewContainer;
let mainThreadTreeViews: MainThreadTreeViews;
let extHostTreeViewsShape: MockExtHostTreeViewsShape;
teardown(() => {
ViewsRegistry.deregisterViews(ViewsRegistry.getViews(container), container);
});
const disposables = ensureNoDisposablesAreLeakedInTestSuite();
setup(async () => {
const instantiationService: TestInstantiationService = <TestInstantiationService>workbenchInstantiationService(undefined, disposables);
const viewDescriptorService = disposables.add(instantiationService.createInstance(ViewDescriptorService));
instantiationService.stub(IViewDescriptorService, viewDescriptorService);
container = Registry.as<IViewContainersRegistry>(Extensions.ViewContainersRegistry).registerViewContainer({ id: 'testContainer', title: nls.localize2('test', 'test'), ctorDescriptor: new SyncDescriptor(<any>{}) }, ViewContainerLocation.Sidebar);
const viewDescriptor: ITreeViewDescriptor = {
id: testTreeViewId,
ctorDescriptor: null!,
name: nls.localize2('Test View 1', 'Test View 1'),
treeView: disposables.add(instantiationService.createInstance(CustomTreeView, 'testTree', 'Test Title', 'extension.id')),
};
ViewsRegistry.registerViews([viewDescriptor], container);
const testExtensionService = new TestExtensionService();
extHostTreeViewsShape = new MockExtHostTreeViewsShape();
mainThreadTreeViews = disposables.add(new MainThreadTreeViews(
new class implements IExtHostContext {
remoteAuthority = '';
extensionHostKind = ExtensionHostKind.LocalProcess;
dispose() { }
assertRegistered() { }
set(v: any): any { return null; }
getProxy(): any {
return extHostTreeViewsShape;
}
drain(): any { return null; }
}, new TestViewsService(), new TestNotificationService(), testExtensionService, new NullLogService()));
mainThreadTreeViews.$registerTreeViewDataProvider(testTreeViewId, { showCollapseAll: false, canSelectMany: false, dropMimeTypes: [], dragMimeTypes: [], hasHandleDrag: false, hasHandleDrop: false, manuallyManageCheckboxes: false });
await testExtensionService.whenInstalledExtensionsRegistered();
});
test('getChildren keeps custom properties', async () => {
const treeView: ITreeView = (<ITreeViewDescriptor>ViewsRegistry.getView(testTreeViewId)).treeView;
const children = await treeView.dataProvider?.getChildren({ handle: 'root', collapsibleState: TreeItemCollapsibleState.Expanded });
assert(children!.length === 1, 'Exactly one child should be returned');
assert((<CustomTreeItem>children![0]).customProp === customValue, 'Tree Items should keep custom properties');
});
});