Skip to content

Commit b7736a2

Browse files
committed
more testing for unsaved document
1 parent d9b9744 commit b7736a2

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

extensions/vscode-notebook-tests/src/notebook.test.ts

+83
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,86 @@ suite('notebook workflow', () => {
189189
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
190190
});
191191
});
192+
193+
suite('notebook dirty state', () => {
194+
test('notebook open', async function () {
195+
const resource = vscode.Uri.parse(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
196+
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
197+
198+
await waitFor(500);
199+
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
200+
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.source, 'test');
201+
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript');
202+
203+
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
204+
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.source, '');
205+
206+
await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove');
207+
const activeCell = vscode.notebook.activeNotebookEditor!.selection;
208+
assert.notEqual(vscode.notebook.activeNotebookEditor!.selection, undefined);
209+
assert.equal(activeCell!.source, '');
210+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 3);
211+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1);
212+
213+
214+
await vscode.commands.executeCommand('default:type', { text: 'var abc = 0;' });
215+
// await vscode.commands.executeCommand('workbench.action.files.save');
216+
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
217+
218+
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
219+
220+
await waitFor(500);
221+
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true);
222+
assert.equal(vscode.notebook.activeNotebookEditor?.selection !== undefined, true);
223+
assert.deepEqual(vscode.notebook.activeNotebookEditor?.document.cells[1], vscode.notebook.activeNotebookEditor?.selection);
224+
assert.equal(vscode.notebook.activeNotebookEditor?.selection?.source, 'var abc = 0;');
225+
226+
await vscode.commands.executeCommand('workbench.action.files.save');
227+
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
228+
});
229+
});
230+
231+
suite('notebook undo redo', () => {
232+
test('notebook open', async function () {
233+
const resource = vscode.Uri.parse(join(vscode.workspace.rootPath || '', './first.vsctestnb'));
234+
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
235+
236+
await waitFor(500);
237+
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
238+
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.source, 'test');
239+
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript');
240+
241+
await vscode.commands.executeCommand('notebook.cell.insertCodeCellBelow');
242+
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.source, '');
243+
244+
await vscode.commands.executeCommand('notebook.cell.insertCodeCellAbove');
245+
const activeCell = vscode.notebook.activeNotebookEditor!.selection;
246+
assert.notEqual(vscode.notebook.activeNotebookEditor!.selection, undefined);
247+
assert.equal(activeCell!.source, '');
248+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 3);
249+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1);
250+
251+
252+
// modify the second cell, delete it
253+
await vscode.commands.executeCommand('default:type', { text: 'var abc = 0;' });
254+
await vscode.commands.executeCommand('notebook.cell.delete');
255+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 2);
256+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(vscode.notebook.activeNotebookEditor!.selection!), 1);
257+
258+
259+
// undo should bring back the deleted cell, and revert to previous content and selection
260+
await vscode.commands.executeCommand('notebook.undo');
261+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 3);
262+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(vscode.notebook.activeNotebookEditor!.selection!), 1);
263+
assert.equal(vscode.notebook.activeNotebookEditor?.selection?.source, 'var abc = 0;');
264+
265+
// redo
266+
// await vscode.commands.executeCommand('notebook.redo');
267+
// assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 2);
268+
// assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(vscode.notebook.activeNotebookEditor!.selection!), 1);
269+
// assert.equal(vscode.notebook.activeNotebookEditor?.selection?.source, 'test');
270+
271+
await vscode.commands.executeCommand('workbench.action.files.save');
272+
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
273+
});
274+
});

0 commit comments

Comments
 (0)