Add Markdown Toolbar functionality to notebook smoke tests. (#15868)

This commit is contained in:
Cory Rivera
2021-06-22 16:38:04 -07:00
committed by GitHub
parent 00361e52a2
commit 6c6a0506b2
2 changed files with 75 additions and 17 deletions

View File

@@ -13,11 +13,13 @@ const winOrCtrl = process.platform === 'darwin' ? 'ctrl' : 'win';
export class Notebook { export class Notebook {
public readonly toolbar: NotebookToolbar; public readonly notebookToolbar: NotebookToolbar;
public readonly textCellToolbar: TextCellToolbar;
public readonly view: NotebookView; public readonly view: NotebookView;
constructor(private code: Code, private quickAccess: QuickAccess, private quickInput: QuickInput, private editors: Editors) { constructor(private code: Code, private quickAccess: QuickAccess, private quickInput: QuickInput, private editors: Editors) {
this.toolbar = new NotebookToolbar(code); this.notebookToolbar = new NotebookToolbar(code);
this.textCellToolbar = new TextCellToolbar(code);
this.view = new NotebookView(code, quickAccess); this.view = new NotebookView(code, quickAccess);
} }
@@ -48,11 +50,11 @@ export class Notebook {
} }
async changeKernel(kernel: string): Promise<void> { async changeKernel(kernel: string): Promise<void> {
await this.toolbar.changeKernel(kernel); await this.notebookToolbar.changeKernel(kernel);
} }
async waitForKernel(kernel: string): Promise<void> { async waitForKernel(kernel: string): Promise<void> {
await this.toolbar.waitForKernel(kernel); await this.notebookToolbar.waitForKernel(kernel);
} }
async runActiveCell(): Promise<void> { async runActiveCell(): Promise<void> {
@@ -70,15 +72,15 @@ export class Notebook {
} }
async trustNotebook(): Promise<void> { async trustNotebook(): Promise<void> {
await this.toolbar.trustNotebook(); await this.notebookToolbar.trustNotebook();
} }
async waitForTrustedIcon(): Promise<void> { async waitForTrustedIcon(): Promise<void> {
await this.toolbar.waitForTrustedIcon(); await this.notebookToolbar.waitForTrustedIcon();
} }
async waitForNotTrustedIcon(): Promise<void> { async waitForNotTrustedIcon(): Promise<void> {
await this.toolbar.waitForNotTrustedIcon(); await this.notebookToolbar.waitForNotTrustedIcon();
} }
// Cell Actions // Cell Actions
@@ -99,6 +101,12 @@ export class Notebook {
return this.code.waitForTextContent(selector, undefined, c => accept(c.replace(/\u00a0/g, ' '))); return this.code.waitForTextContent(selector, undefined, c => accept(c.replace(/\u00a0/g, ' ')));
} }
public async selectAllTextInEditor(): Promise<void> {
const editor = '.notebook-cell.active .monaco-editor';
await this.code.waitAndClick(editor);
await this.code.dispatchKeybinding('ctrl+a');
}
private static readonly placeholderSelector = 'div.placeholder-cell-component'; private static readonly placeholderSelector = 'div.placeholder-cell-component';
async addCellFromPlaceholder(cellType: 'Markdown' | 'Code'): Promise<void> { async addCellFromPlaceholder(cellType: 'Markdown' | 'Code'): Promise<void> {
await this.code.waitAndClick(`${Notebook.placeholderSelector} p a[id="add${cellType}"]`); await this.code.waitAndClick(`${Notebook.placeholderSelector} p a[id="add${cellType}"]`);
@@ -126,14 +134,11 @@ export class Notebook {
await this.code.waitForElementGone(Notebook.doubleClickToEditSelector); await this.code.waitForElementGone(Notebook.doubleClickToEditSelector);
} }
private static readonly textCellToolbar = 'text-cell-component markdown-toolbar-component ul.actions-container'; async waitForTextCellPreviewContent(text: string, fontType: 'p' | 'h1' | 'h2' | 'h3', textStyle?: 'strong' | 'i' | 'u' | 'mark'): Promise<void> {
async changeTextCellView(view: 'Rich Text View' | 'Split View' | 'Markdown View'): Promise<void> { let textSelector = `${Notebook.textCellPreviewSelector} ${fontType}`;
const actionSelector = `${Notebook.textCellToolbar} a[title="${view}"]`; if (textStyle) {
await this.code.waitAndClick(actionSelector); textSelector = `${textSelector} ${textStyle}`;
} }
async waitForTextCellPreviewContent(text: string, fontType: 'p' | 'h1' | 'h2' | 'h3'): Promise<void> {
const textSelector = `${Notebook.textCellPreviewSelector} ${fontType}`;
await this.code.waitForElement(textSelector, result => result?.textContent === text); await this.code.waitForElement(textSelector, result => result?.textContent === text);
} }
@@ -196,6 +201,57 @@ export class Notebook {
} }
} }
export class TextCellToolbar {
private static readonly textCellToolbar = 'text-cell-component markdown-toolbar-component ul.actions-container';
constructor(private code: Code) { }
public async changeTextCellView(view: 'Rich Text View' | 'Split View' | 'Markdown View'): Promise<void> {
await this.clickToolbarButton(view);
}
public async boldSelectedText(): Promise<void> {
await this.clickToolbarButton('Bold');
}
public async italicizeSelectedText(): Promise<void> {
await this.clickToolbarButton('Italics');
}
public async underlineSelectedText(): Promise<void> {
await this.clickToolbarButton('Underline');
}
public async highlightSelectedText(): Promise<void> {
await this.clickToolbarButton('Highlight');
}
public async codifySelectedText(): Promise<void> {
await this.clickToolbarButton('Code');
}
public async insertLink(): Promise<void> {
throw new Error('Method not implemented.');
}
public async insertList(): Promise<void> {
await this.clickToolbarButton('List');
}
public async insertOrderedList(): Promise<void> {
await this.clickToolbarButton('Ordered list');
}
public async changeSelectedTextSize(): Promise<void> {
throw new Error('Method not implemented.');
}
private async clickToolbarButton(buttonTitle: string) {
const actionSelector = `${TextCellToolbar.textCellToolbar} a[title="${buttonTitle}"]`;
await this.code.waitAndClick(actionSelector);
}
}
export class NotebookToolbar { export class NotebookToolbar {
private static readonly toolbarSelector = '.notebookEditor .editor-toolbar .actions-container'; private static readonly toolbarSelector = '.notebookEditor .editor-toolbar .actions-container';

View File

@@ -73,11 +73,13 @@ export function setup() {
await app.workbench.sqlNotebook.doubleClickTextCell(); await app.workbench.sqlNotebook.doubleClickTextCell();
await app.workbench.sqlNotebook.waitForDoubleClickToEditGone(); await app.workbench.sqlNotebook.waitForDoubleClickToEditGone();
await app.workbench.sqlNotebook.changeTextCellView('Split View'); await app.workbench.sqlNotebook.textCellToolbar.changeTextCellView('Split View');
const sampleText: string = 'Test text cells'; const sampleText: string = 'Test text cells';
await app.workbench.sqlNotebook.waitForTypeInEditor(sampleText); await app.workbench.sqlNotebook.waitForTypeInEditor(sampleText);
await app.workbench.sqlNotebook.selectAllTextInEditor();
await app.workbench.sqlNotebook.textCellToolbar.boldSelectedText();
await app.code.dispatchKeybinding('escape'); await app.code.dispatchKeybinding('escape');
await app.workbench.sqlNotebook.waitForTextCellPreviewContent(sampleText, 'p'); await app.workbench.sqlNotebook.waitForTextCellPreviewContent(sampleText, 'p', 'strong');
await app.workbench.quickaccess.runCommand('workbench.action.revertAndCloseActiveEditor'); await app.workbench.quickaccess.runCommand('workbench.action.revertAndCloseActiveEditor');
}); });