mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-20 16:49:06 +01:00
Add test for scrolling
This commit is contained in:
@@ -24,6 +24,22 @@ async function createInteractiveWindow(kernel: Kernel) {
|
||||
return notebookEditor;
|
||||
}
|
||||
|
||||
async function addCell(code: string, notebook: vscode.NotebookDocument) {
|
||||
const cell = new vscode.NotebookCellData(vscode.NotebookCellKind.Code, code, 'typescript');
|
||||
const edit = vscode.NotebookEdit.insertCells(notebook.cellCount, [cell]);
|
||||
const workspaceEdit = new vscode.WorkspaceEdit();
|
||||
workspaceEdit.set(notebook.uri, [edit]);
|
||||
await vscode.workspace.applyEdit(workspaceEdit);
|
||||
return notebook.cellAt(notebook.cellCount - 1);
|
||||
}
|
||||
|
||||
async function addCellAndRun(code: string, notebook: vscode.NotebookDocument) {
|
||||
const cell = await addCell(code, notebook);
|
||||
await vscode.commands.executeCommand('notebook.execute');
|
||||
assert.strictEqual(cell.outputs.length, 1, 'execute failed');
|
||||
return cell;
|
||||
}
|
||||
|
||||
|
||||
(vscode.env.uiKind === vscode.UIKind.Web ? suite.skip : suite)('Interactive Window', function () {
|
||||
|
||||
@@ -49,17 +65,24 @@ async function createInteractiveWindow(kernel: Kernel) {
|
||||
assert.ok(notebookEditor);
|
||||
|
||||
// Try adding a cell and running it.
|
||||
const cell = new vscode.NotebookCellData(vscode.NotebookCellKind.Code, 'print foo', 'typescript');
|
||||
const edit = vscode.NotebookEdit.insertCells(0, [cell]);
|
||||
const workspaceEdit = new vscode.WorkspaceEdit();
|
||||
workspaceEdit.set(notebookEditor.notebook.uri, [edit]);
|
||||
await vscode.workspace.applyEdit(workspaceEdit);
|
||||
await addCell('print foo', notebookEditor.notebook);
|
||||
|
||||
assert.strictEqual(notebookEditor.notebook.cellCount, 1);
|
||||
assert.strictEqual(notebookEditor.notebook.cellAt(0).kind, vscode.NotebookCellKind.Code);
|
||||
});
|
||||
|
||||
await vscode.commands.executeCommand('notebook.execute');
|
||||
assert.strictEqual(notebookEditor.notebook.cellAt(0).outputs.length, 1, 'should execute');
|
||||
test('Interactive window scrolls after execute', async () => {
|
||||
assert.ok(vscode.workspace.workspaceFolders);
|
||||
const notebookEditor = await createInteractiveWindow(defaultKernel);
|
||||
assert.ok(notebookEditor);
|
||||
|
||||
// Run and add a bunch of cells
|
||||
for (let i = 0; i < 20; i++) {
|
||||
await addCellAndRun(`print ${i}`, notebookEditor.notebook);
|
||||
}
|
||||
|
||||
// Verify visible range has the last cell
|
||||
assert.strictEqual(notebookEditor.visibleRanges[notebookEditor.visibleRanges.length - 1].end, notebookEditor.notebook.cellCount, `Last cell is not visible`);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,6 +29,12 @@ async function withEvent<T>(event: vscode.Event<T>, callback: (e: Promise<T>) =>
|
||||
}
|
||||
|
||||
|
||||
function sleep(ms: number): Promise<void> {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
||||
|
||||
export class Kernel {
|
||||
|
||||
readonly controller: vscode.NotebookController;
|
||||
@@ -59,8 +65,9 @@ export class Kernel {
|
||||
// create a single output with exec order 1 and output is plain/text
|
||||
// of either the cell itself or (iff empty) the cell's document's uri
|
||||
const task = this.controller.createNotebookCellExecution(cell);
|
||||
task.start();
|
||||
task.start(Date.now());
|
||||
task.executionOrder = 1;
|
||||
await sleep(10); // Force to be take some time
|
||||
await task.replaceOutput([new vscode.NotebookCellOutput([
|
||||
vscode.NotebookCellOutputItem.text(cell.document.getText() || cell.document.uri.toString(), 'text/plain')
|
||||
])]);
|
||||
|
||||
Reference in New Issue
Block a user