move cell output tests to document.

This commit is contained in:
rebornix
2021-02-17 12:08:58 -08:00
parent 0354f334ed
commit 086112d496
2 changed files with 61 additions and 93 deletions

View File

@@ -429,99 +429,6 @@ suite('Notebook API tests', function () {
await saveAllFilesAndCloseAll(resource);
});
test('edit API (replaceCells)', async function () {
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
const cellsChangeEvent = asPromise<vscode.NotebookCellsChangeEvent>(vscode.notebook.onDidChangeNotebookCells);
await vscode.window.activeNotebookEditor!.edit(editBuilder => {
editBuilder.replaceCells(1, 0, [{ cellKind: vscode.NotebookCellKind.Code, language: 'javascript', source: 'test 2', outputs: [], metadata: undefined }]);
});
const cellChangeEventRet = await cellsChangeEvent;
assert.strictEqual(cellChangeEventRet.document === vscode.window.activeNotebookEditor?.document, true);
assert.strictEqual(cellChangeEventRet.document.isDirty, true);
assert.strictEqual(cellChangeEventRet.changes.length, 1);
assert.strictEqual(cellChangeEventRet.changes[0].start, 1);
assert.strictEqual(cellChangeEventRet.changes[0].deletedCount, 0);
assert.strictEqual(cellChangeEventRet.changes[0].items[0] === vscode.window.activeNotebookEditor!.document.cells[1], true);
await saveAllFilesAndCloseAll(resource);
});
test('edit API (replaceOutput, USE NotebookCellOutput-type)', async function () {
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
await vscode.window.activeNotebookEditor!.edit(editBuilder => {
editBuilder.replaceCellOutput(0, [new vscode.NotebookCellOutput([
new vscode.NotebookCellOutputItem('application/foo', 'bar'),
new vscode.NotebookCellOutputItem('application/json', { data: true }, { metadata: true }),
])]);
});
const document = vscode.window.activeNotebookEditor?.document!;
assert.strictEqual(document.isDirty, true);
assert.strictEqual(document.cells.length, 1);
assert.strictEqual(document.cells[0].outputs.length, 1);
// consuming is OLD api (for now)
const [output] = document.cells[0].outputs;
assert.strictEqual(output.outputs.length, 2);
assert.strictEqual(output.outputs[0].mime, 'application/foo');
assert.strictEqual(output.outputs[0].value, 'bar');
assert.strictEqual(output.outputs[1].mime, 'application/json');
assert.deepStrictEqual(output.outputs[1].value, { data: true });
await saveAllFilesAndCloseAll(undefined);
});
test('edit API (replaceOutput)', async function () {
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
await vscode.window.activeNotebookEditor!.edit(editBuilder => {
editBuilder.replaceCellOutput(0, [new vscode.NotebookCellOutput([
new vscode.NotebookCellOutputItem('foo', 'bar')
])]);
});
const document = vscode.window.activeNotebookEditor?.document!;
assert.strictEqual(document.isDirty, true);
assert.strictEqual(document.cells.length, 1);
assert.strictEqual(document.cells[0].outputs.length, 1);
assert.strictEqual(document.cells[0].outputs[0].outputs.length, 1);
assert.strictEqual(document.cells[0].outputs[0].outputs[0].mime, 'foo');
assert.strictEqual(document.cells[0].outputs[0].outputs[0].value, 'bar');
await saveAllFilesAndCloseAll(undefined);
});
test('edit API (replaceOutput, event)', async function () {
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
const outputChangeEvent = asPromise<vscode.NotebookCellOutputsChangeEvent>(vscode.notebook.onDidChangeCellOutputs);
await vscode.window.activeNotebookEditor!.edit(editBuilder => {
editBuilder.replaceCellOutput(0, [new vscode.NotebookCellOutput([
new vscode.NotebookCellOutputItem('foo', 'bar')
])]);
});
const value = await outputChangeEvent;
assert.strictEqual(value.document === vscode.window.activeNotebookEditor?.document, true);
assert.strictEqual(value.document.isDirty, true);
assert.strictEqual(value.cells.length, 1);
assert.strictEqual(value.document.cells.length, 1);
assert.strictEqual(value.document.cells[0].outputs.length, 1);
assert.strictEqual(value.document.cells[0].outputs[0].outputs.length, 1);
assert.strictEqual(value.document.cells[0].outputs[0].outputs[0].mime, 'foo');
assert.strictEqual(value.document.cells[0].outputs[0].outputs[0].value, 'bar');
await saveAllFilesAndCloseAll(undefined);
});
test('edit API (replaceMetadata)', async function () {
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');