@theia/playwright 1.37.0-next.3 → 1.37.0-next.30

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.
Files changed (93) hide show
  1. package/lib/index.d.ts +4 -0
  2. package/lib/index.d.ts.map +1 -1
  3. package/lib/index.js +4 -0
  4. package/lib/index.js.map +1 -1
  5. package/lib/tests/theia-explorer-view.test.js +24 -5
  6. package/lib/tests/theia-explorer-view.test.js.map +1 -1
  7. package/lib/tests/theia-main-menu.test.js +2 -2
  8. package/lib/tests/theia-main-menu.test.js.map +1 -1
  9. package/lib/tests/theia-output-view.test.d.ts +2 -0
  10. package/lib/tests/theia-output-view.test.d.ts.map +1 -0
  11. package/lib/tests/theia-output-view.test.js +77 -0
  12. package/lib/tests/theia-output-view.test.js.map +1 -0
  13. package/lib/tests/theia-quick-command.test.js +14 -0
  14. package/lib/tests/theia-quick-command.test.js.map +1 -1
  15. package/lib/tests/theia-sample-app.test.js +3 -30
  16. package/lib/tests/theia-sample-app.test.js.map +1 -1
  17. package/lib/tests/theia-terminal-view.test.d.ts +2 -0
  18. package/lib/tests/theia-terminal-view.test.d.ts.map +1 -0
  19. package/lib/tests/theia-terminal-view.test.js +76 -0
  20. package/lib/tests/theia-terminal-view.test.js.map +1 -0
  21. package/lib/tests/theia-toolbar.test.d.ts +2 -0
  22. package/lib/tests/theia-toolbar.test.d.ts.map +1 -0
  23. package/lib/tests/theia-toolbar.test.js +60 -0
  24. package/lib/tests/theia-toolbar.test.js.map +1 -0
  25. package/lib/tests/theia-workspace.test.js +5 -3
  26. package/lib/tests/theia-workspace.test.js.map +1 -1
  27. package/lib/theia-app.d.ts +7 -0
  28. package/lib/theia-app.d.ts.map +1 -1
  29. package/lib/theia-app.js +30 -1
  30. package/lib/theia-app.js.map +1 -1
  31. package/lib/theia-explorer-view.d.ts +6 -4
  32. package/lib/theia-explorer-view.d.ts.map +1 -1
  33. package/lib/theia-explorer-view.js +38 -6
  34. package/lib/theia-explorer-view.js.map +1 -1
  35. package/lib/theia-monaco-editor.d.ts +16 -0
  36. package/lib/theia-monaco-editor.d.ts.map +1 -0
  37. package/lib/theia-monaco-editor.js +76 -0
  38. package/lib/theia-monaco-editor.js.map +1 -0
  39. package/lib/theia-output-channel.d.ts +25 -0
  40. package/lib/theia-output-channel.d.ts.map +1 -0
  41. package/lib/theia-output-channel.js +72 -0
  42. package/lib/theia-output-channel.js.map +1 -0
  43. package/lib/theia-output-view.d.ts +10 -0
  44. package/lib/theia-output-view.d.ts.map +1 -0
  45. package/lib/theia-output-view.js +82 -0
  46. package/lib/theia-output-view.js.map +1 -0
  47. package/lib/theia-quick-command-palette.d.ts +2 -1
  48. package/lib/theia-quick-command-palette.d.ts.map +1 -1
  49. package/lib/theia-quick-command-palette.js +9 -2
  50. package/lib/theia-quick-command-palette.js.map +1 -1
  51. package/lib/theia-terminal.d.ts +14 -0
  52. package/lib/theia-terminal.d.ts.map +1 -0
  53. package/lib/theia-terminal.js +60 -0
  54. package/lib/theia-terminal.js.map +1 -0
  55. package/lib/theia-text-editor.d.ts +2 -3
  56. package/lib/theia-text-editor.d.ts.map +1 -1
  57. package/lib/theia-text-editor.js +11 -40
  58. package/lib/theia-text-editor.js.map +1 -1
  59. package/lib/theia-toolbar-item.d.ts +11 -0
  60. package/lib/theia-toolbar-item.d.ts.map +1 -0
  61. package/lib/theia-toolbar-item.js +40 -0
  62. package/lib/theia-toolbar-item.js.map +1 -0
  63. package/lib/theia-toolbar.d.ts +20 -0
  64. package/lib/theia-toolbar.d.ts.map +1 -0
  65. package/lib/theia-toolbar.js +91 -0
  66. package/lib/theia-toolbar.js.map +1 -0
  67. package/lib/theia-tree-node.d.ts +1 -0
  68. package/lib/theia-tree-node.d.ts.map +1 -1
  69. package/lib/theia-tree-node.js +8 -0
  70. package/lib/theia-tree-node.js.map +1 -1
  71. package/package.json +13 -10
  72. package/src/index.ts +4 -0
  73. package/src/tests/resources/sample-files1/sampleFolderCompact/nestedFolder1/nestedFolder2/sampleFile1-1.txt +0 -0
  74. package/src/tests/theia-explorer-view.test.ts +25 -6
  75. package/src/tests/theia-main-menu.test.ts +2 -2
  76. package/src/tests/theia-output-view.test.ts +85 -0
  77. package/src/tests/theia-quick-command.test.ts +15 -0
  78. package/src/tests/theia-sample-app.test.ts +3 -34
  79. package/src/tests/theia-terminal-view.test.ts +85 -0
  80. package/src/tests/theia-toolbar.test.ts +65 -0
  81. package/src/tests/theia-workspace.test.ts +5 -3
  82. package/src/theia-app.ts +37 -1
  83. package/src/theia-explorer-view.ts +42 -7
  84. package/src/theia-monaco-editor.ts +83 -0
  85. package/src/theia-output-channel.ts +88 -0
  86. package/src/theia-output-view.ts +87 -0
  87. package/src/theia-quick-command-palette.ts +10 -2
  88. package/src/theia-terminal.ts +69 -0
  89. package/src/theia-text-editor.ts +13 -44
  90. package/src/theia-toolbar-item.ts +41 -0
  91. package/src/theia-toolbar.ts +99 -0
  92. package/src/theia-tree-node.ts +10 -1
  93. package/LICENSE +0 -642
@@ -54,24 +54,29 @@ test.describe('Theia Explorer View', () => {
54
54
  expect(await explorer.isActive()).toBe(true);
55
55
  });
56
56
 
57
- test('should show one folder named "sampleFolder" and one file named "sample.txt"', async () => {
57
+ test('should show one folder named "sampleFolder", one named "sampleFolderCompact" and one file named "sample.txt"', async () => {
58
58
  await explorer.selectTreeNode('sampleFolder');
59
59
  expect(await explorer.isTreeNodeSelected('sampleFolder')).toBe(true);
60
60
  const fileStatElements = await explorer.visibleFileStatNodes(DOT_FILES_FILTER);
61
- expect(fileStatElements.length).toBe(2);
61
+ expect(fileStatElements.length).toBe(3);
62
62
 
63
- let file; let folder;
63
+ let file; let folder; let compactFolder;
64
64
  if (await fileStatElements[0].isFolder()) {
65
65
  folder = fileStatElements[0];
66
- file = fileStatElements[1];
66
+ compactFolder = fileStatElements[1];
67
+ file = fileStatElements[2];
67
68
  } else {
68
- folder = fileStatElements[1];
69
+ folder = fileStatElements[2];
70
+ compactFolder = fileStatElements[1];
69
71
  file = fileStatElements[0];
70
72
  }
71
73
 
72
74
  expect(await folder.label()).toBe('sampleFolder');
73
75
  expect(await folder.isFile()).toBe(false);
74
76
  expect(await folder.isFolder()).toBe(true);
77
+ expect(await compactFolder.label()).toBe('sampleFolderCompact');
78
+ expect(await compactFolder.isFile()).toBe(false);
79
+ expect(await compactFolder.isFolder()).toBe(true);
75
80
  expect(await file.label()).toBe('sample.txt');
76
81
  expect(await file.isFolder()).toBe(false);
77
82
  expect(await file.isFile()).toBe(true);
@@ -84,7 +89,7 @@ test.describe('Theia Explorer View', () => {
84
89
  expect(await file.isFile()).toBe(true);
85
90
  });
86
91
 
87
- test('should provide file stat nodes that can define whether they are collapsed or not and that can be expanded', async () => {
92
+ test('should provide file stat nodes that can define whether they are collapsed or not and that can be expanded and collapsed', async () => {
88
93
  const file = await explorer.getFileStatNodeByLabel('sample.txt');
89
94
  expect(await file.isCollapsed()).toBe(false);
90
95
 
@@ -93,6 +98,9 @@ test.describe('Theia Explorer View', () => {
93
98
 
94
99
  await folder.expand();
95
100
  expect(await folder.isCollapsed()).toBe(false);
101
+
102
+ await folder.collapse();
103
+ expect(await folder.isCollapsed()).toBe(true);
96
104
  });
97
105
 
98
106
  test('should provide file stat node by path "sampleFolder/sampleFolder1/sampleFolder1-1/sampleFile1-1-1.txt"', async () => {
@@ -101,6 +109,17 @@ test.describe('Theia Explorer View', () => {
101
109
  expect(await file.label()).toBe('sampleFile1-1-1.txt');
102
110
  });
103
111
 
112
+ test('should be able to check if compact folder "sampleFolderCompact/nestedFolder1/nestedFolder2" exists', async () => {
113
+ // default setting `explorer.compactFolders=true` renders folders in a compact form - single child folders will be compressed in a combined tree element
114
+ expect(await explorer.existsDirectoryNode('sampleFolderCompact/nestedFolder1/nestedFolder2', true /* compact */)).toBe(true);
115
+ });
116
+
117
+ test('should provide file stat node by path of compact folder "sampleFolderCompact/nestedFolder1/nestedFolder2/sampleFile1-1.txt"', async () => {
118
+ const file = await explorer.fileStatNode('sampleFolderCompact/nestedFolder1/nestedFolder2/sampleFile1-1.txt', true /* compact */);
119
+ if (!file) { throw Error('File stat node could not be retrieved by path'); }
120
+ expect(await file.label()).toBe('sampleFile1-1.txt');
121
+ });
122
+
104
123
  test('should open context menu on "sample.txt"', async () => {
105
124
  const file = await explorer.getFileStatNodeByLabel('sample.txt');
106
125
  const menu = await file.openContextMenu();
@@ -74,10 +74,10 @@ test.describe('Theia Main Menu', () => {
74
74
 
75
75
  test('should be able to show menu item in submenu by path', async () => {
76
76
  const mainMenu = await menuBar.openMenu('File');
77
- const openPreferencesItem = await mainMenu.menuItemByNamePath('Preferences', 'Open Settings (UI)');
77
+ const openPreferencesItem = await mainMenu.menuItemByNamePath('Preferences', 'Settings');
78
78
 
79
79
  const label = await openPreferencesItem?.label();
80
- expect(label).toBe('Open Settings (UI)');
80
+ expect(label).toBe('Settings');
81
81
  });
82
82
 
83
83
  test('should close main menu', async () => {
@@ -0,0 +1,85 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 EclipseSource 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
+ import { expect } from '@playwright/test';
18
+ import { TheiaOutputViewChannel } from 'src/theia-output-channel';
19
+ import { TheiaApp } from '../theia-app';
20
+ import { TheiaOutputView } from '../theia-output-view';
21
+ import test, { page } from './fixtures/theia-fixture';
22
+
23
+ let app: TheiaApp;
24
+ let outputView: TheiaOutputView;
25
+ let testChannel: TheiaOutputViewChannel;
26
+
27
+ test.describe('Theia Output View', () => {
28
+
29
+ test.beforeAll(async () => {
30
+ app = await TheiaApp.load(page);
31
+ });
32
+
33
+ test('should open the output view and check if is visible and active', async () => {
34
+ outputView = await app.openView(TheiaOutputView);
35
+ expect(await outputView.isTabVisible()).toBe(true);
36
+ expect(await outputView.isDisplayed()).toBe(true);
37
+ expect(await outputView.isActive()).toBe(true);
38
+ });
39
+ test('should be opened at the bottom and have the title "Output"', async () => {
40
+ expect(await outputView.isInSidePanel()).toBe(false);
41
+ expect(await outputView.side()).toBe('bottom');
42
+ expect(await outputView.title()).toBe('Output');
43
+ });
44
+ test('should be closable', async () => {
45
+ expect(await outputView.isClosable()).toBe(true);
46
+ await outputView.close();
47
+ expect(await outputView.isTabVisible()).toBe(false);
48
+ expect(await outputView.isDisplayed()).toBe(false);
49
+ expect(await outputView.isActive()).toBe(false);
50
+ });
51
+ test('should select a test output channel', async () => {
52
+ outputView = await app.openView(TheiaOutputView);
53
+ expect(await outputView.isTabVisible()).toBe(true);
54
+ expect(await outputView.isDisplayed()).toBe(true);
55
+ expect(await outputView.isActive()).toBe(true);
56
+
57
+ const testChannelName = 'API Sample: my test channel';
58
+ expect(await outputView.selectOutputChannel(testChannelName)).toBe(true);
59
+ });
60
+ test('should check if the output view of the test output channel', async () => {
61
+ const testChannelName = 'API Sample: my test channel';
62
+ expect(await outputView.isOutputChannelSelected(testChannelName));
63
+ const channel = await outputView.getOutputChannel(testChannelName);
64
+ expect(channel).toBeDefined;
65
+ testChannel = channel!;
66
+ expect(await testChannel!.isDisplayed()).toBe(true);
67
+ });
68
+ test('should check if the output view test channel shows the test output', async () => {
69
+ expect(await testChannel.numberOfLines()).toBe(5);
70
+ expect(await testChannel.textContentOfLineByLineNumber(1)).toMatch('hello info1');
71
+ expect(await testChannel.maxSeverityOfLineByLineNumber(1)).toMatch('info');
72
+ expect(await testChannel.textContentOfLineByLineNumber(2)).toMatch('hello info2');
73
+ expect(await testChannel.maxSeverityOfLineByLineNumber(2)).toMatch('info');
74
+ expect(await testChannel.textContentOfLineByLineNumber(3)).toMatch('hello error');
75
+ expect(await testChannel.maxSeverityOfLineByLineNumber(3)).toMatch('error');
76
+ expect(await testChannel.textContentOfLineByLineNumber(4)).toMatch('hello warning');
77
+ expect(await testChannel.maxSeverityOfLineByLineNumber(4)).toMatch('warning');
78
+ expect(await testChannel.textContentOfLineByLineNumber(5)).toMatch(
79
+ 'inlineInfo1 inlineWarning inlineError inlineInfo2'
80
+ );
81
+ expect(await testChannel.maxSeverityOfLineByLineNumber(5)).toMatch('error');
82
+ });
83
+
84
+ });
85
+
@@ -18,6 +18,8 @@ import { expect } from '@playwright/test';
18
18
  import { TheiaAboutDialog } from '../theia-about-dialog';
19
19
  import { TheiaApp } from '../theia-app';
20
20
  import { TheiaExplorerView } from '../theia-explorer-view';
21
+ import { TheiaNotificationIndicator } from '../theia-notification-indicator';
22
+ import { TheiaNotificationOverlay } from '../theia-notification-overlay';
21
23
  import { TheiaQuickCommandPalette } from '../theia-quick-command-palette';
22
24
  import test, { page } from './fixtures/theia-fixture';
23
25
 
@@ -34,6 +36,10 @@ test.describe('Theia Quick Command', () => {
34
36
  test('should show quick command palette', async () => {
35
37
  await quickCommand.open();
36
38
  expect(await quickCommand.isOpen()).toBe(true);
39
+ await quickCommand.hide();
40
+ expect(await quickCommand.isOpen()).toBe(false);
41
+ await quickCommand.open();
42
+ expect(await quickCommand.isOpen()).toBe(true);
37
43
  });
38
44
 
39
45
  test('should trigger \'About\' command after typing', async () => {
@@ -58,4 +64,13 @@ test.describe('Theia Quick Command', () => {
58
64
  expect(await explorerView.isDisplayed()).toBe(true);
59
65
  });
60
66
 
67
+ test('should trigger \'Quick Input: Test Positive Integer\' command by confirming via Enter', async () => {
68
+ await quickCommand.type('Test Positive', true);
69
+ expect(await quickCommand.isOpen()).toBe(true);
70
+ await quickCommand.type('6', true);
71
+ const notificationIndicator = new TheiaNotificationIndicator(app);
72
+ const notification = new TheiaNotificationOverlay(app, notificationIndicator);
73
+ expect(await notification.isEntryVisible('Positive Integer: 6')).toBe(true);
74
+ });
75
+
61
76
  });
@@ -14,44 +14,13 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- import { TheiaApp } from '../theia-app';
18
-
19
17
  import { expect } from '@playwright/test';
18
+ import { TheiaApp } from '../theia-app';
19
+ import { TheiaToolbar } from '../theia-toolbar';
20
20
  import test, { page } from './fixtures/theia-fixture';
21
- import { TheiaPageObject } from '../theia-page-object';
22
-
23
- class TheiaSampleToolbar extends TheiaPageObject {
24
- protected selector = '#main-toolbar';
25
-
26
- async show(): Promise<void> {
27
- if (!await this.isShown()) {
28
- await this.toggle();
29
- }
30
- }
31
-
32
- async toggle(): Promise<void> {
33
- const isShown = await this.isShown();
34
- const viewMenu = await this.app.menuBar.openMenu('View');
35
- await viewMenu.clickMenuItem('Toggle Toolbar');
36
- isShown ? await this.waitUntilHidden() : await this.waitUntilShown();
37
- }
38
-
39
- async waitUntilHidden(): Promise<void> {
40
- await this.page.waitForSelector(this.selector, { state: 'hidden' });
41
- }
42
-
43
- async waitUntilShown(): Promise<void> {
44
- await this.page.waitForSelector(this.selector, { state: 'visible' });
45
- }
46
-
47
- async isShown(): Promise<boolean> {
48
- const toolbar = await this.page.$(this.selector);
49
- return !!toolbar && toolbar.isVisible();
50
- }
51
- }
52
21
 
53
22
  class TheiaSampleApp extends TheiaApp {
54
- protected toolbar = new TheiaSampleToolbar(this);
23
+ protected toolbar = new TheiaToolbar(this);
55
24
 
56
25
  override async waitForInitialized(): Promise<void> {
57
26
  await this.toolbar.show();
@@ -0,0 +1,85 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 EclipseSource 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
+ import { expect } from '@playwright/test';
18
+ import { TheiaApp } from '../theia-app';
19
+ import { TheiaWorkspace } from '../theia-workspace';
20
+ import test, { page } from './fixtures/theia-fixture';
21
+ import { TheiaTerminal } from '../theia-terminal';
22
+
23
+ let app: TheiaApp;
24
+
25
+ test.describe('Theia Terminal View', () => {
26
+
27
+ test.beforeAll(async () => {
28
+ const ws = new TheiaWorkspace(['src/tests/resources/sample-files1']);
29
+ app = await TheiaApp.load(page, ws);
30
+ });
31
+
32
+ test('should be possible to open a new terminal', async () => {
33
+ const terminal = await app.openTerminal(TheiaTerminal);
34
+ expect(await terminal.isTabVisible()).toBe(true);
35
+ expect(await terminal.isDisplayed()).toBe(true);
36
+ expect(await terminal.isActive()).toBe(true);
37
+ });
38
+
39
+ test('should be possible to open two terminals, switch among them, and close them', async () => {
40
+ const terminal1 = await app.openTerminal(TheiaTerminal);
41
+ const terminal2 = await app.openTerminal(TheiaTerminal);
42
+ const allTerminals = [terminal1, terminal2];
43
+
44
+ // all terminal tabs should be visible
45
+ for (const terminal of allTerminals) {
46
+ expect(await terminal.isTabVisible()).toBe(true);
47
+ }
48
+
49
+ // activate one terminal after the other and check that only this terminal is active
50
+ for (const terminal of allTerminals) {
51
+ await terminal.activate();
52
+ expect(await terminal1.isActive()).toBe(terminal1 === terminal);
53
+ expect(await terminal2.isActive()).toBe(terminal2 === terminal);
54
+ }
55
+
56
+ // close all terminals
57
+ for (const terminal of allTerminals) {
58
+ await terminal.close();
59
+ }
60
+
61
+ // check that all terminals are closed
62
+ for (const terminal of allTerminals) {
63
+ expect(await terminal.isTabVisible()).toBe(false);
64
+ }
65
+ });
66
+
67
+ test('should allow to write and read terminal contents', async () => {
68
+ const terminal = await app.openTerminal(TheiaTerminal);
69
+ await terminal.write('hello');
70
+ const contents = await terminal.contents();
71
+ expect(contents).toContain('hello');
72
+ });
73
+
74
+ test('should allow to submit a command and read output', async () => {
75
+ const terminal = await app.openTerminal(TheiaTerminal);
76
+ if (process.platform === 'win32') {
77
+ await terminal.submit('dir');
78
+ } else {
79
+ await terminal.submit('ls');
80
+ }
81
+ const contents = await terminal.contents();
82
+ expect(contents).toContain('sample.txt');
83
+ });
84
+
85
+ });
@@ -0,0 +1,65 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 EclipseSource 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
+ import { expect } from '@playwright/test';
18
+ import { TheiaApp } from '../theia-app';
19
+ import { TheiaToolbar } from '../theia-toolbar';
20
+ import test, { page } from './fixtures/theia-fixture';
21
+
22
+ let app: TheiaApp;
23
+ let toolbar: TheiaToolbar;
24
+
25
+ test.describe('Theia Toolbar', () => {
26
+
27
+ test.beforeAll(async () => {
28
+ app = await TheiaApp.load(page);
29
+ toolbar = new TheiaToolbar(app);
30
+ });
31
+
32
+ test('should toggle the toolbar and check visibility', async () => {
33
+ // depending on the user settings we have different starting conditions for the toolbar
34
+ const isShownInitially = await toolbar.isShown();
35
+ expect(await toolbar.isShown()).toBe(isShownInitially);
36
+ await toolbar.toggle();
37
+ expect(await toolbar.isShown()).toBe(!isShownInitially);
38
+ await toolbar.hide();
39
+ expect(await toolbar.isShown()).toBe(false);
40
+ await toolbar.show();
41
+ expect(await toolbar.isShown()).toBe(true);
42
+ });
43
+
44
+ test('should show the default toolbar tools of the sample Theia application', async () => {
45
+ expect(await toolbar.toolbarItems()).toHaveLength(5);
46
+ expect(await toolbar.toolbarItemIds()).toStrictEqual([
47
+ 'textEditor.commands.go.back',
48
+ 'textEditor.commands.go.forward',
49
+ 'workbench.action.splitEditorRight',
50
+ 'theia-sample-toolbar-contribution',
51
+ 'workbench.action.showCommands'
52
+ ]);
53
+ });
54
+
55
+ test('should trigger the "Command Palette" toolbar tool as expect the command palette to open', async () => {
56
+ const commandPaletteTool = await toolbar.toolBarItem('workbench.action.showCommands');
57
+ expect(commandPaletteTool).toBeDefined;
58
+ expect(await commandPaletteTool!.isEnabled()).toBe(true);
59
+
60
+ await commandPaletteTool!.trigger();
61
+ expect(await app.quickCommandPalette.isOpen()).toBe(true);
62
+ await app.quickCommandPalette.hide();
63
+ expect(await app.quickCommandPalette.isOpen()).toBe(false);
64
+ });
65
+ });
@@ -14,10 +14,10 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
+ import { expect } from '@playwright/test';
17
18
  import { TheiaApp } from '../theia-app';
18
19
  import { DOT_FILES_FILTER, TheiaExplorerView } from '../theia-explorer-view';
19
20
  import { TheiaWorkspace } from '../theia-workspace';
20
- import { expect } from '@playwright/test';
21
21
  import test, { page } from './fixtures/theia-fixture';
22
22
 
23
23
  test.describe('Theia Workspace', () => {
@@ -33,8 +33,9 @@ test.describe('Theia Workspace', () => {
33
33
  const ws = new TheiaWorkspace(['src/tests/resources/sample-files1']);
34
34
  const app = await TheiaApp.load(page, ws);
35
35
  const explorer = await app.openView(TheiaExplorerView);
36
- // resources/sample-files1 contains one folder and one file
36
+ // resources/sample-files1 contains two folders and one file
37
37
  expect(await explorer.existsDirectoryNode('sampleFolder')).toBe(true);
38
+ expect(await explorer.existsDirectoryNode('sampleFolderCompact')).toBe(true);
38
39
  expect(await explorer.existsFileNode('sample.txt')).toBe(true);
39
40
  });
40
41
 
@@ -42,8 +43,9 @@ test.describe('Theia Workspace', () => {
42
43
  const ws = new TheiaWorkspace(['src/tests/resources/sample-files1', 'src/tests/resources/sample-files2']);
43
44
  const app = await TheiaApp.load(page, ws);
44
45
  const explorer = await app.openView(TheiaExplorerView);
45
- // resources/sample-files1 contains one folder and one file
46
+ // resources/sample-files1 contains two folders and one file
46
47
  expect(await explorer.existsDirectoryNode('sampleFolder')).toBe(true);
48
+ expect(await explorer.existsDirectoryNode('sampleFolderCompact')).toBe(true);
47
49
  expect(await explorer.existsFileNode('sample.txt')).toBe(true);
48
50
  // resources/sample-files2 contains one file
49
51
  expect(await explorer.existsFileNode('another-sample.txt')).toBe(true);
package/src/theia-app.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // *****************************************************************************
2
- // Copyright (C) 2021 logi.cals GmbH, EclipseSource and others.
2
+ // Copyright (C) 2021-2023 logi.cals GmbH, EclipseSource and others.
3
3
  //
4
4
  // This program and the accompanying materials are made available under the
5
5
  // terms of the Eclipse Public License v. 2.0 which is available at
@@ -21,6 +21,7 @@ import { TheiaMenuBar } from './theia-main-menu';
21
21
  import { TheiaPreferenceScope, TheiaPreferenceView } from './theia-preference-view';
22
22
  import { TheiaQuickCommandPalette } from './theia-quick-command-palette';
23
23
  import { TheiaStatusBar } from './theia-status-bar';
24
+ import { TheiaTerminal } from './theia-terminal';
24
25
  import { TheiaView } from './theia-view';
25
26
  import { TheiaWorkspace } from './theia-workspace';
26
27
 
@@ -147,6 +148,41 @@ export class TheiaApp {
147
148
  return editor;
148
149
  }
149
150
 
151
+ async openTerminal<T extends TheiaTerminal>(terminalFactory: { new(id: string, app: TheiaApp): T }): Promise<T> {
152
+ const mainMenu = await this.menuBar.openMenu('Terminal');
153
+ const menuItem = await mainMenu.menuItemByName('New Terminal');
154
+ if (!menuItem) {
155
+ throw Error('Menu item \'New Terminal\' could not be found.');
156
+ }
157
+
158
+ const newTabIds = await this.runAndWaitForNewTabs(() => menuItem.click());
159
+ if (newTabIds.length > 1) {
160
+ console.warn('More than one new tab detected after opening the terminal');
161
+ }
162
+
163
+ return new terminalFactory(newTabIds[0], this);
164
+ }
165
+
166
+ protected async runAndWaitForNewTabs(command: () => Promise<void>): Promise<string[]> {
167
+ const tabIdsBefore = await this.visibleTabIds();
168
+ await command();
169
+ return (await this.waitForNewTabs(tabIdsBefore)).filter(item => !tabIdsBefore.includes(item));
170
+ }
171
+
172
+ protected async waitForNewTabs(tabIds: string[]): Promise<string[]> {
173
+ let tabIdsCurrent: string[];
174
+ while ((tabIdsCurrent = (await this.visibleTabIds())).length <= tabIds.length) {
175
+ console.debug('Awaiting a new tab to appear');
176
+ }
177
+ return tabIdsCurrent;
178
+ }
179
+
180
+ protected async visibleTabIds(): Promise<string[]> {
181
+ const tabs = await this.page.$$('.p-TabBar-tab');
182
+ const tabIds = (await Promise.all(tabs.map(tab => tab.getAttribute('id')))).filter(id => !!id);
183
+ return tabIds as string[];
184
+ }
185
+
150
186
  /** Specific Theia apps may add additional conditions to wait for. */
151
187
  async waitForInitialized(): Promise<void> {
152
188
  // empty by default
@@ -112,11 +112,11 @@ export class TheiaExplorerView extends TheiaView {
112
112
  return file;
113
113
  }
114
114
 
115
- async fileStatNode(filePath: string): Promise<TheiaExplorerFileStatNode | undefined> {
116
- return this.fileStatNodeBySegments(...filePath.split('/'));
115
+ async fileStatNode(filePath: string, compact = false): Promise<TheiaExplorerFileStatNode | undefined> {
116
+ return compact ? this.compactFileStatNode(filePath) : this.fileStatNodeBySegments(...filePath.split('/'));
117
117
  }
118
118
 
119
- async fileStatNodeBySegments(...pathFragments: string[]): Promise<TheiaExplorerFileStatNode | undefined> {
119
+ protected async fileStatNodeBySegments(...pathFragments: string[]): Promise<TheiaExplorerFileStatNode | undefined> {
120
120
  await super.activate();
121
121
  const viewElement = await this.viewElement();
122
122
 
@@ -141,6 +141,35 @@ export class TheiaExplorerView extends TheiaView {
141
141
  return currentTreeNode;
142
142
  }
143
143
 
144
+ protected async compactFileStatNode(path: string): Promise<TheiaExplorerFileStatNode | undefined> {
145
+ // default setting `explorer.compactFolders=true` renders folders in a compact form - single child folders will be compressed in a combined tree element
146
+ await super.activate();
147
+ const viewElement = await this.viewElement();
148
+
149
+ // check if first segment folder needs to be expanded first (if folder has never been expanded, it will not show the compact folder structure)
150
+ await this.waitForVisibleFileNodes();
151
+ const firstSegment = path.split('/')[0];
152
+ const selector = this.treeNodeSelector(firstSegment);
153
+ const folderElement = await viewElement?.$(selector);
154
+ if (folderElement && await folderElement.isVisible()) {
155
+ const folderNode = await viewElement?.waitForSelector(selector, { state: 'visible' });
156
+ if (!folderNode) {
157
+ throw new Error(`Tree node '${selector}' not found in explorer`);
158
+ }
159
+ const folderFileStatNode = new TheiaExplorerFileStatNode(folderNode, this);
160
+ if (await folderFileStatNode.isCollapsed()) {
161
+ await folderFileStatNode.expand();
162
+ }
163
+ }
164
+ // now get tree node via the full path
165
+ const fullPathSelector = this.treeNodeSelector(path);
166
+ const treeNode = await viewElement?.waitForSelector(fullPathSelector, { state: 'visible' });
167
+ if (!treeNode) {
168
+ throw new Error(`Tree node '${fullPathSelector}' not found in explorer`);
169
+ }
170
+ return new TheiaExplorerFileStatNode(treeNode, this);
171
+ }
172
+
144
173
  async selectTreeNode(filePath: string): Promise<void> {
145
174
  await this.activate();
146
175
  const treeNode = await this.page.waitForSelector(this.treeNodeSelector(filePath));
@@ -181,8 +210,8 @@ export class TheiaExplorerView extends TheiaView {
181
210
  await menuItem.click();
182
211
  }
183
212
 
184
- protected async existsNode(path: string, isDirectory: boolean): Promise<boolean> {
185
- const fileStatNode = await this.fileStatNode(path);
213
+ protected async existsNode(path: string, isDirectory: boolean, compact = false): Promise<boolean> {
214
+ const fileStatNode = await this.fileStatNode(path, compact);
186
215
  if (!fileStatNode) {
187
216
  return false;
188
217
  }
@@ -202,8 +231,14 @@ export class TheiaExplorerView extends TheiaView {
202
231
  return this.existsNode(path, false);
203
232
  }
204
233
 
205
- async existsDirectoryNode(path: string): Promise<boolean> {
206
- return this.existsNode(path, true);
234
+ async existsDirectoryNode(path: string, compact = false): Promise<boolean> {
235
+ return this.existsNode(path, true, compact);
236
+ }
237
+
238
+ async waitForTreeNodeVisible(path: string): Promise<void> {
239
+ // wait for tree node to be visible, e.g. after triggering create
240
+ const viewElement = await this.viewElement();
241
+ await viewElement?.waitForSelector(this.treeNodeSelector(path), { state: 'visible' });
207
242
  }
208
243
 
209
244
  async getNumberOfVisibleNodes(): Promise<number> {
@@ -0,0 +1,83 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 EclipseSource 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
+ import { ElementHandle } from '@playwright/test';
18
+ import { TheiaPageObject } from './theia-page-object';
19
+ import { TheiaApp } from './theia-app';
20
+
21
+ export class TheiaMonacoEditor extends TheiaPageObject {
22
+ constructor(protected readonly selector: string, app: TheiaApp) {
23
+ super(app);
24
+ }
25
+
26
+ async waitForVisible(): Promise<void> {
27
+ await this.page.waitForSelector(this.selector, { state: 'visible' });
28
+ }
29
+
30
+ protected viewElement(): Promise<ElementHandle<SVGElement | HTMLElement> | null> {
31
+ return this.page.$(this.selector);
32
+ }
33
+
34
+ async numberOfLines(): Promise<number | undefined> {
35
+ await this.waitForVisible();
36
+ const viewElement = await this.viewElement();
37
+ const lineElements = await viewElement?.$$('.view-lines .view-line');
38
+ return lineElements?.length;
39
+ }
40
+
41
+ async textContentOfLineByLineNumber(lineNumber: number): Promise<string | undefined> {
42
+ await this.waitForVisible();
43
+ const lineElement = await this.lineByLineNumber(lineNumber);
44
+ const content = await lineElement?.textContent();
45
+ return content ? this.replaceEditorSymbolsWithSpace(content) : undefined;
46
+ }
47
+
48
+ async lineByLineNumber(lineNumber: number): Promise<ElementHandle<SVGElement | HTMLElement> | undefined> {
49
+ await this.waitForVisible();
50
+ const viewElement = await this.viewElement();
51
+ const lines = await viewElement?.$$('.view-lines > .view-line');
52
+ if (!lines) {
53
+ throw new Error('Couldn\'t retrieve lines of monaco editor');
54
+ }
55
+
56
+ const linesWithXCoordinates = [];
57
+ for (const lineElement of lines) {
58
+ const box = await lineElement.boundingBox();
59
+ linesWithXCoordinates.push({ x: box ? box.x : Number.MAX_VALUE, lineElement });
60
+ }
61
+ linesWithXCoordinates.sort((a, b) => a.x.toString().localeCompare(b.x.toString()));
62
+ return linesWithXCoordinates[lineNumber - 1].lineElement;
63
+ }
64
+
65
+ async textContentOfLineContainingText(text: string): Promise<string | undefined> {
66
+ await this.waitForVisible();
67
+ const lineElement = await this.lineContainingText(text);
68
+ const content = await lineElement?.textContent();
69
+ return content ? this.replaceEditorSymbolsWithSpace(content) : undefined;
70
+ }
71
+
72
+ async lineContainingText(text: string): Promise<ElementHandle<SVGElement | HTMLElement> | undefined> {
73
+ const viewElement = await this.viewElement();
74
+ return viewElement?.waitForSelector(`.view-lines .view-line:has-text("${text}")`);
75
+ }
76
+
77
+ protected replaceEditorSymbolsWithSpace(content: string): string | Promise<string | undefined> {
78
+ // [ ] &nbsp; => \u00a0 -- NO-BREAK SPACE
79
+ // [·] &middot; => \u00b7 -- MIDDLE DOT
80
+ // [] &zwnj; => \u200c -- ZERO WIDTH NON-JOINER
81
+ return content.replace(/[\u00a0\u00b7]/g, ' ').replace(/[\u200c]/g, '');
82
+ }
83
+ }