move document event tests into notebook.document
This commit is contained in:
parent
ef62adb3ba
commit
5c063c5f83
2 changed files with 58 additions and 52 deletions
|
@ -38,6 +38,7 @@ suite('Notebook Document', function () {
|
|||
};
|
||||
|
||||
const disposables: vscode.Disposable[] = [];
|
||||
const testDisposables: vscode.Disposable[] = [];
|
||||
|
||||
suiteTeardown(async function () {
|
||||
utils.assertNoRpc();
|
||||
|
@ -47,6 +48,11 @@ suite('Notebook Document', function () {
|
|||
disposables.length = 0;
|
||||
});
|
||||
|
||||
teardown(async function () {
|
||||
utils.disposeAll(testDisposables);
|
||||
testDisposables.length = 0;
|
||||
});
|
||||
|
||||
suiteSetup(function () {
|
||||
disposables.push(vscode.workspace.registerNotebookContentProvider('notebook.nbdtest', complexContentProvider));
|
||||
disposables.push(vscode.workspace.registerNotebookSerializer('notebook.nbdserializer', simpleContentProvider));
|
||||
|
@ -277,6 +283,37 @@ suite('Notebook Document', function () {
|
|||
assert.strictEqual(data.changes[0].items[1], document.cellAt(1));
|
||||
});
|
||||
|
||||
test('workspace edit API (replaceMetadata)', async function () {
|
||||
const uri = await utils.createRandomFile(undefined, undefined, '.nbdtest');
|
||||
const document = await vscode.workspace.openNotebookDocument(uri);
|
||||
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.replaceNotebookCellMetadata(document.uri, 0, { inputCollapsed: true });
|
||||
const success = await vscode.workspace.applyEdit(edit);
|
||||
assert.strictEqual(success, true);
|
||||
assert.strictEqual(document.cellAt(0).metadata.inputCollapsed, true);
|
||||
});
|
||||
|
||||
test('workspace edit API (replaceMetadata, event)', async function () {
|
||||
const uri = await utils.createRandomFile(undefined, undefined, '.nbdtest');
|
||||
const document = await vscode.workspace.openNotebookDocument(uri);
|
||||
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
const event = utils.asPromise<vscode.NotebookCellMetadataChangeEvent>(vscode.notebooks.onDidChangeCellMetadata);
|
||||
|
||||
edit.replaceNotebookCellMetadata(document.uri, 0, { inputCollapsed: true });
|
||||
const success = await vscode.workspace.applyEdit(edit);
|
||||
assert.strictEqual(success, true);
|
||||
const data = await event;
|
||||
|
||||
// check document
|
||||
assert.strictEqual(document.cellAt(0).metadata.inputCollapsed, true);
|
||||
|
||||
// check event data
|
||||
assert.strictEqual(data.document === document, true);
|
||||
assert.strictEqual(data.cell.index, 0);
|
||||
});
|
||||
|
||||
test('document save API', async function () {
|
||||
const uri = await utils.createRandomFile(undefined, undefined, '.nbdtest');
|
||||
const notebook = await vscode.workspace.openNotebookDocument(uri);
|
||||
|
@ -372,4 +409,23 @@ suite('Notebook Document', function () {
|
|||
await document.save();
|
||||
assert.strictEqual(document.isDirty, false);
|
||||
});
|
||||
|
||||
test('onDidOpenNotebookDocument - emit event only once when opened in two editors', async function () {
|
||||
let counter = 0;
|
||||
testDisposables.push(vscode.workspace.onDidOpenNotebookDocument(() => {
|
||||
counter++;
|
||||
}));
|
||||
|
||||
const uri = await utils.createRandomFile(undefined, undefined, '.nbdtest');
|
||||
const notebook = await vscode.workspace.openNotebookDocument(uri);
|
||||
assert.strictEqual(counter, 1);
|
||||
|
||||
await vscode.window.showNotebookDocument(notebook, { viewColumn: vscode.ViewColumn.Active });
|
||||
assert.strictEqual(counter, 1);
|
||||
assert.strictEqual(vscode.window.visibleNotebookEditors.length, 1);
|
||||
|
||||
await vscode.window.showNotebookDocument(notebook, { viewColumn: vscode.ViewColumn.Beside });
|
||||
assert.strictEqual(counter, 1);
|
||||
assert.strictEqual(vscode.window.visibleNotebookEditors.length, 2);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -204,24 +204,6 @@ suite('Notebook API tests', function () {
|
|||
await saveAllFilesAndCloseAll();
|
||||
});
|
||||
|
||||
test('shared document in notebook editors', async function () {
|
||||
let counter = 0;
|
||||
testDisposables.push(vscode.workspace.onDidOpenNotebookDocument(() => {
|
||||
counter++;
|
||||
}));
|
||||
|
||||
const notebook = await openRandomNotebookDocument();
|
||||
assert.strictEqual(counter, 1);
|
||||
|
||||
await vscode.window.showNotebookDocument(notebook, { viewColumn: vscode.ViewColumn.Active });
|
||||
assert.strictEqual(counter, 1);
|
||||
assert.strictEqual(vscode.window.visibleNotebookEditors.length, 1);
|
||||
|
||||
await vscode.window.showNotebookDocument(notebook, { viewColumn: vscode.ViewColumn.Beside });
|
||||
assert.strictEqual(counter, 1);
|
||||
assert.strictEqual(vscode.window.visibleNotebookEditors.length, 2);
|
||||
});
|
||||
|
||||
test('editor onDidChangeVisibleNotebookEditors-event', async function () {
|
||||
const resource = await createRandomNotebookFile();
|
||||
const firstEditorOpen = asPromise(vscode.window.onDidChangeVisibleNotebookEditors);
|
||||
|
@ -388,38 +370,6 @@ suite('Notebook API tests', function () {
|
|||
await firstEditorDeactivate;
|
||||
});
|
||||
|
||||
test('edit API (replaceMetadata)', async function () {
|
||||
const notebook = await openRandomNotebookDocument();
|
||||
await vscode.window.showNotebookDocument(notebook);
|
||||
|
||||
await vscode.window.activeNotebookEditor!.edit(editBuilder => {
|
||||
editBuilder.replaceCellMetadata(0, { inputCollapsed: true });
|
||||
});
|
||||
|
||||
const document = vscode.window.activeNotebookEditor?.document!;
|
||||
assert.strictEqual(document.cellCount, 2);
|
||||
assert.strictEqual(document.cellAt(0).metadata.inputCollapsed, true);
|
||||
|
||||
assert.strictEqual(document.isDirty, true);
|
||||
});
|
||||
|
||||
test('edit API (replaceMetadata, event)', async function () {
|
||||
const notebook = await openRandomNotebookDocument();
|
||||
await vscode.window.showNotebookDocument(notebook);
|
||||
|
||||
const event = asPromise<vscode.NotebookCellMetadataChangeEvent>(vscode.notebooks.onDidChangeCellMetadata);
|
||||
|
||||
await vscode.window.activeNotebookEditor!.edit(editBuilder => {
|
||||
editBuilder.replaceCellMetadata(0, { inputCollapsed: true });
|
||||
});
|
||||
|
||||
const data = await event;
|
||||
assert.strictEqual(data.document, vscode.window.activeNotebookEditor?.document);
|
||||
assert.strictEqual(data.cell.metadata.inputCollapsed, true);
|
||||
|
||||
assert.strictEqual(data.document.isDirty, true);
|
||||
});
|
||||
|
||||
test('edit API batch edits', async function () {
|
||||
const resource = await createRandomNotebookFile();
|
||||
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
|
||||
|
@ -461,7 +411,7 @@ suite('Notebook API tests', function () {
|
|||
assert.strictEqual(vscode.window.activeNotebookEditor!.document.cellCount, 2);
|
||||
});
|
||||
|
||||
test('initialzation should not emit cell change events.', async function () {
|
||||
test('#98841, initialzation should not emit cell change events.', async function () {
|
||||
let count = 0;
|
||||
|
||||
testDisposables.push(vscode.notebooks.onDidChangeNotebookCells(() => {
|
||||
|
@ -1254,7 +1204,7 @@ suite('Notebook API tests', function () {
|
|||
// });
|
||||
});
|
||||
|
||||
suite('Notebook API tests (no kernel)', function () {
|
||||
suite('Notebook API tests (metadata)', function () {
|
||||
const testDisposables: vscode.Disposable[] = [];
|
||||
const suiteDisposables: vscode.Disposable[] = [];
|
||||
|
||||
|
|
Loading…
Reference in a new issue