@theia/playwright 1.54.0 → 1.55.0-next.25
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/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -1
- package/lib/tests/theia-explorer-view.test.js +3 -2
- package/lib/tests/theia-explorer-view.test.js.map +1 -1
- package/lib/tests/theia-notebook-editor.test.d.ts +2 -0
- package/lib/tests/theia-notebook-editor.test.d.ts.map +1 -0
- package/lib/tests/theia-notebook-editor.test.js +170 -0
- package/lib/tests/theia-notebook-editor.test.js.map +1 -0
- package/lib/tests/theia-quick-command.test.js +5 -0
- package/lib/tests/theia-quick-command.test.js.map +1 -1
- package/lib/theia-monaco-editor.d.ts +10 -0
- package/lib/theia-monaco-editor.d.ts.map +1 -1
- package/lib/theia-monaco-editor.js +29 -1
- package/lib/theia-monaco-editor.js.map +1 -1
- package/lib/theia-notebook-cell.d.ts +88 -0
- package/lib/theia-notebook-cell.d.ts.map +1 -0
- package/lib/theia-notebook-cell.js +195 -0
- package/lib/theia-notebook-cell.js.map +1 -0
- package/lib/theia-notebook-editor.d.ts +50 -0
- package/lib/theia-notebook-editor.d.ts.map +1 -0
- package/lib/theia-notebook-editor.js +153 -0
- package/lib/theia-notebook-editor.js.map +1 -0
- package/lib/theia-notebook-toolbar.d.ts +13 -0
- package/lib/theia-notebook-toolbar.d.ts.map +1 -0
- package/lib/theia-notebook-toolbar.js +47 -0
- package/lib/theia-notebook-toolbar.js.map +1 -0
- package/lib/theia-preference-view.d.ts +7 -1
- package/lib/theia-preference-view.d.ts.map +1 -1
- package/lib/theia-preference-view.js +16 -2
- package/lib/theia-preference-view.js.map +1 -1
- package/lib/theia-quick-command-palette.d.ts +1 -0
- package/lib/theia-quick-command-palette.d.ts.map +1 -1
- package/lib/theia-quick-command-palette.js +8 -0
- package/lib/theia-quick-command-palette.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +3 -0
- package/src/tests/resources/notebook-files/.theia/settings.json +3 -0
- package/src/tests/resources/notebook-files/sample.ipynb +18 -0
- package/src/tests/theia-explorer-view.test.ts +3 -2
- package/src/tests/theia-notebook-editor.test.ts +209 -0
- package/src/tests/theia-quick-command.test.ts +6 -0
- package/src/theia-monaco-editor.ts +31 -1
- package/src/theia-notebook-cell.ts +232 -0
- package/src/theia-notebook-editor.ts +171 -0
- package/src/theia-notebook-toolbar.ts +53 -0
- package/src/theia-preference-view.ts +14 -2
- package/src/theia-quick-command-palette.ts +10 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 TypeFox GmbH 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
|
+
import { Locator } from '@playwright/test';
|
|
18
|
+
import { join } from 'path';
|
|
19
|
+
import { TheiaApp } from './theia-app';
|
|
20
|
+
import { TheiaEditor } from './theia-editor';
|
|
21
|
+
import { TheiaNotebookCell } from './theia-notebook-cell';
|
|
22
|
+
import { TheiaNotebookToolbar } from './theia-notebook-toolbar';
|
|
23
|
+
import { TheiaQuickCommandPalette } from './theia-quick-command-palette';
|
|
24
|
+
import { TheiaToolbarItem } from './theia-toolbar-item';
|
|
25
|
+
import { OSUtil, normalizeId, urlEncodePath } from './util';
|
|
26
|
+
|
|
27
|
+
export namespace NotebookCommands {
|
|
28
|
+
export const SELECT_KERNEL_COMMAND = 'notebook.selectKernel';
|
|
29
|
+
export const ADD_NEW_CELL_COMMAND = 'notebook.add-new-code-cell';
|
|
30
|
+
export const ADD_NEW_MARKDOWN_CELL_COMMAND = 'notebook.add-new-markdown-cell';
|
|
31
|
+
export const EXECUTE_NOTEBOOK_COMMAND = 'notebook.execute';
|
|
32
|
+
export const CLEAR_ALL_OUTPUTS_COMMAND = 'notebook.clear-all-outputs';
|
|
33
|
+
export const EXPORT_COMMAND = 'jupyter.notebookeditor.export';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class TheiaNotebookEditor extends TheiaEditor {
|
|
37
|
+
|
|
38
|
+
constructor(filePath: string, app: TheiaApp) {
|
|
39
|
+
// shell-tab-notebook::file://<path>
|
|
40
|
+
// notebook:file://<path>
|
|
41
|
+
super({
|
|
42
|
+
tabSelector: normalizeId(`#shell-tab-notebook:file://${urlEncodePath(join(app.workspace.escapedPath, OSUtil.fileSeparator, filePath))}`),
|
|
43
|
+
viewSelector: normalizeId(`#notebook:file://${urlEncodePath(join(app.workspace.escapedPath, OSUtil.fileSeparator, filePath))}`)
|
|
44
|
+
}, app);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected viewLocator(): Locator {
|
|
48
|
+
return this.page.locator(this.data.viewSelector);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
tabLocator(): Locator {
|
|
52
|
+
return this.page.locator(this.data.viewSelector);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
override async waitForVisible(): Promise<void> {
|
|
56
|
+
await super.waitForVisible();
|
|
57
|
+
// wait for toolbar being rendered as it takes some time to load the kernel data.
|
|
58
|
+
await this.notebookToolbar().waitForVisible();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @returns The main toolbar of the notebook editor.
|
|
63
|
+
*/
|
|
64
|
+
notebookToolbar(): TheiaNotebookToolbar {
|
|
65
|
+
return new TheiaNotebookToolbar(this.viewLocator(), this.app);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @returns The name of the selected kernel.
|
|
70
|
+
*/
|
|
71
|
+
async selectedKernel(): Promise<string | undefined | null> {
|
|
72
|
+
const kernelItem = await this.toolbarItem(NotebookCommands.SELECT_KERNEL_COMMAND);
|
|
73
|
+
if (!kernelItem) {
|
|
74
|
+
throw new Error('Select kernel toolbar item not found.');
|
|
75
|
+
}
|
|
76
|
+
return this.notebookToolbar().locator.locator('#kernel-text').innerText();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Allows to select a kernel using toolbar item.
|
|
81
|
+
* @param kernelName The name of the kernel to select.
|
|
82
|
+
*/
|
|
83
|
+
async selectKernel(kernelName: string): Promise<void> {
|
|
84
|
+
await this.triggerToolbarItem(NotebookCommands.SELECT_KERNEL_COMMAND);
|
|
85
|
+
const qInput = new TheiaQuickCommandPalette(this.app);
|
|
86
|
+
const widget = await this.page.waitForSelector(qInput.selector, { timeout: 5000 });
|
|
87
|
+
if (widget && !await qInput.isOpen()) {
|
|
88
|
+
throw new Error('Failed to trigger kernel selection');
|
|
89
|
+
}
|
|
90
|
+
await qInput.type(kernelName, true);
|
|
91
|
+
await qInput.hide();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async availableKernels(): Promise<string[]> {
|
|
95
|
+
await this.triggerToolbarItem(NotebookCommands.SELECT_KERNEL_COMMAND);
|
|
96
|
+
const qInput = new TheiaQuickCommandPalette(this.app);
|
|
97
|
+
const widget = await this.page.waitForSelector(qInput.selector, { timeout: 5000 });
|
|
98
|
+
if (widget && !await qInput.isOpen()) {
|
|
99
|
+
throw new Error('Failed to trigger kernel selection');
|
|
100
|
+
}
|
|
101
|
+
await qInput.type('Python', false);
|
|
102
|
+
try {
|
|
103
|
+
const listItems = await Promise.all((await qInput.visibleItems()).map(async item => item.textContent()));
|
|
104
|
+
await this.page.keyboard.press('Enter');
|
|
105
|
+
await qInput.hide();
|
|
106
|
+
return listItems.filter(item => item !== null) as string[];
|
|
107
|
+
} finally {
|
|
108
|
+
await qInput.hide();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Adds a new code cell to the notebook.
|
|
114
|
+
*/
|
|
115
|
+
async addCodeCell(): Promise<void> {
|
|
116
|
+
const currentCellsCount = (await this.cells()).length;
|
|
117
|
+
await this.triggerToolbarItem(NotebookCommands.ADD_NEW_CELL_COMMAND);
|
|
118
|
+
await this.waitForCellCountChanged(currentCellsCount);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Adds a new markdown cell to the notebook.
|
|
123
|
+
*/
|
|
124
|
+
async addMarkdownCell(): Promise<void> {
|
|
125
|
+
const currentCellsCount = (await this.cells()).length;
|
|
126
|
+
await this.triggerToolbarItem(NotebookCommands.ADD_NEW_MARKDOWN_CELL_COMMAND);
|
|
127
|
+
await this.waitForCellCountChanged(currentCellsCount);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
protected async waitForCellCountChanged(prevCount: number): Promise<void> {
|
|
131
|
+
await this.viewLocator().locator('li.theia-notebook-cell').evaluateAll(
|
|
132
|
+
(elements, currentCount) => elements.length !== currentCount, prevCount
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async executeAllCells(): Promise<void> {
|
|
137
|
+
await this.triggerToolbarItem(NotebookCommands.EXECUTE_NOTEBOOK_COMMAND);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async clearAllOutputs(): Promise<void> {
|
|
141
|
+
await this.triggerToolbarItem(NotebookCommands.CLEAR_ALL_OUTPUTS_COMMAND);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async exportAs(): Promise<void> {
|
|
145
|
+
await this.triggerToolbarItem(NotebookCommands.EXPORT_COMMAND);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async cells(): Promise<TheiaNotebookCell[]> {
|
|
149
|
+
const cellsLocator = this.viewLocator().locator('li.theia-notebook-cell');
|
|
150
|
+
const cells: Array<TheiaNotebookCell> = [];
|
|
151
|
+
for (const cellLocator of await cellsLocator.all()) {
|
|
152
|
+
await cellLocator.waitFor({ state: 'visible' });
|
|
153
|
+
cells.push(new TheiaNotebookCell(cellLocator, this.viewLocator(), this.app));
|
|
154
|
+
}
|
|
155
|
+
return cells;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
protected async triggerToolbarItem(id: string): Promise<void> {
|
|
159
|
+
const item = await this.toolbarItem(id);
|
|
160
|
+
if (!item) {
|
|
161
|
+
throw new Error(`Toolbar item with id ${id} not found`);
|
|
162
|
+
}
|
|
163
|
+
await item.trigger();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
protected async toolbarItem(id: string): Promise<TheiaToolbarItem | undefined> {
|
|
167
|
+
const toolBar = this.notebookToolbar();
|
|
168
|
+
await toolBar.waitForVisible();
|
|
169
|
+
return toolBar.toolBarItem(id);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 TypeFox GmbH 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
|
+
import { ElementHandle, Locator } from '@playwright/test';
|
|
18
|
+
import { TheiaApp } from './theia-app';
|
|
19
|
+
import { TheiaToolbar } from './theia-toolbar';
|
|
20
|
+
|
|
21
|
+
export class TheiaNotebookToolbar extends TheiaToolbar {
|
|
22
|
+
public readonly locator: Locator;
|
|
23
|
+
|
|
24
|
+
constructor(parentLocator: Locator, app: TheiaApp) {
|
|
25
|
+
super(app);
|
|
26
|
+
this.selector = 'div#notebook-main-toolbar';
|
|
27
|
+
this.locator = parentLocator.locator(this.selector);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected override toolBarItemSelector(toolbarItemId = ''): string {
|
|
31
|
+
return `div.theia-notebook-main-toolbar-item${toolbarItemId ? `[id="${toolbarItemId}"]` : ''}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
protected override async toolbarElementHandle(): Promise<ElementHandle<SVGElement | HTMLElement> | null> {
|
|
35
|
+
// Use locator instead of page to find the toolbar element.
|
|
36
|
+
return this.locator.elementHandle();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
override async waitForVisible(): Promise<void> {
|
|
40
|
+
// Use locator instead of page to find the toolbar element.
|
|
41
|
+
await this.locator.waitFor({ state: 'visible' });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
override async waitUntilHidden(): Promise<void> {
|
|
45
|
+
// Use locator instead of page to find the toolbar element.
|
|
46
|
+
await this.locator.waitFor({ state: 'hidden' });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
override async waitUntilShown(): Promise<void> {
|
|
50
|
+
// Use locator instead of page to find the toolbar element.
|
|
51
|
+
await this.locator.waitFor({ state: 'visible' });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -86,8 +86,20 @@ export class TheiaPreferenceView extends TheiaView {
|
|
|
86
86
|
super(TheiaSettingsViewData, app);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
/**
|
|
90
|
+
* @param preferenceScope The preference scope (Workspace or User) to open the view for. Default is Workspace.
|
|
91
|
+
* @param useMenu If true, the view will be opened via the main menu. If false,
|
|
92
|
+
* the view will be opened via the quick command palette. Default is using the main menu.
|
|
93
|
+
* @returns The TheiaPreferenceView page object instance.
|
|
94
|
+
*/
|
|
95
|
+
override async open(preferenceScope = TheiaPreferenceScope.Workspace, useMenu: boolean = true): Promise<TheiaView> {
|
|
96
|
+
if (useMenu) {
|
|
97
|
+
const mainMenu = await this.app.menuBar.openMenu('File');
|
|
98
|
+
await (await mainMenu.menuItemByNamePath('Preferences', 'Settings'))?.click();
|
|
99
|
+
} else {
|
|
100
|
+
await this.app.quickCommandPalette.type('Preferences:');
|
|
101
|
+
await this.app.quickCommandPalette.trigger('Preferences: Open Settings (UI)');
|
|
102
|
+
}
|
|
91
103
|
await this.waitForVisible();
|
|
92
104
|
await this.openPreferenceScope(preferenceScope);
|
|
93
105
|
return this;
|
|
@@ -78,4 +78,14 @@ export class TheiaQuickCommandPalette extends TheiaPageObject {
|
|
|
78
78
|
}
|
|
79
79
|
return command.$('.monaco-list-row.focused .monaco-highlighted-label');
|
|
80
80
|
}
|
|
81
|
+
|
|
82
|
+
async visibleItems(): Promise<ElementHandle<SVGElement | HTMLElement>[]> {
|
|
83
|
+
// FIXME rewrite with locators
|
|
84
|
+
const command = await this.page.waitForSelector(this.selector);
|
|
85
|
+
if (!command) {
|
|
86
|
+
throw new Error('No selected command found!');
|
|
87
|
+
}
|
|
88
|
+
return command.$$('.monaco-highlighted-label');
|
|
89
|
+
}
|
|
90
|
+
|
|
81
91
|
}
|