Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/bulkEdit/test/browser/bulkCellEdits.test.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { CancellationToken } from '../../../../../base/common/cancellation.js';
8
import { URI } from '../../../../../base/common/uri.js';
9
import { mockObject } from '../../../../../base/test/common/mock.js';
10
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
11
import { IProgress } from '../../../../../platform/progress/common/progress.js';
12
import { UndoRedoGroup, UndoRedoSource } from '../../../../../platform/undoRedo/common/undoRedo.js';
13
import { BulkCellEdits, ResourceNotebookCellEdit } from '../../browser/bulkCellEdits.js';
14
import { NotebookTextModel } from '../../../notebook/common/model/notebookTextModel.js';
15
import { CellEditType, CellUri, IResolvedNotebookEditorModel } from '../../../notebook/common/notebookCommon.js';
16
import { INotebookEditorModelResolverService } from '../../../notebook/common/notebookEditorModelResolverService.js';
17
import { TestEditorService } from '../../../../test/browser/workbenchTestServices.js';
18
19
suite('BulkCellEdits', function () {
20
const store = ensureNoDisposablesAreLeakedInTestSuite();
21
22
async function runTest(inputUri: URI, resolveUri: URI) {
23
const progress: IProgress<void> = { report: _ => { } };
24
const editorService = store.add(new TestEditorService());
25
26
const notebook = mockObject<NotebookTextModel>()();
27
notebook.uri.returns(URI.file('/project/notebook.ipynb'));
28
29
const notebookEditorModel = mockObject<IResolvedNotebookEditorModel>()({ notebook: notebook as any });
30
notebookEditorModel.isReadonly.returns(false);
31
32
const notebookService = mockObject<INotebookEditorModelResolverService>()();
33
notebookService.resolve.returns({ object: notebookEditorModel, dispose: () => { } });
34
35
const edits = [
36
new ResourceNotebookCellEdit(inputUri, { index: 0, count: 1, editType: CellEditType.Replace, cells: [] })
37
];
38
const bce = new BulkCellEdits(new UndoRedoGroup(), new UndoRedoSource(), progress, CancellationToken.None, edits, editorService, notebookService as any);
39
await bce.apply();
40
41
const resolveArgs = notebookService.resolve.args[0];
42
assert.strictEqual(resolveArgs[0].toString(), resolveUri.toString());
43
}
44
45
const notebookUri = URI.file('/foo/bar.ipynb');
46
test('works with notebook URI', async () => {
47
await runTest(notebookUri, notebookUri);
48
});
49
50
test('maps cell URI to notebook URI', async () => {
51
await runTest(CellUri.generate(notebookUri, 5), notebookUri);
52
});
53
54
test('throws for invalid cell URI', async () => {
55
const badCellUri = CellUri.generate(notebookUri, 5).with({ fragment: '' });
56
await assert.rejects(async () => await runTest(badCellUri, notebookUri));
57
});
58
});
59
60