提交 cf5dfe1b 编写于 作者: J Johannes Rieken

unit test for applying metadata and output, https://github.com/microsoft/vscode/issues/105283

上级 88664e26
......@@ -252,10 +252,12 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
break;
case CellEditType.Output:
//TODO@joh,@rebornix no event, no undo stop (?)
this.assertIndex(edit.index);
const cell = this.cells[edit.index];
this.spliceNotebookCellOutputs(cell.handle, [[0, cell.outputs.length, edit.outputs]]);
break;
case CellEditType.Metadata:
this.assertIndex(edit.index);
this.changeCellMetadata(this.cells[edit.index].handle, edit.metadata);
break;
}
......
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { CellKind, CellEditType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, CellEditType, CellOutputKind } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { withTestNotebook, TestCell, setupInstantiationService } from 'vs/workbench/contrib/notebook/test/testNotebookEditor';
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
......@@ -139,4 +139,89 @@ suite('NotebookTextModel', () => {
}
);
});
test('output', function () {
withTestNotebook(
instantiationService,
blukEditService,
undoRedoService,
[
['var a = 1;', 'javascript', CellKind.Code, [], { editable: true }],
],
(editor, viewModel, textModel) => {
// invalid index 1
assert.throws(() => {
textModel.applyEdit(textModel.versionId, [{
index: Number.MAX_VALUE,
editType: CellEditType.Output,
outputs: []
}], true);
});
// invalid index 2
assert.throws(() => {
textModel.applyEdit(textModel.versionId, [{
index: -1,
editType: CellEditType.Output,
outputs: []
}], true);
});
textModel.applyEdit(textModel.versionId, [{
index: 0,
editType: CellEditType.Output,
outputs: [{
outputKind: CellOutputKind.Rich,
outputId: 'someId',
data: { 'text/markdown': '_Hello_' }
}]
}], true);
assert.equal(textModel.cells.length, 1);
assert.equal(textModel.cells[0].outputs.length, 1);
assert.equal(textModel.cells[0].outputs[0].outputKind, CellOutputKind.Rich);
}
);
});
test('metadata', function () {
withTestNotebook(
instantiationService,
blukEditService,
undoRedoService,
[
['var a = 1;', 'javascript', CellKind.Code, [], { editable: true }],
],
(editor, viewModel, textModel) => {
// invalid index 1
assert.throws(() => {
textModel.applyEdit(textModel.versionId, [{
index: Number.MAX_VALUE,
editType: CellEditType.Metadata,
metadata: { editable: false }
}], true);
});
// invalid index 2
assert.throws(() => {
textModel.applyEdit(textModel.versionId, [{
index: -1,
editType: CellEditType.Metadata,
metadata: { editable: false }
}], true);
});
textModel.applyEdit(textModel.versionId, [{
index: 0,
editType: CellEditType.Metadata,
metadata: { editable: false },
}], true);
assert.equal(textModel.cells.length, 1);
assert.equal(textModel.cells[0].metadata?.editable, false);
}
);
});
});
......@@ -381,9 +381,15 @@ export function withTestNotebook(instantiationService: TestInstantiationService,
const viewType = 'notebook';
const editor = new TestNotebookEditor();
const notebook = new NotebookTextModel(0, viewType, false, URI.parse('test'), undoRedoService, textModelService);
notebook.cells = cells.map((cell, index) => {
return new NotebookCellTextModel(notebook.uri, index, cell[0], cell[1], cell[2], cell[3], cell[4], textModelService);
});
notebook.initialize(cells.map(cell => {
return {
source: cell[0],
language: cell[1],
cellKind: cell[2],
outputs: cell[3],
metadata: cell[4]
};
}));
const model = new NotebookEditorTestModel(notebook);
const eventDispatcher = new NotebookEventDispatcher();
const viewModel = new NotebookViewModel(viewType, model.notebook, eventDispatcher, null, instantiationService, blukEditService, undoRedoService);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册