Skip to content

Commit

Permalink
Apply re-view suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuebner committed Sep 19, 2024
1 parent 9ed18da commit 82100a5
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
run: yarn --cwd examples/playwright ui-tests-ci

- name: Archive test results
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 #v4
if: ${{ failure() }}
with:
name: playwright-test-results
Expand Down
1 change: 0 additions & 1 deletion examples/playwright/configs/playwright.ci.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const ciConfig: PlaywrightTestConfig = {
...baseConfig,
workers: 1,
retries: 2,
timeout: 30 * 1000,
reporter: [['list'], ['allure-playwright'], ['github']]
};

Expand Down
2 changes: 0 additions & 2 deletions examples/playwright/src/tests/theia-notebook-editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ test.describe('Theia Notebook Editor interaction', () => {

test('kernels are installed', async () => {
editor = await app.openEditor('sample.ipynb', TheiaNotebookEditor);
await editor.tabLocator().click(); // force activate

const kernels = await editor.availableKernels();
const msg = `Available kernels:\n ${kernels.join('\n')}`;
Expand Down Expand Up @@ -97,7 +96,6 @@ test.describe('Theia Notebook Cell interaction', () => {

test.beforeEach(async () => {
editor = await app.openEditor('sample.ipynb', TheiaNotebookEditor);
await editor.tabLocator().click(); // force activate
const selectedKernel = await editor.selectedKernel();
if (selectedKernel?.match(/^Python 3/) === null) {
await editor.selectKernel('Python 3');
Expand Down
6 changes: 6 additions & 0 deletions examples/playwright/src/tests/theia-quick-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,10 @@ test.describe('Theia Quick Command', () => {
expect(await notification.isEntryVisible('Positive Integer: 6')).toBe(true);
});

test('retrieve and check visible items', async () => {
await quickCommand.type('close all tabs', false);
const listItems = await Promise.all((await quickCommand.visibleItems()).map(async item => item.textContent()));
expect(listItems).toContain('View: Close All Tabs in Main Area');
});

});
30 changes: 30 additions & 0 deletions examples/playwright/src/theia-monaco-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,36 @@ export class TheiaMonacoEditor extends TheiaPageObject {
return viewElement?.waitForSelector(`.view-lines .view-line:has-text("${text}")`);
}

/**
* @returns The text content of the editor.
*/
async editorText(): Promise<string | undefined> {
const lines: string[] = [];
const linesCount = await this.numberOfLines();
if (linesCount === undefined) {
return undefined;
}
for (let line = 1; line <= linesCount; line++) {
const lineText = await this.textContentOfLineByLineNumber(line);
if (lineText === undefined) {
break;
}
lines.push(lineText);
}
return lines.join('\n');
}

/**
* Adds text to the editor.
* @param text The text to add to the editor.
* @param lineNumber The line number where to add the text. Default is 1.
*/
async addEditorText(text: string, lineNumber: number = 1): Promise<void> {
const line = await this.lineByLineNumber(lineNumber);
await line?.click();
await this.page.keyboard.type(text);
}

protected replaceEditorSymbolsWithSpace(content: string): string | Promise<string | undefined> {
// [ ] &nbsp; => \u00a0 -- NO-BREAK SPACE
// [·] &middot; => \u00b7 -- MIDDLE DOT
Expand Down
18 changes: 2 additions & 16 deletions examples/playwright/src/theia-notebook-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,7 @@ export class TheiaNotebookCell extends TheiaPageObject {
* @returns The text content of the cell editor.
*/
async editorText(): Promise<string | undefined> {
const lines: string[] = [];
const linesCount = await this.monacoEditor.numberOfLines();
if (linesCount === undefined) {
return undefined;
}
for (let line = 1; line <= linesCount; line++) {
const lineText = await this.monacoEditor.textContentOfLineByLineNumber(line);
if (lineText === undefined) {
break;
}
lines.push(lineText);
}
return lines.join('\n');
return this.editor.editorText();
}

/**
Expand All @@ -89,9 +77,7 @@ export class TheiaNotebookCell extends TheiaPageObject {
* @param lineNumber The line number where to add the text. Default is 1.
*/
async addEditorText(text: string, lineNumber: number = 1): Promise<void> {
const line = await this.editor.lineByLineNumber(lineNumber);
await line?.click();
await this.page.keyboard.type(text);
await this.editor.addEditorText(text, lineNumber);
}

/**
Expand Down
27 changes: 17 additions & 10 deletions examples/playwright/src/theia-notebook-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ import { TheiaQuickCommandPalette } from './theia-quick-command-palette';
import { TheiaToolbarItem } from './theia-toolbar-item';
import { OSUtil, normalizeId, urlEncodePath } from './util';

export namespace NotebookCommands {
export const SELECT_KERNEL_COMMAND = 'notebook.selectKernel';
export const ADD_NEW_CELL_COMMAND = 'notebook.add-new-code-cell';
export const ADD_NEW_MARKDOWN_CELL_COMMAND = 'notebook.add-new-markdown-cell';
export const EXECUTE_NOTEBOOK_COMMAND = 'notebook.execute';
export const CLEAR_ALL_OUTPUTS_COMMAND = 'notebook.clear-all-outputs';
export const EXPORT_COMMAND = 'jupyter.notebookeditor.export';
}

export class TheiaNotebookEditor extends TheiaEditor {

constructor(filePath: string, app: TheiaApp) {
Expand Down Expand Up @@ -60,7 +69,7 @@ export class TheiaNotebookEditor extends TheiaEditor {
* @returns The name of the selected kernel.
*/
async selectedKernel(): Promise<string | undefined | null> {
const kernelItem = await this.toolbarItem('notebook.selectKernel');
const kernelItem = await this.toolbarItem(NotebookCommands.SELECT_KERNEL_COMMAND);
if (!kernelItem) {
throw new Error('Select kernel toolbar item not found.');
}
Expand All @@ -72,8 +81,7 @@ export class TheiaNotebookEditor extends TheiaEditor {
* @param kernelName The name of the kernel to select.
*/
async selectKernel(kernelName: string): Promise<void> {
// TODO should we use NotebookCommands.SELECT_KERNEL_COMMAND.id? Need a dependency...
await this.triggerToolbarItem('notebook.selectKernel');
await this.triggerToolbarItem(NotebookCommands.SELECT_KERNEL_COMMAND);
const qInput = new TheiaQuickCommandPalette(this.app);
const widget = await this.page.waitForSelector(qInput.selector, { timeout: 5000 });
if (widget && !await qInput.isOpen()) {
Expand All @@ -84,8 +92,7 @@ export class TheiaNotebookEditor extends TheiaEditor {
}

async availableKernels(): Promise<string[]> {
// TODO should we use NotebookCommands.SELECT_KERNEL_COMMAND.id? Need a dependency...
await this.triggerToolbarItem('notebook.selectKernel');
await this.triggerToolbarItem(NotebookCommands.SELECT_KERNEL_COMMAND);
const qInput = new TheiaQuickCommandPalette(this.app);
const widget = await this.page.waitForSelector(qInput.selector, { timeout: 5000 });
if (widget && !await qInput.isOpen()) {
Expand All @@ -107,7 +114,7 @@ export class TheiaNotebookEditor extends TheiaEditor {
*/
async addCodeCell(): Promise<void> {
const currentCellsCount = (await this.cells()).length;
await this.triggerToolbarItem('notebook.add-new-code-cell');
await this.triggerToolbarItem(NotebookCommands.ADD_NEW_CELL_COMMAND);
await this.waitForCellCountChanged(currentCellsCount);
}

Expand All @@ -116,7 +123,7 @@ export class TheiaNotebookEditor extends TheiaEditor {
*/
async addMarkdownCell(): Promise<void> {
const currentCellsCount = (await this.cells()).length;
await this.triggerToolbarItem('notebook.add-new-markdown-cell');
await this.triggerToolbarItem(NotebookCommands.ADD_NEW_MARKDOWN_CELL_COMMAND);
await this.waitForCellCountChanged(currentCellsCount);
}

Expand All @@ -127,15 +134,15 @@ export class TheiaNotebookEditor extends TheiaEditor {
}

async executeAllCells(): Promise<void> {
this.triggerToolbarItem('notebook.execute');
await this.triggerToolbarItem(NotebookCommands.EXECUTE_NOTEBOOK_COMMAND);
}

async clearAllOutputs(): Promise<void> {
this.triggerToolbarItem('notebook.clear-all-outputs');
await this.triggerToolbarItem(NotebookCommands.CLEAR_ALL_OUTPUTS_COMMAND);
}

async exportAs(): Promise<void> {
this.triggerToolbarItem('jupyter.notebookeditor.export');
await this.triggerToolbarItem(NotebookCommands.EXPORT_COMMAND);
}

async cells(): Promise<TheiaNotebookCell[]> {
Expand Down

0 comments on commit 82100a5

Please sign in to comment.