import { Code } from './code' ; import { QuickAccess } from './quickaccess' ; const activeRowSelector = `.notebook-editor .monaco-list-row.focused` ; export class Notebook { constructor ( private readonly quickAccess , private readonly code ) { } async openNotebook ( ) { await this . quickAccess . runCommand ( 'vscode-notebook-tests.createNewNotebook' ) ; await this . code . waitForElement ( activeRowSelector ) ; await this . focusFirstCell ( ) ; await this . waitForActiveCellEditorContents ( 'code()' ) ; } async focusNextCell ( ) { await this . code . dispatchKeybinding ( 'down' ) ; } async focusFirstCell ( ) { await this . quickAccess . runCommand ( 'notebook.focusTop' ) ; } async editCell ( ) { await this . code . dispatchKeybinding ( 'enter' ) ; } async stopEditingCell ( ) { await this . quickAccess . runCommand ( 'notebook.cell.quitEdit' ) ; } async waitForTypeInEditor ( text ) { const editor = `${ activeRowSelector } .monaco-editor` ; await this . code . waitForElement ( editor ) ; const textarea = `${ editor } textarea` ; await this . code . waitForActiveElement ( textarea ) ; await this . code . waitForTypeInEditor ( textarea , text ) ; await this . _waitForActiveCellEditorContents ( c => c . indexOf ( text ) > - 1 ) ; } async waitForActiveCellEditorContents ( contents ) { return this . _waitForActiveCellEditorContents ( str => str === contents ) ; } private async _waitForActiveCellEditorContents ( accept ) { const selector = `${ activeRowSelector } .monaco-editor .view-lines` ; return this . code . waitForTextContent ( selector , undefined , c => accept ( c . replace ( /\u00a0/g , ' ' ) ) ) ; } async waitForMarkdownContents ( markdownSelector , text ) { const selector = `${ activeRowSelector } .markdown ${ markdownSelector }` ; await this . code . waitForTextContent ( selector , text ) ; } async insertNotebookCell ( kind ) { if ( kind === 'markdown' ) { await this . quickAccess . runCommand ( 'notebook.cell.insertMarkdownCellBelow' ) ; } else { await this . quickAccess . runCommand ( 'notebook.cell.insertCodeCellBelow' ) ; } } async deleteActiveCell ( ) { await this . quickAccess . runCommand ( 'notebook.cell.delete' ) ; } async focusInCellOutput ( ) { await this . quickAccess . runCommand ( 'notebook.cell.focusInOutput' ) ; await this . code . waitForActiveElement ( 'webview, .webview' ) ; } async focusOutCellOutput ( ) { await this . quickAccess . runCommand ( 'notebook.cell.focusOutOutput' ) ; } async executeActiveCell ( ) { await this . quickAccess . runCommand ( 'notebook.cell.execute' ) ; } async executeCellAction ( selector ) { await this . code . waitAndClick ( selector ) ; } }