@theia/api-tests 1.48.1 → 1.48.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/api-tests.d.ts +21 -21
- package/src/browser-utils.spec.js +54 -54
- package/src/contribution-filter.spec.js +36 -36
- package/src/explorer-open-close.spec.js +155 -155
- package/src/file-search.spec.js +132 -132
- package/src/find-replace.spec.js +170 -170
- package/src/keybindings.spec.js +116 -116
- package/src/launch-preferences.spec.js +728 -728
- package/src/menus.spec.js +176 -176
- package/src/monaco-api.spec.js +203 -203
- package/src/navigator.spec.js +92 -92
- package/src/preferences.spec.js +207 -207
- package/src/saveable.spec.js +503 -503
- package/src/scm.spec.js +173 -173
- package/src/shell.spec.js +41 -41
- package/src/task-configurations.spec.js +112 -112
- package/src/typescript.spec.js +860 -860
- package/src/undo-redo-selectAll.spec.js +193 -193
- package/src/views.spec.js +76 -76
package/src/file-search.spec.js
CHANGED
|
@@ -1,132 +1,132 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2021 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
// @ts-check
|
|
18
|
-
describe('file-search', function () {
|
|
19
|
-
|
|
20
|
-
const { assert } = chai;
|
|
21
|
-
|
|
22
|
-
const Uri = require('@theia/core/lib/common/uri');
|
|
23
|
-
const { QuickFileOpenService } = require('@theia/file-search/lib/browser/quick-file-open');
|
|
24
|
-
const { CancellationTokenSource } = require('@theia/core/lib/common/cancellation');
|
|
25
|
-
|
|
26
|
-
/** @type {import('inversify').Container} */
|
|
27
|
-
const container = window['theia'].container;
|
|
28
|
-
const quickFileOpenService = container.get(QuickFileOpenService);
|
|
29
|
-
|
|
30
|
-
describe('quick-file-open', () => {
|
|
31
|
-
|
|
32
|
-
describe('#compareItems', () => {
|
|
33
|
-
|
|
34
|
-
/** @type import ('@theia/file-search/lib/browser/quick-file-open').QuickFileOpenService['compareItems']*/
|
|
35
|
-
const sortByCompareItems = (a, b) => quickFileOpenService['compareItems'](a, b);
|
|
36
|
-
|
|
37
|
-
it('should compare two quick-open-items by `label`', () => {
|
|
38
|
-
|
|
39
|
-
/** @type import ('@theia/file-search/lib/browser/quick-file-open').FileQuickPickItem*/
|
|
40
|
-
const a = { label: 'a', uri: new Uri.default('b') };
|
|
41
|
-
/** @type import ('@theia/file-search/lib/browser/quick-file-open').FileQuickPickItem*/
|
|
42
|
-
const b = { label: 'b', uri: new Uri.default('a') };
|
|
43
|
-
|
|
44
|
-
assert.deepEqual([a, b].sort(sortByCompareItems), [a, b], 'a should be before b');
|
|
45
|
-
assert.deepEqual([b, a].sort(sortByCompareItems), [a, b], 'a should be before b');
|
|
46
|
-
assert.equal(quickFileOpenService['compareItems'](a, a), 0, 'items should be equal');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('should compare two quick-open-items by `uri`', () => {
|
|
50
|
-
|
|
51
|
-
/** @type import ('@theia/file-search/lib/browser/quick-file-open').FileQuickPickItem*/
|
|
52
|
-
const a = { label: 'a', uri: new Uri.default('a') };
|
|
53
|
-
/** @type import ('@theia/file-search/lib/browser/quick-file-open').FileQuickPickItem*/
|
|
54
|
-
const b = { label: 'a', uri: new Uri.default('b') };
|
|
55
|
-
assert.deepEqual([a, b].sort(sortByCompareItems), [a, b], 'a should be before b');
|
|
56
|
-
assert.deepEqual([b, a].sort(sortByCompareItems), [a, b], 'a should be before b');
|
|
57
|
-
assert.equal(sortByCompareItems(a, a), 0, 'items should be equal');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('should not place very good matches above exact matches', () => {
|
|
61
|
-
const exactMatch = 'almost_absurdly_long_file_name_with_many_parts.file';
|
|
62
|
-
const veryGoodMatch = 'almost_absurdly_long_file_name_with_many_parts_plus_one.file';
|
|
63
|
-
quickFileOpenService['filterAndRange'] = { filter: exactMatch };
|
|
64
|
-
/** @type import ('@theia/file-search/lib/browser/quick-file-open').FileQuickPickItem*/
|
|
65
|
-
const a = { label: exactMatch, uri: new Uri.default(exactMatch) };
|
|
66
|
-
/** @type import ('@theia/file-search/lib/browser/quick-file-open').FileQuickPickItem*/
|
|
67
|
-
const b = { label: veryGoodMatch, uri: new Uri.default(veryGoodMatch) };
|
|
68
|
-
assert.deepEqual([a, b].sort(sortByCompareItems), [a, b], 'a should be before b');
|
|
69
|
-
assert.deepEqual([b, a].sort(sortByCompareItems), [a, b], 'a should be before b');
|
|
70
|
-
assert.equal(sortByCompareItems(a, a), 0, 'items should be equal');
|
|
71
|
-
quickFileOpenService['filterAndRange'] = quickFileOpenService['filterAndRangeDefault'];
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe('#filterAndRange', () => {
|
|
77
|
-
|
|
78
|
-
it('should return the default when not searching', () => {
|
|
79
|
-
const filterAndRange = quickFileOpenService['filterAndRange'];
|
|
80
|
-
assert.equal(filterAndRange, quickFileOpenService['filterAndRangeDefault']);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('should update when searching', () => {
|
|
84
|
-
quickFileOpenService['getPicks']('a:2:1', new CancellationTokenSource().token); // perform a mock search.
|
|
85
|
-
const filterAndRange = quickFileOpenService['filterAndRange'];
|
|
86
|
-
assert.equal(filterAndRange.filter, 'a');
|
|
87
|
-
assert.deepEqual(filterAndRange.range, { start: { line: 1, character: 0 }, end: { line: 1, character: 0 } });
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe('#splitFilterAndRange', () => {
|
|
93
|
-
|
|
94
|
-
const expression1 = 'a:2:1';
|
|
95
|
-
const expression2 = 'a:2,1';
|
|
96
|
-
const expression3 = 'a:2#2';
|
|
97
|
-
const expression4 = 'a#2:2';
|
|
98
|
-
const expression5 = 'a#2,1';
|
|
99
|
-
const expression6 = 'a#2#2';
|
|
100
|
-
const expression7 = 'a:2';
|
|
101
|
-
const expression8 = 'a#2';
|
|
102
|
-
|
|
103
|
-
it('should split the filter correctly for different combinations', () => {
|
|
104
|
-
assert.equal((quickFileOpenService['splitFilterAndRange'](expression1).filter), 'a');
|
|
105
|
-
assert.equal((quickFileOpenService['splitFilterAndRange'](expression2).filter), 'a');
|
|
106
|
-
assert.equal((quickFileOpenService['splitFilterAndRange'](expression3).filter), 'a');
|
|
107
|
-
assert.equal((quickFileOpenService['splitFilterAndRange'](expression4).filter), 'a');
|
|
108
|
-
assert.equal((quickFileOpenService['splitFilterAndRange'](expression5).filter), 'a');
|
|
109
|
-
assert.equal((quickFileOpenService['splitFilterAndRange'](expression6).filter), 'a');
|
|
110
|
-
assert.equal((quickFileOpenService['splitFilterAndRange'](expression7).filter), 'a');
|
|
111
|
-
assert.equal((quickFileOpenService['splitFilterAndRange'](expression8).filter), 'a');
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should split the range correctly for different combinations', () => {
|
|
115
|
-
const rangeTest1 = { start: { line: 1, character: 0 }, end: { line: 1, character: 0 } };
|
|
116
|
-
const rangeTest2 = { start: { line: 1, character: 1 }, end: { line: 1, character: 1 } };
|
|
117
|
-
|
|
118
|
-
assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression1).range, rangeTest1);
|
|
119
|
-
assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression2).range, rangeTest1);
|
|
120
|
-
assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression3).range, rangeTest2);
|
|
121
|
-
assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression4).range, rangeTest2);
|
|
122
|
-
assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression5).range, rangeTest1);
|
|
123
|
-
assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression6).range, rangeTest2);
|
|
124
|
-
assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression7).range, rangeTest1);
|
|
125
|
-
assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression8).range, rangeTest1);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
});
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2021 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
// @ts-check
|
|
18
|
+
describe('file-search', function () {
|
|
19
|
+
|
|
20
|
+
const { assert } = chai;
|
|
21
|
+
|
|
22
|
+
const Uri = require('@theia/core/lib/common/uri');
|
|
23
|
+
const { QuickFileOpenService } = require('@theia/file-search/lib/browser/quick-file-open');
|
|
24
|
+
const { CancellationTokenSource } = require('@theia/core/lib/common/cancellation');
|
|
25
|
+
|
|
26
|
+
/** @type {import('inversify').Container} */
|
|
27
|
+
const container = window['theia'].container;
|
|
28
|
+
const quickFileOpenService = container.get(QuickFileOpenService);
|
|
29
|
+
|
|
30
|
+
describe('quick-file-open', () => {
|
|
31
|
+
|
|
32
|
+
describe('#compareItems', () => {
|
|
33
|
+
|
|
34
|
+
/** @type import ('@theia/file-search/lib/browser/quick-file-open').QuickFileOpenService['compareItems']*/
|
|
35
|
+
const sortByCompareItems = (a, b) => quickFileOpenService['compareItems'](a, b);
|
|
36
|
+
|
|
37
|
+
it('should compare two quick-open-items by `label`', () => {
|
|
38
|
+
|
|
39
|
+
/** @type import ('@theia/file-search/lib/browser/quick-file-open').FileQuickPickItem*/
|
|
40
|
+
const a = { label: 'a', uri: new Uri.default('b') };
|
|
41
|
+
/** @type import ('@theia/file-search/lib/browser/quick-file-open').FileQuickPickItem*/
|
|
42
|
+
const b = { label: 'b', uri: new Uri.default('a') };
|
|
43
|
+
|
|
44
|
+
assert.deepEqual([a, b].sort(sortByCompareItems), [a, b], 'a should be before b');
|
|
45
|
+
assert.deepEqual([b, a].sort(sortByCompareItems), [a, b], 'a should be before b');
|
|
46
|
+
assert.equal(quickFileOpenService['compareItems'](a, a), 0, 'items should be equal');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should compare two quick-open-items by `uri`', () => {
|
|
50
|
+
|
|
51
|
+
/** @type import ('@theia/file-search/lib/browser/quick-file-open').FileQuickPickItem*/
|
|
52
|
+
const a = { label: 'a', uri: new Uri.default('a') };
|
|
53
|
+
/** @type import ('@theia/file-search/lib/browser/quick-file-open').FileQuickPickItem*/
|
|
54
|
+
const b = { label: 'a', uri: new Uri.default('b') };
|
|
55
|
+
assert.deepEqual([a, b].sort(sortByCompareItems), [a, b], 'a should be before b');
|
|
56
|
+
assert.deepEqual([b, a].sort(sortByCompareItems), [a, b], 'a should be before b');
|
|
57
|
+
assert.equal(sortByCompareItems(a, a), 0, 'items should be equal');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('should not place very good matches above exact matches', () => {
|
|
61
|
+
const exactMatch = 'almost_absurdly_long_file_name_with_many_parts.file';
|
|
62
|
+
const veryGoodMatch = 'almost_absurdly_long_file_name_with_many_parts_plus_one.file';
|
|
63
|
+
quickFileOpenService['filterAndRange'] = { filter: exactMatch };
|
|
64
|
+
/** @type import ('@theia/file-search/lib/browser/quick-file-open').FileQuickPickItem*/
|
|
65
|
+
const a = { label: exactMatch, uri: new Uri.default(exactMatch) };
|
|
66
|
+
/** @type import ('@theia/file-search/lib/browser/quick-file-open').FileQuickPickItem*/
|
|
67
|
+
const b = { label: veryGoodMatch, uri: new Uri.default(veryGoodMatch) };
|
|
68
|
+
assert.deepEqual([a, b].sort(sortByCompareItems), [a, b], 'a should be before b');
|
|
69
|
+
assert.deepEqual([b, a].sort(sortByCompareItems), [a, b], 'a should be before b');
|
|
70
|
+
assert.equal(sortByCompareItems(a, a), 0, 'items should be equal');
|
|
71
|
+
quickFileOpenService['filterAndRange'] = quickFileOpenService['filterAndRangeDefault'];
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('#filterAndRange', () => {
|
|
77
|
+
|
|
78
|
+
it('should return the default when not searching', () => {
|
|
79
|
+
const filterAndRange = quickFileOpenService['filterAndRange'];
|
|
80
|
+
assert.equal(filterAndRange, quickFileOpenService['filterAndRangeDefault']);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should update when searching', () => {
|
|
84
|
+
quickFileOpenService['getPicks']('a:2:1', new CancellationTokenSource().token); // perform a mock search.
|
|
85
|
+
const filterAndRange = quickFileOpenService['filterAndRange'];
|
|
86
|
+
assert.equal(filterAndRange.filter, 'a');
|
|
87
|
+
assert.deepEqual(filterAndRange.range, { start: { line: 1, character: 0 }, end: { line: 1, character: 0 } });
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('#splitFilterAndRange', () => {
|
|
93
|
+
|
|
94
|
+
const expression1 = 'a:2:1';
|
|
95
|
+
const expression2 = 'a:2,1';
|
|
96
|
+
const expression3 = 'a:2#2';
|
|
97
|
+
const expression4 = 'a#2:2';
|
|
98
|
+
const expression5 = 'a#2,1';
|
|
99
|
+
const expression6 = 'a#2#2';
|
|
100
|
+
const expression7 = 'a:2';
|
|
101
|
+
const expression8 = 'a#2';
|
|
102
|
+
|
|
103
|
+
it('should split the filter correctly for different combinations', () => {
|
|
104
|
+
assert.equal((quickFileOpenService['splitFilterAndRange'](expression1).filter), 'a');
|
|
105
|
+
assert.equal((quickFileOpenService['splitFilterAndRange'](expression2).filter), 'a');
|
|
106
|
+
assert.equal((quickFileOpenService['splitFilterAndRange'](expression3).filter), 'a');
|
|
107
|
+
assert.equal((quickFileOpenService['splitFilterAndRange'](expression4).filter), 'a');
|
|
108
|
+
assert.equal((quickFileOpenService['splitFilterAndRange'](expression5).filter), 'a');
|
|
109
|
+
assert.equal((quickFileOpenService['splitFilterAndRange'](expression6).filter), 'a');
|
|
110
|
+
assert.equal((quickFileOpenService['splitFilterAndRange'](expression7).filter), 'a');
|
|
111
|
+
assert.equal((quickFileOpenService['splitFilterAndRange'](expression8).filter), 'a');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should split the range correctly for different combinations', () => {
|
|
115
|
+
const rangeTest1 = { start: { line: 1, character: 0 }, end: { line: 1, character: 0 } };
|
|
116
|
+
const rangeTest2 = { start: { line: 1, character: 1 }, end: { line: 1, character: 1 } };
|
|
117
|
+
|
|
118
|
+
assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression1).range, rangeTest1);
|
|
119
|
+
assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression2).range, rangeTest1);
|
|
120
|
+
assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression3).range, rangeTest2);
|
|
121
|
+
assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression4).range, rangeTest2);
|
|
122
|
+
assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression5).range, rangeTest1);
|
|
123
|
+
assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression6).range, rangeTest2);
|
|
124
|
+
assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression7).range, rangeTest1);
|
|
125
|
+
assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression8).range, rangeTest1);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
});
|
package/src/find-replace.spec.js
CHANGED
|
@@ -1,170 +1,170 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2020 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
// @ts-check
|
|
18
|
-
describe('Find and Replace', function () {
|
|
19
|
-
this.timeout(20_000);
|
|
20
|
-
const { assert } = chai;
|
|
21
|
-
|
|
22
|
-
const { animationFrame } = require('@theia/core/lib/browser/browser');
|
|
23
|
-
const { DisposableCollection } = require('@theia/core/lib/common/disposable');
|
|
24
|
-
const { CommonCommands } = require('@theia/core/lib/browser/common-frontend-contribution');
|
|
25
|
-
const { EditorManager } = require('@theia/editor/lib/browser/editor-manager');
|
|
26
|
-
const { WorkspaceService } = require('@theia/workspace/lib/browser/workspace-service');
|
|
27
|
-
const { CommandRegistry } = require('@theia/core/lib/common/command');
|
|
28
|
-
const { KeybindingRegistry } = require('@theia/core/lib/browser/keybinding');
|
|
29
|
-
const { ContextKeyService } = require('@theia/core/lib/browser/context-key-service');
|
|
30
|
-
const { FileNavigatorContribution } = require('@theia/navigator/lib/browser/navigator-contribution');
|
|
31
|
-
const { ApplicationShell } = require('@theia/core/lib/browser/shell/application-shell');
|
|
32
|
-
const { HostedPluginSupport } = require('@theia/plugin-ext/lib/hosted/browser/hosted-plugin');
|
|
33
|
-
const { ProgressStatusBarItem } = require('@theia/core/lib/browser/progress-status-bar-item');
|
|
34
|
-
const { EXPLORER_VIEW_CONTAINER_ID } = require('@theia/navigator/lib/browser/navigator-widget-factory');
|
|
35
|
-
const { MonacoEditor } = require('@theia/monaco/lib/browser/monaco-editor');
|
|
36
|
-
const container = window.theia.container;
|
|
37
|
-
const editorManager = container.get(EditorManager);
|
|
38
|
-
const workspaceService = container.get(WorkspaceService);
|
|
39
|
-
const commands = container.get(CommandRegistry);
|
|
40
|
-
const keybindings = container.get(KeybindingRegistry);
|
|
41
|
-
const contextKeyService = container.get(ContextKeyService);
|
|
42
|
-
const navigatorContribution = container.get(FileNavigatorContribution);
|
|
43
|
-
const shell = container.get(ApplicationShell);
|
|
44
|
-
const rootUri = workspaceService.tryGetRoots()[0].resource;
|
|
45
|
-
const pluginService = container.get(HostedPluginSupport);
|
|
46
|
-
const progressStatusBarItem = container.get(ProgressStatusBarItem);
|
|
47
|
-
const fileUri = rootUri.resolve('../api-tests/test-ts-workspace/demo-file.ts');
|
|
48
|
-
|
|
49
|
-
const toTearDown = new DisposableCollection();
|
|
50
|
-
|
|
51
|
-
function pause(ms = 500) {
|
|
52
|
-
console.debug(`pause test for: ${ms} ms`);
|
|
53
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @template T
|
|
58
|
-
* @param {() => Promise<T> | T} condition
|
|
59
|
-
* @returns {Promise<T>}
|
|
60
|
-
*/
|
|
61
|
-
function waitForAnimation(condition) {
|
|
62
|
-
return new Promise(async (resolve, dispose) => {
|
|
63
|
-
toTearDown.push({ dispose });
|
|
64
|
-
do {
|
|
65
|
-
await animationFrame();
|
|
66
|
-
} while (!condition());
|
|
67
|
-
resolve();
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
before(async () => {
|
|
72
|
-
await pluginService.didStart;
|
|
73
|
-
await shell.leftPanelHandler.collapse();
|
|
74
|
-
await editorManager.closeAll({ save: false });
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
beforeEach(async function () {
|
|
78
|
-
await navigatorContribution.closeView();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
afterEach(async () => {
|
|
82
|
-
await editorManager.closeAll({ save: false });
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
after(async () => {
|
|
86
|
-
await shell.leftPanelHandler.collapse();
|
|
87
|
-
toTearDown.dispose();
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* @param {import('@theia/core/lib/common/command').Command} command
|
|
92
|
-
*/
|
|
93
|
-
async function assertEditorFindReplace(command) {
|
|
94
|
-
assert.isFalse(contextKeyService.match('findWidgetVisible'));
|
|
95
|
-
assert.isFalse(contextKeyService.match('findInputFocussed'));
|
|
96
|
-
assert.isFalse(contextKeyService.match('replaceInputFocussed'));
|
|
97
|
-
|
|
98
|
-
keybindings.dispatchCommand(command.id);
|
|
99
|
-
await waitForAnimation(() => contextKeyService.match('findInputFocussed'));
|
|
100
|
-
|
|
101
|
-
assert.isTrue(contextKeyService.match('findWidgetVisible'));
|
|
102
|
-
assert.isTrue(contextKeyService.match('findInputFocussed'));
|
|
103
|
-
assert.isFalse(contextKeyService.match('replaceInputFocussed'));
|
|
104
|
-
|
|
105
|
-
keybindings.dispatchKeyDown('Tab');
|
|
106
|
-
await waitForAnimation(() => !contextKeyService.match('findInputFocussed'));
|
|
107
|
-
assert.isTrue(contextKeyService.match('findWidgetVisible'));
|
|
108
|
-
assert.isFalse(contextKeyService.match('findInputFocussed'));
|
|
109
|
-
assert.equal(contextKeyService.match('replaceInputFocussed'), command === CommonCommands.REPLACE);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
for (const command of [CommonCommands.FIND, CommonCommands.REPLACE]) {
|
|
113
|
-
it(command.label + ' in the active editor', async function () {
|
|
114
|
-
await openExplorer();
|
|
115
|
-
|
|
116
|
-
await openEditor();
|
|
117
|
-
|
|
118
|
-
await assertEditorFindReplace(command);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it(command.label + ' in the active explorer without the current editor', async function () {
|
|
122
|
-
await openExplorer();
|
|
123
|
-
|
|
124
|
-
// should not throw
|
|
125
|
-
await commands.executeCommand(command.id);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it(command.label + ' in the active explorer with the current editor', async function () {
|
|
129
|
-
await openEditor();
|
|
130
|
-
|
|
131
|
-
await openExplorer();
|
|
132
|
-
|
|
133
|
-
await assertEditorFindReplace(command);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async function openExplorer() {
|
|
139
|
-
await navigatorContribution.openView({ activate: true });
|
|
140
|
-
const widget = await shell.revealWidget(EXPLORER_VIEW_CONTAINER_ID);
|
|
141
|
-
assert.isDefined(widget, 'Explorer widget should exist');
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
async function openEditor() {
|
|
145
|
-
await editorManager.open(fileUri, { mode: 'activate' });
|
|
146
|
-
await waitLanguageServerReady();
|
|
147
|
-
const activeEditor = /** @type {MonacoEditor} */ MonacoEditor.get(editorManager.activeEditor);
|
|
148
|
-
assert.isDefined(activeEditor);
|
|
149
|
-
// @ts-ignore
|
|
150
|
-
assert.equal(activeEditor.uri.resolveToAbsolute().toString(), fileUri.resolveToAbsolute().toString());
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
async function waitLanguageServerReady() {
|
|
154
|
-
// quite a bit of jitter in the "Initializing LS" status bar entry,
|
|
155
|
-
// so we want to read a few times in a row that it's done (undefined)
|
|
156
|
-
const MAX_N = 5
|
|
157
|
-
let n = MAX_N;
|
|
158
|
-
while (n > 0) {
|
|
159
|
-
await pause(1);
|
|
160
|
-
if (progressStatusBarItem.currentProgress) {
|
|
161
|
-
n = MAX_N;
|
|
162
|
-
} else {
|
|
163
|
-
n--;
|
|
164
|
-
}
|
|
165
|
-
if (n < 5) {
|
|
166
|
-
console.debug('n = ' + n);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
});
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2020 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
// @ts-check
|
|
18
|
+
describe('Find and Replace', function () {
|
|
19
|
+
this.timeout(20_000);
|
|
20
|
+
const { assert } = chai;
|
|
21
|
+
|
|
22
|
+
const { animationFrame } = require('@theia/core/lib/browser/browser');
|
|
23
|
+
const { DisposableCollection } = require('@theia/core/lib/common/disposable');
|
|
24
|
+
const { CommonCommands } = require('@theia/core/lib/browser/common-frontend-contribution');
|
|
25
|
+
const { EditorManager } = require('@theia/editor/lib/browser/editor-manager');
|
|
26
|
+
const { WorkspaceService } = require('@theia/workspace/lib/browser/workspace-service');
|
|
27
|
+
const { CommandRegistry } = require('@theia/core/lib/common/command');
|
|
28
|
+
const { KeybindingRegistry } = require('@theia/core/lib/browser/keybinding');
|
|
29
|
+
const { ContextKeyService } = require('@theia/core/lib/browser/context-key-service');
|
|
30
|
+
const { FileNavigatorContribution } = require('@theia/navigator/lib/browser/navigator-contribution');
|
|
31
|
+
const { ApplicationShell } = require('@theia/core/lib/browser/shell/application-shell');
|
|
32
|
+
const { HostedPluginSupport } = require('@theia/plugin-ext/lib/hosted/browser/hosted-plugin');
|
|
33
|
+
const { ProgressStatusBarItem } = require('@theia/core/lib/browser/progress-status-bar-item');
|
|
34
|
+
const { EXPLORER_VIEW_CONTAINER_ID } = require('@theia/navigator/lib/browser/navigator-widget-factory');
|
|
35
|
+
const { MonacoEditor } = require('@theia/monaco/lib/browser/monaco-editor');
|
|
36
|
+
const container = window.theia.container;
|
|
37
|
+
const editorManager = container.get(EditorManager);
|
|
38
|
+
const workspaceService = container.get(WorkspaceService);
|
|
39
|
+
const commands = container.get(CommandRegistry);
|
|
40
|
+
const keybindings = container.get(KeybindingRegistry);
|
|
41
|
+
const contextKeyService = container.get(ContextKeyService);
|
|
42
|
+
const navigatorContribution = container.get(FileNavigatorContribution);
|
|
43
|
+
const shell = container.get(ApplicationShell);
|
|
44
|
+
const rootUri = workspaceService.tryGetRoots()[0].resource;
|
|
45
|
+
const pluginService = container.get(HostedPluginSupport);
|
|
46
|
+
const progressStatusBarItem = container.get(ProgressStatusBarItem);
|
|
47
|
+
const fileUri = rootUri.resolve('../api-tests/test-ts-workspace/demo-file.ts');
|
|
48
|
+
|
|
49
|
+
const toTearDown = new DisposableCollection();
|
|
50
|
+
|
|
51
|
+
function pause(ms = 500) {
|
|
52
|
+
console.debug(`pause test for: ${ms} ms`);
|
|
53
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @template T
|
|
58
|
+
* @param {() => Promise<T> | T} condition
|
|
59
|
+
* @returns {Promise<T>}
|
|
60
|
+
*/
|
|
61
|
+
function waitForAnimation(condition) {
|
|
62
|
+
return new Promise(async (resolve, dispose) => {
|
|
63
|
+
toTearDown.push({ dispose });
|
|
64
|
+
do {
|
|
65
|
+
await animationFrame();
|
|
66
|
+
} while (!condition());
|
|
67
|
+
resolve();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
before(async () => {
|
|
72
|
+
await pluginService.didStart;
|
|
73
|
+
await shell.leftPanelHandler.collapse();
|
|
74
|
+
await editorManager.closeAll({ save: false });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
beforeEach(async function () {
|
|
78
|
+
await navigatorContribution.closeView();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
afterEach(async () => {
|
|
82
|
+
await editorManager.closeAll({ save: false });
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
after(async () => {
|
|
86
|
+
await shell.leftPanelHandler.collapse();
|
|
87
|
+
toTearDown.dispose();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @param {import('@theia/core/lib/common/command').Command} command
|
|
92
|
+
*/
|
|
93
|
+
async function assertEditorFindReplace(command) {
|
|
94
|
+
assert.isFalse(contextKeyService.match('findWidgetVisible'));
|
|
95
|
+
assert.isFalse(contextKeyService.match('findInputFocussed'));
|
|
96
|
+
assert.isFalse(contextKeyService.match('replaceInputFocussed'));
|
|
97
|
+
|
|
98
|
+
keybindings.dispatchCommand(command.id);
|
|
99
|
+
await waitForAnimation(() => contextKeyService.match('findInputFocussed'));
|
|
100
|
+
|
|
101
|
+
assert.isTrue(contextKeyService.match('findWidgetVisible'));
|
|
102
|
+
assert.isTrue(contextKeyService.match('findInputFocussed'));
|
|
103
|
+
assert.isFalse(contextKeyService.match('replaceInputFocussed'));
|
|
104
|
+
|
|
105
|
+
keybindings.dispatchKeyDown('Tab');
|
|
106
|
+
await waitForAnimation(() => !contextKeyService.match('findInputFocussed'));
|
|
107
|
+
assert.isTrue(contextKeyService.match('findWidgetVisible'));
|
|
108
|
+
assert.isFalse(contextKeyService.match('findInputFocussed'));
|
|
109
|
+
assert.equal(contextKeyService.match('replaceInputFocussed'), command === CommonCommands.REPLACE);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
for (const command of [CommonCommands.FIND, CommonCommands.REPLACE]) {
|
|
113
|
+
it(command.label + ' in the active editor', async function () {
|
|
114
|
+
await openExplorer();
|
|
115
|
+
|
|
116
|
+
await openEditor();
|
|
117
|
+
|
|
118
|
+
await assertEditorFindReplace(command);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it(command.label + ' in the active explorer without the current editor', async function () {
|
|
122
|
+
await openExplorer();
|
|
123
|
+
|
|
124
|
+
// should not throw
|
|
125
|
+
await commands.executeCommand(command.id);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it(command.label + ' in the active explorer with the current editor', async function () {
|
|
129
|
+
await openEditor();
|
|
130
|
+
|
|
131
|
+
await openExplorer();
|
|
132
|
+
|
|
133
|
+
await assertEditorFindReplace(command);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async function openExplorer() {
|
|
139
|
+
await navigatorContribution.openView({ activate: true });
|
|
140
|
+
const widget = await shell.revealWidget(EXPLORER_VIEW_CONTAINER_ID);
|
|
141
|
+
assert.isDefined(widget, 'Explorer widget should exist');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function openEditor() {
|
|
145
|
+
await editorManager.open(fileUri, { mode: 'activate' });
|
|
146
|
+
await waitLanguageServerReady();
|
|
147
|
+
const activeEditor = /** @type {MonacoEditor} */ MonacoEditor.get(editorManager.activeEditor);
|
|
148
|
+
assert.isDefined(activeEditor);
|
|
149
|
+
// @ts-ignore
|
|
150
|
+
assert.equal(activeEditor.uri.resolveToAbsolute().toString(), fileUri.resolveToAbsolute().toString());
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async function waitLanguageServerReady() {
|
|
154
|
+
// quite a bit of jitter in the "Initializing LS" status bar entry,
|
|
155
|
+
// so we want to read a few times in a row that it's done (undefined)
|
|
156
|
+
const MAX_N = 5
|
|
157
|
+
let n = MAX_N;
|
|
158
|
+
while (n > 0) {
|
|
159
|
+
await pause(1);
|
|
160
|
+
if (progressStatusBarItem.currentProgress) {
|
|
161
|
+
n = MAX_N;
|
|
162
|
+
} else {
|
|
163
|
+
n--;
|
|
164
|
+
}
|
|
165
|
+
if (n < 5) {
|
|
166
|
+
console.debug('n = ' + n);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
});
|