diff --git a/test/automation/src/sql/notebook.ts b/test/automation/src/sql/notebook.ts index a202bc4cf6..9e6d59fded 100644 --- a/test/automation/src/sql/notebook.ts +++ b/test/automation/src/sql/notebook.ts @@ -117,6 +117,30 @@ export class Notebook { await this.code.waitForElementGone(Notebook.placeholderSelector); } + async waitForCollapseIconInCells(): Promise { + let cellIds = await this.getCellIds(); + for (let i of cellIds) { + const editor = `.notebook-cell[id="${i}"] code-cell-component code-component collapse-component`; + await this.code.waitForElement(`${editor} [title="Collapse code cell contents"]`); + } + } + + async waitForExpandIconInCells(): Promise { + let cellIds = await this.getCellIds(); + for (let i of cellIds) { + const editor = `.notebook-cell[id="${i}"] code-cell-component code-component collapse-component`; + await this.code.waitForElement(`${editor} [title="Expand code cell contents"]`); + } + } + + /** + * Helper function + * @returns cell ids for the notebook + */ + async getCellIds(): Promise { + return (await this.code.waitForElements('div.notebook-cell', false)).map(cell => cell.attributes['id']); + } + // Text Cell Actions private static readonly textCellPreviewSelector = 'div.notebook-preview'; @@ -260,6 +284,10 @@ export class NotebookToolbar { private static readonly trustedButtonSelector = `${NotebookToolbar.toolbarSelector} a[class="${NotebookToolbar.trustedButtonClass}"]`; private static readonly notTrustedButtonClass = 'action-label codicon masked-icon icon-shield-x'; private static readonly notTrustedButtonSelector = `${NotebookToolbar.toolbarSelector} a[class="${NotebookToolbar.notTrustedButtonClass}"]`; + private static readonly collapseCellsClass = 'action-label codicon masked-icon icon-collapse-cells'; + private static readonly collapseCellsButtonSelector = `${NotebookToolbar.toolbarSelector} a[class="${NotebookToolbar.collapseCellsClass}"]`; + private static readonly expandCellsClass = 'action-label codicon masked-icon icon-expand-cells'; + private static readonly expandCellsButtonSelector = `${NotebookToolbar.toolbarSelector} a[class="${NotebookToolbar.expandCellsClass}"]`; constructor(private code: Code) { } @@ -295,6 +323,30 @@ export class NotebookToolbar { async waitForNotTrustedIcon(): Promise { await this.code.waitForElement(NotebookToolbar.notTrustedButtonSelector); } + + async collapseCells(): Promise { + let buttons: IElement[] = await this.code.waitForElements(NotebookToolbar.toolbarButtonSelector, false); + let collapseButton = buttons.find(button => button.className.includes('icon-collapse-cells')); + if (collapseButton) { + await this.code.waitAndClick(NotebookToolbar.collapseCellsButtonSelector); + } + } + + async expandCells(): Promise { + let buttons: IElement[] = await this.code.waitForElements(NotebookToolbar.toolbarButtonSelector, false); + let expandButton = buttons.find(button => button.className.includes('icon-expand-cells')); + if (expandButton) { + await this.code.waitAndClick(NotebookToolbar.expandCellsButtonSelector); + } + } + + async waitForCollapseCellsNotebookIcon(): Promise { + await this.code.waitForElement(NotebookToolbar.collapseCellsButtonSelector); + } + + async waitForExpandCellsNotebookIcon(): Promise { + await this.code.waitForElement(NotebookToolbar.expandCellsButtonSelector); + } } export class NotebookView { diff --git a/test/smoke/src/sql/areas/notebook/notebook.test.ts b/test/smoke/src/sql/areas/notebook/notebook.test.ts index 90a6192e9f..54daf70fb2 100644 --- a/test/smoke/src/sql/areas/notebook/notebook.test.ts +++ b/test/smoke/src/sql/areas/notebook/notebook.test.ts @@ -94,6 +94,22 @@ export function setup() { const app = this.app as Application; await app.workbench.quickaccess.runCommand('workbench.action.revertAndCloseActiveEditor'); }); + + describe('Notebook Toolbar Actions', async () => { + + it('Collapse and Expand Cell', async function () { + const app = this.app as Application; + await app.workbench.sqlNotebook.openFile('collapsed.ipynb'); + await app.workbench.sqlNotebook.waitForCollapseIconInCells(); + await app.workbench.sqlNotebook.notebookToolbar.waitForCollapseCellsNotebookIcon(); + await app.workbench.sqlNotebook.notebookToolbar.collapseCells(); + await app.workbench.sqlNotebook.waitForExpandIconInCells(); + await app.workbench.sqlNotebook.notebookToolbar.waitForExpandCellsNotebookIcon(); + await app.workbench.sqlNotebook.notebookToolbar.expandCells(); + await app.workbench.sqlNotebook.waitForCollapseIconInCells(); + await app.workbench.sqlNotebook.notebookToolbar.waitForCollapseCellsNotebookIcon(); + }); + }); }); }