forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtreeView.unit.test.ts
More file actions
63 lines (56 loc) · 3.14 KB
/
treeView.unit.test.ts
File metadata and controls
63 lines (56 loc) · 3.14 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { anything, deepEqual, instance, mock, verify, when } from 'ts-mockito';
import * as typemoq from 'typemoq';
import { TreeView, Uri } from 'vscode';
import { ApplicationShell } from '../../../client/common/application/applicationShell';
import { CommandManager } from '../../../client/common/application/commandManager';
import { IApplicationShell, ICommandManager } from '../../../client/common/application/types';
import { Commands } from '../../../client/common/constants';
import { TestTreeViewProvider } from '../../../client/testing/explorer/testTreeViewProvider';
import { TreeViewService } from '../../../client/testing/explorer/treeView';
import { ITestTreeViewProvider, TestDataItem } from '../../../client/testing/types';
// tslint:disable:no-any
suite('Unit Tests Test Explorer Tree View', () => {
let treeViewService: TreeViewService;
let treeView: typemoq.IMock<TreeView<TestDataItem>>;
let commandManager: ICommandManager;
let appShell: IApplicationShell;
let treeViewProvider: ITestTreeViewProvider;
setup(() => {
commandManager = mock(CommandManager);
treeViewProvider = mock(TestTreeViewProvider);
appShell = mock(ApplicationShell);
treeView = typemoq.Mock.ofType<TreeView<TestDataItem>>();
treeViewService = new TreeViewService(instance(treeViewProvider), [],
instance(appShell), instance(commandManager));
});
test('Activation will create the treeview (without a resource)', async () => {
await treeViewService.activate(undefined);
verify(appShell.createTreeView('python_tests', deepEqual({ showCollapseAll: true, treeDataProvider: instance(treeViewProvider) }))).once();
});
test('Activation will create the treeview (with a resource)', async () => {
await treeViewService.activate(Uri.file(__filename));
verify(appShell.createTreeView('python_tests', deepEqual({ showCollapseAll: true, treeDataProvider: instance(treeViewProvider) }))).once();
});
test('Activation will add command handlers (without a resource)', async () => {
await treeViewService.activate(undefined);
verify(commandManager.registerCommand(Commands.Test_Reveal_Test_Item, treeViewService.onRevealTestItem, treeViewService)).once();
});
test('Activation will add command handlers (with a resource)', async () => {
await treeViewService.activate(Uri.file(__filename));
verify(commandManager.registerCommand(Commands.Test_Reveal_Test_Item, treeViewService.onRevealTestItem, treeViewService)).once();
});
test('Invoking the command handler will reveal the node in the tree', async () => {
const data = {} as any;
treeView
.setup(t => t.reveal(typemoq.It.isAny()))
.returns(() => Promise.resolve())
.verifiable(typemoq.Times.once());
when(appShell.createTreeView('python_tests', anything())).thenReturn(treeView.object);
await treeViewService.activate(undefined);
await treeViewService.onRevealTestItem(data);
treeView.verifyAll();
});
});