|
4 | 4 | *--------------------------------------------------------------------------------------------*/
|
5 | 5 |
|
6 | 6 | import * as assert from 'assert';
|
7 |
| -import { CellKind, CellEditType } from 'vs/workbench/contrib/notebook/common/notebookCommon'; |
| 7 | +import { CellKind, CellEditType, CellOutputKind } from 'vs/workbench/contrib/notebook/common/notebookCommon'; |
8 | 8 | import { withTestNotebook, TestCell, setupInstantiationService } from 'vs/workbench/contrib/notebook/test/testNotebookEditor';
|
9 | 9 | import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
|
10 | 10 | import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
|
@@ -139,4 +139,89 @@ suite('NotebookTextModel', () => {
|
139 | 139 | }
|
140 | 140 | );
|
141 | 141 | });
|
| 142 | + |
| 143 | + test('output', function () { |
| 144 | + withTestNotebook( |
| 145 | + instantiationService, |
| 146 | + blukEditService, |
| 147 | + undoRedoService, |
| 148 | + [ |
| 149 | + ['var a = 1;', 'javascript', CellKind.Code, [], { editable: true }], |
| 150 | + ], |
| 151 | + (editor, viewModel, textModel) => { |
| 152 | + |
| 153 | + // invalid index 1 |
| 154 | + assert.throws(() => { |
| 155 | + textModel.applyEdit(textModel.versionId, [{ |
| 156 | + index: Number.MAX_VALUE, |
| 157 | + editType: CellEditType.Output, |
| 158 | + outputs: [] |
| 159 | + }], true); |
| 160 | + }); |
| 161 | + |
| 162 | + // invalid index 2 |
| 163 | + assert.throws(() => { |
| 164 | + textModel.applyEdit(textModel.versionId, [{ |
| 165 | + index: -1, |
| 166 | + editType: CellEditType.Output, |
| 167 | + outputs: [] |
| 168 | + }], true); |
| 169 | + }); |
| 170 | + |
| 171 | + textModel.applyEdit(textModel.versionId, [{ |
| 172 | + index: 0, |
| 173 | + editType: CellEditType.Output, |
| 174 | + outputs: [{ |
| 175 | + outputKind: CellOutputKind.Rich, |
| 176 | + outputId: 'someId', |
| 177 | + data: { 'text/markdown': '_Hello_' } |
| 178 | + }] |
| 179 | + }], true); |
| 180 | + |
| 181 | + assert.equal(textModel.cells.length, 1); |
| 182 | + assert.equal(textModel.cells[0].outputs.length, 1); |
| 183 | + assert.equal(textModel.cells[0].outputs[0].outputKind, CellOutputKind.Rich); |
| 184 | + } |
| 185 | + ); |
| 186 | + }); |
| 187 | + |
| 188 | + test('metadata', function () { |
| 189 | + withTestNotebook( |
| 190 | + instantiationService, |
| 191 | + blukEditService, |
| 192 | + undoRedoService, |
| 193 | + [ |
| 194 | + ['var a = 1;', 'javascript', CellKind.Code, [], { editable: true }], |
| 195 | + ], |
| 196 | + (editor, viewModel, textModel) => { |
| 197 | + |
| 198 | + // invalid index 1 |
| 199 | + assert.throws(() => { |
| 200 | + textModel.applyEdit(textModel.versionId, [{ |
| 201 | + index: Number.MAX_VALUE, |
| 202 | + editType: CellEditType.Metadata, |
| 203 | + metadata: { editable: false } |
| 204 | + }], true); |
| 205 | + }); |
| 206 | + |
| 207 | + // invalid index 2 |
| 208 | + assert.throws(() => { |
| 209 | + textModel.applyEdit(textModel.versionId, [{ |
| 210 | + index: -1, |
| 211 | + editType: CellEditType.Metadata, |
| 212 | + metadata: { editable: false } |
| 213 | + }], true); |
| 214 | + }); |
| 215 | + |
| 216 | + textModel.applyEdit(textModel.versionId, [{ |
| 217 | + index: 0, |
| 218 | + editType: CellEditType.Metadata, |
| 219 | + metadata: { editable: false }, |
| 220 | + }], true); |
| 221 | + |
| 222 | + assert.equal(textModel.cells.length, 1); |
| 223 | + assert.equal(textModel.cells[0].metadata?.editable, false); |
| 224 | + } |
| 225 | + ); |
| 226 | + }); |
142 | 227 | });
|
0 commit comments