Keyboard navigation smoke test (#18796)

This commit is contained in:
Barbara Valdez
2022-04-28 17:05:23 -07:00
committed by GitHub
parent 7ef0ef65f4
commit 5dd1cbeed8
4 changed files with 101 additions and 22 deletions

View File

@@ -0,0 +1,7 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export const ctrlOrCmd = process.platform === 'darwin' ? 'cmd' : 'ctrl';
export const winOrCtrl = process.platform === 'darwin' ? 'ctrl' : 'win';

View File

@@ -8,20 +8,22 @@ import { QuickAccess } from '../quickaccess';
import { QuickInput } from '../quickinput';
import { Editors } from '../editors';
import { IElement } from '..';
import * as constants from '../sql/constants';
const activeCellSelector = '.notebook-cell.active';
export class Notebook {
public readonly notebookToolbar: NotebookToolbar;
public readonly textCellToolbar: TextCellToolbar;
public readonly notebookFind: NotebookFind;
public readonly view: NotebookTreeView;
public readonly winOrCtrl = process.platform === 'darwin' ? 'ctrl' : 'win';
public readonly ctrlOrCmd = process.platform === 'darwin' ? 'cmd' : 'ctrl';
constructor(private code: Code, private quickAccess: QuickAccess, private quickInput: QuickInput, private editors: Editors) {
this.notebookToolbar = new NotebookToolbar(code);
this.textCellToolbar = new TextCellToolbar(code);
this.view = new NotebookTreeView(code, quickAccess);
this.notebookFind = new NotebookFind(code);
}
async openFile(fileName: string): Promise<void> {
@@ -33,7 +35,7 @@ export class Notebook {
}
async newUntitledNotebook(): Promise<void> {
await this.code.dispatchKeybinding(this.winOrCtrl + '+Alt+n');
await this.code.dispatchKeybinding(`${constants.winOrCtrl}+Alt+n`);
await this.editors.waitForActiveTab(`Notebook-0`);
await this.code.waitForElement('.notebookEditor');
}
@@ -47,21 +49,35 @@ export class Notebook {
await this.code.dispatchKeybinding('ctrl+shift+c');
}
await this.code.waitForElement('.notebook-cell.active');
await this.code.waitForElement(activeCellSelector);
}
async waitForActiveCellGone(): Promise<void> {
await this.code.waitForElementGone(activeCellSelector);
}
async runActiveCell(): Promise<void> {
await this.code.dispatchKeybinding('F5');
}
async exitActiveCell(): Promise<void> {
await this.code.dispatchKeybinding('escape'); // first escape to exit edit mode
await this.code.dispatchKeybinding('escape'); // second escape to deselect cell
}
async runAllCells(): Promise<void> {
await this.code.dispatchKeybinding('ctrl+shift+F5');
}
// Cell Actions
async waitForTypeInEditor(text: string) {
const editor = '.notebook-cell.active .monaco-editor';
async getActiveCell(id?: string): Promise<IElement> {
const activeCell = id ? `${activeCellSelector}[id="${id}"]` : activeCellSelector;
return this.code.waitForElement(activeCell);
}
async waitForTypeInEditor(text: string, cellId?: string) {
const editor = cellId ? `${activeCellSelector}[id="${cellId}"] .monaco-editor` : `${activeCellSelector} .monaco-editor`;
await this.code.waitAndClick(editor);
const textarea = `${editor} textarea`;
@@ -72,7 +88,7 @@ export class Notebook {
}
async waitForActiveCellEditorContents(accept: (contents: string) => boolean): Promise<any> {
const selector = '.notebook-cell.active .monaco-editor .view-lines';
const selector = `${activeCellSelector} .monaco-editor .view-lines`;
return this.code.waitForTextContent(selector, undefined, c => accept(c.replace(/\u00a0/g, ' ')));
}
@@ -82,24 +98,24 @@ export class Notebook {
}
public async selectAllTextInRichTextEditor(): Promise<void> {
const editor = '.notebook-cell.active .notebook-preview[contenteditable="true"]';
const editor = `${activeCellSelector} .notebook-preview[contenteditable="true"]`;
await this.selectAllText(editor);
}
public async selectAllTextInEditor(): Promise<void> {
const editor = '.notebook-cell.active .monaco-editor';
const editor = `${activeCellSelector} .monaco-editor`;
await this.selectAllText(editor);
}
private async selectAllText(selector: string): Promise<void> {
await this.code.waitAndClick(selector);
await this.code.dispatchKeybinding(this.ctrlOrCmd + '+a');
await this.code.dispatchKeybinding(`${constants.ctrlOrCmd}+a`);
}
private static readonly placeholderSelector = 'div.placeholder-cell-component';
async addCellFromPlaceholder(cellType: 'Markdown' | 'Code'): Promise<void> {
await this.code.waitAndClick(`${Notebook.placeholderSelector} p a[id="add${cellType}"]`);
await this.code.waitForElement('.notebook-cell.active');
await this.code.waitForElement(activeCellSelector);
}
async waitForPlaceholderGone(): Promise<void> {
@@ -172,12 +188,12 @@ export class Notebook {
// Cell Output Actions
async waitForJupyterErrorOutput(): Promise<void> {
const jupyterErrorOutput = `.notebook-cell.active .notebook-output mime-output[data-mime-type="application/vnd.jupyter.stderr"]`;
const jupyterErrorOutput = `${activeCellSelector} .notebook-output mime-output[data-mime-type="application/vnd.jupyter.stderr"]`;
await this.code.waitForElement(jupyterErrorOutput);
}
async waitForActiveCellResults(): Promise<void> {
const outputComponent = '.notebook-cell.active .notebook-output';
const outputComponent = `${activeCellSelector} .notebook-output`;
await this.code.waitForElement(outputComponent);
}
@@ -192,7 +208,7 @@ export class Notebook {
}
async waitForActiveCellResultsGone(): Promise<void> {
const outputComponent = '.notebook-cell.active .notebook-output';
const outputComponent = `${activeCellSelector} .notebook-output`;
await this.code.waitForElementGone(outputComponent);
}
@@ -438,3 +454,14 @@ export class NotebookTreeView {
await this.code.waitForElementGone(NotebookTreeView.pinnedNotebooksSelector);
}
}
export class NotebookFind {
constructor(private code: Code) { }
async openFindWidget(): Promise<void> {
const findWidgetCmd = `${constants.ctrlOrCmd}+f`;
await this.code.dispatchKeybinding(findWidgetCmd);
await this.code.waitForElement('.editor-widget.find-widget.visible');
}
}