From 316798a9b5ef568fdfe6a9fa798126a70a667390 Mon Sep 17 00:00:00 2001 From: Cory Rivera Date: Wed, 6 Apr 2022 10:02:51 -0700 Subject: [PATCH] Add cell toolbar tests for undoing text styling by clicking button twice. (#18807) --- test/automation/src/sql/notebook.ts | 5 + .../src/sql/areas/notebook/notebook.test.ts | 96 +++++++++++++------ 2 files changed, 71 insertions(+), 30 deletions(-) diff --git a/test/automation/src/sql/notebook.ts b/test/automation/src/sql/notebook.ts index 534a7b3bcb..da4ff07b59 100644 --- a/test/automation/src/sql/notebook.ts +++ b/test/automation/src/sql/notebook.ts @@ -155,6 +155,11 @@ export class Notebook { await this.code.waitForElement(textSelector, result => !!result?.textContent?.includes(text)); // Use includes to handle whitespace/quote edge cases } + async waitForTextCellPreviewContentGone(selector: string): Promise { + let textSelector = `${Notebook.textCellPreviewSelector} ${selector}`; + await this.code.waitForElementGone(textSelector); + } + // Cell Output Actions async waitForActiveCellResults(): Promise { diff --git a/test/smoke/src/sql/areas/notebook/notebook.test.ts b/test/smoke/src/sql/areas/notebook/notebook.test.ts index a045ba051c..b5e5fd66e0 100644 --- a/test/smoke/src/sql/areas/notebook/notebook.test.ts +++ b/test/smoke/src/sql/areas/notebook/notebook.test.ts @@ -146,70 +146,106 @@ export function setup(opts: minimist.ParsedArgs) { }); describe('Cell Toolbar Actions', function () { - const sampleText: string = 'Test Text'; - async function createCellAndSelectAllText(app: Application): Promise { + async function verifyCellToolbarBehavior(app: Application, toolbarAction: () => Promise, selector: string, checkIfGone: boolean = false): Promise { + const sampleText: string = 'Test Text'; + await app.workbench.sqlNotebook.newUntitledNotebook(); await app.workbench.sqlNotebook.addCellFromPlaceholder('Markdown'); await app.workbench.sqlNotebook.waitForPlaceholderGone(); await app.workbench.sqlNotebook.textCellToolbar.changeTextCellView('Split View'); await app.workbench.sqlNotebook.waitForTypeInEditor(sampleText); await app.workbench.sqlNotebook.selectAllTextInEditor(); + + await toolbarAction(); + await app.code.dispatchKeybinding('escape'); + if (checkIfGone) { + await app.workbench.sqlNotebook.waitForTextCellPreviewContentGone(selector); + } else { + await app.workbench.sqlNotebook.waitForTextCellPreviewContent(sampleText, selector); + } } it('can bold selected text', async function () { const app = this.app as Application; - await createCellAndSelectAllText(app); - await app.workbench.sqlNotebook.textCellToolbar.boldSelectedText(); - await app.code.dispatchKeybinding('escape'); - await app.workbench.sqlNotebook.waitForTextCellPreviewContent(sampleText, 'p strong'); + await verifyCellToolbarBehavior(app, () => app.workbench.sqlNotebook.textCellToolbar.boldSelectedText(), 'p strong'); + }); + + it('can undo bold text', async function () { + const app = this.app as Application; + await verifyCellToolbarBehavior(app, async () => { + await app.workbench.sqlNotebook.textCellToolbar.boldSelectedText(); + await app.workbench.sqlNotebook.textCellToolbar.boldSelectedText(); + }, 'p strong', true); }); it('can italicize selected text', async function () { const app = this.app as Application; - await createCellAndSelectAllText(app); - await app.workbench.sqlNotebook.textCellToolbar.italicizeSelectedText(); - await app.code.dispatchKeybinding('escape'); - await app.workbench.sqlNotebook.waitForTextCellPreviewContent(sampleText, 'p em'); + await verifyCellToolbarBehavior(app, () => app.workbench.sqlNotebook.textCellToolbar.italicizeSelectedText(), 'p em'); + }); + + it('can undo italic text', async function () { + const app = this.app as Application; + await verifyCellToolbarBehavior(app, async () => { + await app.workbench.sqlNotebook.textCellToolbar.italicizeSelectedText(); + await app.workbench.sqlNotebook.textCellToolbar.italicizeSelectedText(); + }, 'p em', true); }); it('can underline selected text', async function () { const app = this.app as Application; - await createCellAndSelectAllText(app); - await app.workbench.sqlNotebook.textCellToolbar.underlineSelectedText(); - await app.code.dispatchKeybinding('escape'); - await app.workbench.sqlNotebook.waitForTextCellPreviewContent(sampleText, 'p u'); + await verifyCellToolbarBehavior(app, () => app.workbench.sqlNotebook.textCellToolbar.underlineSelectedText(), 'p u'); + }); + + it('can undo underlined text', async function () { + const app = this.app as Application; + await verifyCellToolbarBehavior(app, async () => { + await app.workbench.sqlNotebook.textCellToolbar.underlineSelectedText(); + await app.workbench.sqlNotebook.textCellToolbar.underlineSelectedText(); + }, 'p u', true); }); it('can highlight selected text', async function () { const app = this.app as Application; - await createCellAndSelectAllText(app); - await app.workbench.sqlNotebook.textCellToolbar.highlightSelectedText(); - await app.code.dispatchKeybinding('escape'); - await app.workbench.sqlNotebook.waitForTextCellPreviewContent(sampleText, 'p mark'); + await verifyCellToolbarBehavior(app, () => app.workbench.sqlNotebook.textCellToolbar.highlightSelectedText(), 'p mark'); + }); + + it('can undo highlighted text', async function () { + const app = this.app as Application; + await verifyCellToolbarBehavior(app, async () => { + await app.workbench.sqlNotebook.textCellToolbar.highlightSelectedText(); + await app.workbench.sqlNotebook.textCellToolbar.highlightSelectedText(); + }, 'p mark', true); }); it('can codify selected text', async function () { const app = this.app as Application; - await createCellAndSelectAllText(app); - await app.workbench.sqlNotebook.textCellToolbar.codifySelectedText(); - await app.code.dispatchKeybinding('escape'); - await app.workbench.sqlNotebook.waitForTextCellPreviewContent(sampleText, 'pre code'); + await verifyCellToolbarBehavior(app, () => app.workbench.sqlNotebook.textCellToolbar.codifySelectedText(), 'pre code'); }); it('can bullet selected text', async function () { const app = this.app as Application; - await createCellAndSelectAllText(app); - await app.workbench.sqlNotebook.textCellToolbar.insertList(); - await app.code.dispatchKeybinding('escape'); - await app.workbench.sqlNotebook.waitForTextCellPreviewContent(sampleText, 'ul li'); + await verifyCellToolbarBehavior(app, () => app.workbench.sqlNotebook.textCellToolbar.insertList(), 'ul li'); + }); + + it('can undo bulleted text', async function () { + const app = this.app as Application; + await verifyCellToolbarBehavior(app, async () => { + await app.workbench.sqlNotebook.textCellToolbar.insertList(); + await app.workbench.sqlNotebook.textCellToolbar.insertList(); + }, 'ul li', true); }); it('can number selected text', async function () { const app = this.app as Application; - await createCellAndSelectAllText(app); - await app.workbench.sqlNotebook.textCellToolbar.insertOrderedList(); - await app.code.dispatchKeybinding('escape'); - await app.workbench.sqlNotebook.waitForTextCellPreviewContent(sampleText, 'ol li'); + await verifyCellToolbarBehavior(app, () => app.workbench.sqlNotebook.textCellToolbar.insertOrderedList(), 'ol li'); + }); + + it('can undo numbered text', async function () { + const app = this.app as Application; + await verifyCellToolbarBehavior(app, async () => { + await app.workbench.sqlNotebook.textCellToolbar.insertOrderedList(); + await app.workbench.sqlNotebook.textCellToolbar.insertOrderedList(); + }, 'ol li', true); }); // Text size tests are disabled because the text size dropdown