Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/automation/src/notebook.ts
3520 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Code } from './code';
7
import { QuickAccess } from './quickaccess';
8
import { QuickInput } from './quickinput';
9
10
const activeRowSelector = `.notebook-editor .monaco-list-row.focused`;
11
12
export class Notebook {
13
14
constructor(
15
private readonly quickAccess: QuickAccess,
16
private readonly quickInput: QuickInput,
17
private readonly code: Code) {
18
}
19
20
async openNotebook() {
21
await this.quickAccess.openFileQuickAccessAndWait('notebook.ipynb', 1);
22
await this.quickInput.selectQuickInputElement(0);
23
24
await this.code.waitForElement(activeRowSelector);
25
await this.focusFirstCell();
26
}
27
28
async focusNextCell() {
29
await this.code.dispatchKeybinding('down', async () => {
30
// TODO: Add an accept callback to verify the keybinding was successful
31
});
32
}
33
34
async focusFirstCell() {
35
await this.quickAccess.runCommand('notebook.focusTop');
36
}
37
38
async editCell() {
39
await this.code.dispatchKeybinding('enter', async () => {
40
// TODO: Add an accept callback to verify the keybinding was successful
41
});
42
}
43
44
async stopEditingCell() {
45
await this.quickAccess.runCommand('notebook.cell.quitEdit');
46
}
47
48
async waitForTypeInEditor(text: string): Promise<any> {
49
const editor = `${activeRowSelector} .monaco-editor`;
50
51
await this.code.waitForElement(editor);
52
53
const editContext = `${editor} ${!this.code.editContextEnabled ? 'textarea' : '.native-edit-context'}`;
54
await this.code.waitForActiveElement(editContext);
55
56
await this.code.waitForTypeInEditor(editContext, text);
57
58
await this._waitForActiveCellEditorContents(c => c.indexOf(text) > -1);
59
}
60
61
async waitForActiveCellEditorContents(contents: string): Promise<any> {
62
return this._waitForActiveCellEditorContents(str => str === contents);
63
}
64
65
private async _waitForActiveCellEditorContents(accept: (contents: string) => boolean): Promise<any> {
66
const selector = `${activeRowSelector} .monaco-editor .view-lines`;
67
return this.code.waitForTextContent(selector, undefined, c => accept(c.replace(/\u00a0/g, ' ')));
68
}
69
70
async waitForMarkdownContents(markdownSelector: string, text: string): Promise<void> {
71
const selector = `${activeRowSelector} .markdown ${markdownSelector}`;
72
await this.code.waitForTextContent(selector, text);
73
}
74
75
async insertNotebookCell(kind: 'markdown' | 'code'): Promise<void> {
76
if (kind === 'markdown') {
77
await this.quickAccess.runCommand('notebook.cell.insertMarkdownCellBelow');
78
} else {
79
await this.quickAccess.runCommand('notebook.cell.insertCodeCellBelow');
80
}
81
}
82
83
async deleteActiveCell(): Promise<void> {
84
await this.quickAccess.runCommand('notebook.cell.delete');
85
}
86
87
async focusInCellOutput(): Promise<void> {
88
await this.quickAccess.runCommand('notebook.cell.focusInOutput');
89
await this.code.waitForActiveElement('webview, .webview');
90
}
91
92
async focusOutCellOutput(): Promise<void> {
93
await this.quickAccess.runCommand('notebook.cell.focusOutOutput');
94
}
95
96
async executeActiveCell(): Promise<void> {
97
await this.quickAccess.runCommand('notebook.cell.execute');
98
}
99
100
async executeCellAction(selector: string): Promise<void> {
101
await this.code.waitAndClick(selector);
102
}
103
}
104
105