@theia/api-tests 1.34.3 → 1.34.4

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.
@@ -1,193 +1,193 @@
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 WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- // @ts-check
18
- describe('Undo, Redo and Select All', function () {
19
- this.timeout(5000);
20
-
21
- const { assert } = chai;
22
-
23
- const { animationFrame } = require('@theia/core/lib/browser/browser');
24
- const { DisposableCollection } = require('@theia/core/lib/common/disposable');
25
- const { CommonCommands } = require('@theia/core/lib/browser/common-frontend-contribution');
26
- const { EditorManager } = require('@theia/editor/lib/browser/editor-manager');
27
- const { WorkspaceService } = require('@theia/workspace/lib/browser/workspace-service');
28
- const { CommandRegistry } = require('@theia/core/lib/common/command');
29
- const { KeybindingRegistry } = require('@theia/core/lib/browser/keybinding');
30
- const { FileNavigatorContribution } = require('@theia/navigator/lib/browser/navigator-contribution');
31
- const { ApplicationShell } = require('@theia/core/lib/browser/shell/application-shell');
32
- const { MonacoEditor } = require('@theia/monaco/lib/browser/monaco-editor');
33
- const { ScmContribution } = require('@theia/scm/lib/browser/scm-contribution');
34
- const { Range } = require('@theia/monaco-editor-core/esm/vs/editor/common/core/range');
35
- const { PreferenceService, PreferenceScope } = require('@theia/core/lib/browser');
36
-
37
- const container = window.theia.container;
38
- const editorManager = container.get(EditorManager);
39
- const workspaceService = container.get(WorkspaceService);
40
- const commands = container.get(CommandRegistry);
41
- const keybindings = container.get(KeybindingRegistry);
42
- const navigatorContribution = container.get(FileNavigatorContribution);
43
- const shell = container.get(ApplicationShell);
44
- const scmContribution = container.get(ScmContribution);
45
- /** @type {PreferenceService} */
46
- const preferenceService = container.get(PreferenceService)
47
-
48
- const rootUri = workspaceService.tryGetRoots()[0].resource;
49
- const fileUri = rootUri.resolve('webpack.config.js');
50
-
51
- const toTearDown = new DisposableCollection();
52
-
53
- /**
54
- * @template T
55
- * @param {() => Promise<T> | T} condition
56
- * @returns {Promise<T>}
57
- */
58
- function waitForAnimation(condition) {
59
- return new Promise(async (resolve, dispose) => {
60
- toTearDown.push({ dispose });
61
- do {
62
- await animationFrame();
63
- } while (!condition());
64
- resolve(undefined);
65
- });
66
- }
67
- const originalValue = preferenceService.get('files.autoSave', undefined, rootUri.toString());
68
- before(async () => {
69
- await preferenceService.set('files.autoSave', 'off', undefined, rootUri.toString());
70
- shell.leftPanelHandler.collapse();
71
- });
72
-
73
- beforeEach(async function () {
74
- await scmContribution.closeView();
75
- await navigatorContribution.closeView();
76
- await editorManager.closeAll({ save: false });
77
- });
78
-
79
- afterEach(async () => {
80
- toTearDown.dispose();
81
- await scmContribution.closeView();
82
- await navigatorContribution.closeView();
83
- await editorManager.closeAll({ save: false });
84
- });
85
-
86
- after(async () => {
87
- await preferenceService.set('files.autoSave', originalValue, undefined, rootUri.toString());
88
- shell.leftPanelHandler.collapse();
89
- });
90
-
91
- /**
92
- * @param {import('@theia/editor/lib/browser/editor-widget').EditorWidget} widget
93
- */
94
- async function assertInEditor(widget) {
95
- const originalContent = widget.editor.document.getText();
96
- const editor = /** @type {MonacoEditor} */ (MonacoEditor.get(widget));
97
- editor.getControl().pushUndoStop();
98
- editor.getControl().executeEdits('test', [{
99
- range: new Range(1, 1, 1, 1),
100
- text: 'A'
101
- }]);
102
- editor.getControl().pushUndoStop();
103
-
104
- const modifiedContent = widget.editor.document.getText();
105
- assert.notEqual(modifiedContent, originalContent);
106
-
107
- keybindings.dispatchCommand(CommonCommands.UNDO.id);
108
- await waitForAnimation(() => widget.editor.document.getText() === originalContent);
109
- assert.equal(widget.editor.document.getText(), originalContent);
110
-
111
- keybindings.dispatchCommand(CommonCommands.REDO.id);
112
- await waitForAnimation(() => widget.editor.document.getText() === modifiedContent);
113
- assert.equal(widget.editor.document.getText(), modifiedContent);
114
-
115
- const originalSelection = widget.editor.selection;
116
- keybindings.dispatchCommand(CommonCommands.SELECT_ALL.id);
117
- await waitForAnimation(() => widget.editor.selection.end.line !== originalSelection.end.line);
118
- assert.notDeepEqual(widget.editor.selection, originalSelection);
119
- }
120
-
121
- it('in the active editor', async function () {
122
- await navigatorContribution.openView({ activate: true });
123
-
124
- const widget = await editorManager.open(fileUri, { mode: 'activate' });
125
- await assertInEditor(widget);
126
- });
127
-
128
- it('in the active explorer without the current editor', async function () {
129
- await navigatorContribution.openView({ activate: true });
130
-
131
- // should not throw
132
- await commands.executeCommand(CommonCommands.UNDO.id);
133
- await commands.executeCommand(CommonCommands.REDO.id);
134
- await commands.executeCommand(CommonCommands.SELECT_ALL.id);
135
- });
136
-
137
- it('in the active explorer with the current editor', async function () {
138
- const widget = await editorManager.open(fileUri, { mode: 'activate' });
139
-
140
- await navigatorContribution.openView({ activate: true });
141
-
142
- await assertInEditor(widget);
143
- });
144
-
145
- async function assertInScm() {
146
- const scmInput = document.activeElement;
147
- if (!(scmInput instanceof HTMLTextAreaElement)) {
148
- assert.isTrue(scmInput instanceof HTMLTextAreaElement);
149
- return;
150
- }
151
-
152
- const originalValue = scmInput.value;
153
- document.execCommand('insertText', false, 'A');
154
- await waitForAnimation(() => scmInput.value !== originalValue);
155
- const modifiedValue = scmInput.value;
156
- assert.notEqual(originalValue, modifiedValue);
157
-
158
- keybindings.dispatchCommand(CommonCommands.UNDO.id);
159
- await waitForAnimation(() => scmInput.value === originalValue);
160
- assert.equal(scmInput.value, originalValue);
161
-
162
- keybindings.dispatchCommand(CommonCommands.REDO.id);
163
- await waitForAnimation(() => scmInput.value === modifiedValue);
164
- assert.equal(scmInput.value, modifiedValue);
165
-
166
- const selection = document.getSelection();
167
- if (!selection) {
168
- assert.isDefined(selection);
169
- return;
170
- }
171
-
172
- selection.empty();
173
- assert.equal(selection.rangeCount, 0);
174
-
175
- keybindings.dispatchCommand(CommonCommands.SELECT_ALL.id);
176
- await waitForAnimation(() => !!selection.rangeCount);
177
- assert.notEqual(selection.rangeCount, 0);
178
- assert.isTrue(selection.containsNode(scmInput));
179
- }
180
-
181
- it('in the active scm in workspace without the current editor', async function () {
182
- await scmContribution.openView({ activate: true });
183
- await assertInScm();
184
- });
185
-
186
- it('in the active scm in workspace with the current editor', async function () {
187
- await editorManager.open(fileUri, { mode: 'activate' });
188
-
189
- await scmContribution.openView({ activate: true });
190
- await assertInScm();
191
- });
192
-
193
- });
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 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ // @ts-check
18
+ describe('Undo, Redo and Select All', function () {
19
+ this.timeout(5000);
20
+
21
+ const { assert } = chai;
22
+
23
+ const { animationFrame } = require('@theia/core/lib/browser/browser');
24
+ const { DisposableCollection } = require('@theia/core/lib/common/disposable');
25
+ const { CommonCommands } = require('@theia/core/lib/browser/common-frontend-contribution');
26
+ const { EditorManager } = require('@theia/editor/lib/browser/editor-manager');
27
+ const { WorkspaceService } = require('@theia/workspace/lib/browser/workspace-service');
28
+ const { CommandRegistry } = require('@theia/core/lib/common/command');
29
+ const { KeybindingRegistry } = require('@theia/core/lib/browser/keybinding');
30
+ const { FileNavigatorContribution } = require('@theia/navigator/lib/browser/navigator-contribution');
31
+ const { ApplicationShell } = require('@theia/core/lib/browser/shell/application-shell');
32
+ const { MonacoEditor } = require('@theia/monaco/lib/browser/monaco-editor');
33
+ const { ScmContribution } = require('@theia/scm/lib/browser/scm-contribution');
34
+ const { Range } = require('@theia/monaco-editor-core/esm/vs/editor/common/core/range');
35
+ const { PreferenceService, PreferenceScope } = require('@theia/core/lib/browser');
36
+
37
+ const container = window.theia.container;
38
+ const editorManager = container.get(EditorManager);
39
+ const workspaceService = container.get(WorkspaceService);
40
+ const commands = container.get(CommandRegistry);
41
+ const keybindings = container.get(KeybindingRegistry);
42
+ const navigatorContribution = container.get(FileNavigatorContribution);
43
+ const shell = container.get(ApplicationShell);
44
+ const scmContribution = container.get(ScmContribution);
45
+ /** @type {PreferenceService} */
46
+ const preferenceService = container.get(PreferenceService)
47
+
48
+ const rootUri = workspaceService.tryGetRoots()[0].resource;
49
+ const fileUri = rootUri.resolve('webpack.config.js');
50
+
51
+ const toTearDown = new DisposableCollection();
52
+
53
+ /**
54
+ * @template T
55
+ * @param {() => Promise<T> | T} condition
56
+ * @returns {Promise<T>}
57
+ */
58
+ function waitForAnimation(condition) {
59
+ return new Promise(async (resolve, dispose) => {
60
+ toTearDown.push({ dispose });
61
+ do {
62
+ await animationFrame();
63
+ } while (!condition());
64
+ resolve(undefined);
65
+ });
66
+ }
67
+ const originalValue = preferenceService.get('files.autoSave', undefined, rootUri.toString());
68
+ before(async () => {
69
+ await preferenceService.set('files.autoSave', 'off', undefined, rootUri.toString());
70
+ shell.leftPanelHandler.collapse();
71
+ });
72
+
73
+ beforeEach(async function () {
74
+ await scmContribution.closeView();
75
+ await navigatorContribution.closeView();
76
+ await editorManager.closeAll({ save: false });
77
+ });
78
+
79
+ afterEach(async () => {
80
+ toTearDown.dispose();
81
+ await scmContribution.closeView();
82
+ await navigatorContribution.closeView();
83
+ await editorManager.closeAll({ save: false });
84
+ });
85
+
86
+ after(async () => {
87
+ await preferenceService.set('files.autoSave', originalValue, undefined, rootUri.toString());
88
+ shell.leftPanelHandler.collapse();
89
+ });
90
+
91
+ /**
92
+ * @param {import('@theia/editor/lib/browser/editor-widget').EditorWidget} widget
93
+ */
94
+ async function assertInEditor(widget) {
95
+ const originalContent = widget.editor.document.getText();
96
+ const editor = /** @type {MonacoEditor} */ (MonacoEditor.get(widget));
97
+ editor.getControl().pushUndoStop();
98
+ editor.getControl().executeEdits('test', [{
99
+ range: new Range(1, 1, 1, 1),
100
+ text: 'A'
101
+ }]);
102
+ editor.getControl().pushUndoStop();
103
+
104
+ const modifiedContent = widget.editor.document.getText();
105
+ assert.notEqual(modifiedContent, originalContent);
106
+
107
+ keybindings.dispatchCommand(CommonCommands.UNDO.id);
108
+ await waitForAnimation(() => widget.editor.document.getText() === originalContent);
109
+ assert.equal(widget.editor.document.getText(), originalContent);
110
+
111
+ keybindings.dispatchCommand(CommonCommands.REDO.id);
112
+ await waitForAnimation(() => widget.editor.document.getText() === modifiedContent);
113
+ assert.equal(widget.editor.document.getText(), modifiedContent);
114
+
115
+ const originalSelection = widget.editor.selection;
116
+ keybindings.dispatchCommand(CommonCommands.SELECT_ALL.id);
117
+ await waitForAnimation(() => widget.editor.selection.end.line !== originalSelection.end.line);
118
+ assert.notDeepEqual(widget.editor.selection, originalSelection);
119
+ }
120
+
121
+ it('in the active editor', async function () {
122
+ await navigatorContribution.openView({ activate: true });
123
+
124
+ const widget = await editorManager.open(fileUri, { mode: 'activate' });
125
+ await assertInEditor(widget);
126
+ });
127
+
128
+ it('in the active explorer without the current editor', async function () {
129
+ await navigatorContribution.openView({ activate: true });
130
+
131
+ // should not throw
132
+ await commands.executeCommand(CommonCommands.UNDO.id);
133
+ await commands.executeCommand(CommonCommands.REDO.id);
134
+ await commands.executeCommand(CommonCommands.SELECT_ALL.id);
135
+ });
136
+
137
+ it('in the active explorer with the current editor', async function () {
138
+ const widget = await editorManager.open(fileUri, { mode: 'activate' });
139
+
140
+ await navigatorContribution.openView({ activate: true });
141
+
142
+ await assertInEditor(widget);
143
+ });
144
+
145
+ async function assertInScm() {
146
+ const scmInput = document.activeElement;
147
+ if (!(scmInput instanceof HTMLTextAreaElement)) {
148
+ assert.isTrue(scmInput instanceof HTMLTextAreaElement);
149
+ return;
150
+ }
151
+
152
+ const originalValue = scmInput.value;
153
+ document.execCommand('insertText', false, 'A');
154
+ await waitForAnimation(() => scmInput.value !== originalValue);
155
+ const modifiedValue = scmInput.value;
156
+ assert.notEqual(originalValue, modifiedValue);
157
+
158
+ keybindings.dispatchCommand(CommonCommands.UNDO.id);
159
+ await waitForAnimation(() => scmInput.value === originalValue);
160
+ assert.equal(scmInput.value, originalValue);
161
+
162
+ keybindings.dispatchCommand(CommonCommands.REDO.id);
163
+ await waitForAnimation(() => scmInput.value === modifiedValue);
164
+ assert.equal(scmInput.value, modifiedValue);
165
+
166
+ const selection = document.getSelection();
167
+ if (!selection) {
168
+ assert.isDefined(selection);
169
+ return;
170
+ }
171
+
172
+ selection.empty();
173
+ assert.equal(selection.rangeCount, 0);
174
+
175
+ keybindings.dispatchCommand(CommonCommands.SELECT_ALL.id);
176
+ await waitForAnimation(() => !!selection.rangeCount);
177
+ assert.notEqual(selection.rangeCount, 0);
178
+ assert.isTrue(selection.containsNode(scmInput));
179
+ }
180
+
181
+ it('in the active scm in workspace without the current editor', async function () {
182
+ await scmContribution.openView({ activate: true });
183
+ await assertInScm();
184
+ });
185
+
186
+ it('in the active scm in workspace with the current editor', async function () {
187
+ await editorManager.open(fileUri, { mode: 'activate' });
188
+
189
+ await scmContribution.openView({ activate: true });
190
+ await assertInScm();
191
+ });
192
+
193
+ });
package/src/views.spec.js CHANGED
@@ -1,76 +1,76 @@
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 WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- // @ts-check
18
- describe('Views', function () {
19
- this.timeout(7500);
20
-
21
- const { assert } = chai;
22
-
23
- const { ApplicationShell } = require('@theia/core/lib/browser/shell/application-shell');
24
- const { FileNavigatorContribution } = require('@theia/navigator/lib/browser/navigator-contribution');
25
- const { ScmContribution } = require('@theia/scm/lib/browser/scm-contribution');
26
- const { OutlineViewContribution } = require('@theia/outline-view/lib/browser/outline-view-contribution');
27
- const { ProblemContribution } = require('@theia/markers/lib/browser/problem/problem-contribution');
28
- const { PropertyViewContribution } = require('@theia/property-view/lib/browser/property-view-contribution');
29
- const { HostedPluginSupport } = require('@theia/plugin-ext/lib/hosted/browser/hosted-plugin');
30
-
31
- /** @type {import('inversify').Container} */
32
- const container = window['theia'].container;
33
- const shell = container.get(ApplicationShell);
34
- const navigatorContribution = container.get(FileNavigatorContribution);
35
- const scmContribution = container.get(ScmContribution);
36
- const outlineContribution = container.get(OutlineViewContribution);
37
- const problemContribution = container.get(ProblemContribution);
38
- const propertyViewContribution = container.get(PropertyViewContribution);
39
- const pluginService = container.get(HostedPluginSupport);
40
-
41
- before(() => Promise.all([
42
- shell.leftPanelHandler.collapse(),
43
- (async function () {
44
- await pluginService.didStart;
45
- await pluginService.activateByViewContainer('explorer');
46
- })()
47
- ]));
48
-
49
- for (const contribution of [navigatorContribution, scmContribution, outlineContribution, problemContribution, propertyViewContribution]) {
50
- it(`should toggle ${contribution.viewLabel}`, async function () {
51
- let view = await contribution.closeView();
52
- if (view) {
53
- assert.notEqual(shell.getAreaFor(view), contribution.defaultViewOptions.area);
54
- assert.isFalse(view.isVisible);
55
- assert.notEqual(view, shell.activeWidget);
56
- }
57
-
58
- view = await contribution.toggleView();
59
- assert.notEqual(view, undefined);
60
- assert.equal(shell.getAreaFor(view), contribution.defaultViewOptions.area);
61
- assert.isDefined(shell.getTabBarFor(view));
62
- // @ts-ignore
63
- assert.equal(shell.getAreaFor(shell.getTabBarFor(view)), contribution.defaultViewOptions.area);
64
- assert.isTrue(view.isVisible);
65
- assert.equal(view, shell.activeWidget);
66
-
67
- view = await contribution.toggleView();
68
- assert.notEqual(view, undefined);
69
- assert.equal(shell.getAreaFor(view), contribution.defaultViewOptions.area);
70
- assert.isDefined(shell.getTabBarFor(view));
71
- assert.isFalse(view.isVisible);
72
- assert.notEqual(view, shell.activeWidget);
73
- });
74
- }
75
-
76
- });
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 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ // @ts-check
18
+ describe('Views', function () {
19
+ this.timeout(7500);
20
+
21
+ const { assert } = chai;
22
+
23
+ const { ApplicationShell } = require('@theia/core/lib/browser/shell/application-shell');
24
+ const { FileNavigatorContribution } = require('@theia/navigator/lib/browser/navigator-contribution');
25
+ const { ScmContribution } = require('@theia/scm/lib/browser/scm-contribution');
26
+ const { OutlineViewContribution } = require('@theia/outline-view/lib/browser/outline-view-contribution');
27
+ const { ProblemContribution } = require('@theia/markers/lib/browser/problem/problem-contribution');
28
+ const { PropertyViewContribution } = require('@theia/property-view/lib/browser/property-view-contribution');
29
+ const { HostedPluginSupport } = require('@theia/plugin-ext/lib/hosted/browser/hosted-plugin');
30
+
31
+ /** @type {import('inversify').Container} */
32
+ const container = window['theia'].container;
33
+ const shell = container.get(ApplicationShell);
34
+ const navigatorContribution = container.get(FileNavigatorContribution);
35
+ const scmContribution = container.get(ScmContribution);
36
+ const outlineContribution = container.get(OutlineViewContribution);
37
+ const problemContribution = container.get(ProblemContribution);
38
+ const propertyViewContribution = container.get(PropertyViewContribution);
39
+ const pluginService = container.get(HostedPluginSupport);
40
+
41
+ before(() => Promise.all([
42
+ shell.leftPanelHandler.collapse(),
43
+ (async function () {
44
+ await pluginService.didStart;
45
+ await pluginService.activateByViewContainer('explorer');
46
+ })()
47
+ ]));
48
+
49
+ for (const contribution of [navigatorContribution, scmContribution, outlineContribution, problemContribution, propertyViewContribution]) {
50
+ it(`should toggle ${contribution.viewLabel}`, async function () {
51
+ let view = await contribution.closeView();
52
+ if (view) {
53
+ assert.notEqual(shell.getAreaFor(view), contribution.defaultViewOptions.area);
54
+ assert.isFalse(view.isVisible);
55
+ assert.notEqual(view, shell.activeWidget);
56
+ }
57
+
58
+ view = await contribution.toggleView();
59
+ assert.notEqual(view, undefined);
60
+ assert.equal(shell.getAreaFor(view), contribution.defaultViewOptions.area);
61
+ assert.isDefined(shell.getTabBarFor(view));
62
+ // @ts-ignore
63
+ assert.equal(shell.getAreaFor(shell.getTabBarFor(view)), contribution.defaultViewOptions.area);
64
+ assert.isTrue(view.isVisible);
65
+ assert.equal(view, shell.activeWidget);
66
+
67
+ view = await contribution.toggleView();
68
+ assert.notEqual(view, undefined);
69
+ assert.equal(shell.getAreaFor(view), contribution.defaultViewOptions.area);
70
+ assert.isDefined(shell.getTabBarFor(view));
71
+ assert.isFalse(view.isVisible);
72
+ assert.notEqual(view, shell.activeWidget);
73
+ });
74
+ }
75
+
76
+ });