forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactiveResource.unit.test.ts
More file actions
101 lines (83 loc) · 4.16 KB
/
activeResource.unit.test.ts
File metadata and controls
101 lines (83 loc) · 4.16 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
96
97
98
99
100
101
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { assert } from 'chai';
import { instance, mock, verify, when } from 'ts-mockito';
import { Uri } from 'vscode';
import { ActiveResourceService } from '../../client/common/application/activeResource';
import { DocumentManager } from '../../client/common/application/documentManager';
import { IDocumentManager, IWorkspaceService } from '../../client/common/application/types';
import { WorkspaceService } from '../../client/common/application/workspace';
// tslint:disable-next-line: max-func-body-length
suite('Active resource service', () => {
let documentManager: IDocumentManager;
let workspaceService: IWorkspaceService;
let activeResourceService: ActiveResourceService;
setup(() => {
documentManager = mock(DocumentManager);
workspaceService = mock(WorkspaceService);
activeResourceService = new ActiveResourceService(instance(documentManager), instance(workspaceService));
});
test('Return document uri if the active document is not new (has been saved)', async () => {
const activeTextEditor = {
document: {
isUntitled: false,
uri: Uri.parse('a')
}
};
// tslint:disable-next-line:no-any
when(documentManager.activeTextEditor).thenReturn(activeTextEditor as any);
const activeResource = activeResourceService.getActiveResource();
assert.deepEqual(activeResource, activeTextEditor.document.uri);
verify(documentManager.activeTextEditor).atLeast(1);
verify(workspaceService.workspaceFolders).never();
});
test("Don't return document uri if the active document is new (still unsaved)", async () => {
const activeTextEditor = {
document: {
isUntitled: true,
uri: Uri.parse('a')
}
};
// tslint:disable-next-line:no-any
when(documentManager.activeTextEditor).thenReturn(activeTextEditor as any);
when(workspaceService.workspaceFolders).thenReturn([]);
const activeResource = activeResourceService.getActiveResource();
assert.notDeepEqual(activeResource, activeTextEditor.document.uri);
verify(documentManager.activeTextEditor).atLeast(1);
verify(workspaceService.workspaceFolders).atLeast(1);
});
test('If no document is currently opened & the workspace opened contains workspace folders, return the uri of the first workspace folder', async () => {
const workspaceFolders = [
{
uri: Uri.parse('a')
},
{
uri: Uri.parse('b')
}
];
when(documentManager.activeTextEditor).thenReturn(undefined);
// tslint:disable-next-line:no-any
when(workspaceService.workspaceFolders).thenReturn(workspaceFolders as any);
const activeResource = activeResourceService.getActiveResource();
assert.deepEqual(activeResource, workspaceFolders[0].uri);
verify(documentManager.activeTextEditor).atLeast(1);
verify(workspaceService.workspaceFolders).atLeast(1);
});
test('If no document is currently opened & no folder is opened, return undefined', async () => {
when(documentManager.activeTextEditor).thenReturn(undefined);
when(workspaceService.workspaceFolders).thenReturn(undefined);
const activeResource = activeResourceService.getActiveResource();
assert.deepEqual(activeResource, undefined);
verify(documentManager.activeTextEditor).atLeast(1);
verify(workspaceService.workspaceFolders).atLeast(1);
});
test('If no document is currently opened & workspace contains no workspace folders, return undefined', async () => {
when(documentManager.activeTextEditor).thenReturn(undefined);
when(workspaceService.workspaceFolders).thenReturn([]);
const activeResource = activeResourceService.getActiveResource();
assert.deepEqual(activeResource, undefined);
verify(documentManager.activeTextEditor).atLeast(1);
verify(workspaceService.workspaceFolders).atLeast(1);
});
});