mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-21 01:25:37 -05:00
Add Cell after current active cell (#10203)
* Add Cell after current active cell * fixed error * more fixes * Addressed PR * merged with master * Fixed the tests and code * removed try catch and modified the test to check the method does not throw. Co-authored-by: Rajesh Kamath <rajkashop@hotmail.com>
This commit is contained in:
@@ -27,6 +27,7 @@ import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/br
|
||||
import { TreeUpdateUtils } from 'sql/workbench/services/objectExplorer/browser/treeUpdateUtils';
|
||||
import { find, firstIndex } from 'vs/base/common/arrays';
|
||||
import { INotebookEditor } from 'sql/workbench/services/notebook/browser/notebookService';
|
||||
import { NotebookComponent } from 'sql/workbench/contrib/notebook/browser/notebook.component';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
|
||||
const msgLoading = localize('loading', "Loading kernels...");
|
||||
@@ -47,15 +48,18 @@ export class AddCellAction extends Action {
|
||||
) {
|
||||
super(id, label, cssClass);
|
||||
}
|
||||
public run(context: INotebookEditor): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
try {
|
||||
context.addCell(this.cellType);
|
||||
resolve(true);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
public async run(context: INotebookEditor): Promise<any> {
|
||||
//Add Cell after current selected cell.
|
||||
let index = 0;
|
||||
if (context && context.cells) {
|
||||
let notebookcomponent = context as NotebookComponent;
|
||||
let id = notebookcomponent.activeCellId;
|
||||
if (id) {
|
||||
index = context.cells.findIndex(cell => cell.id === id);
|
||||
index = index + 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
context.addCell(this.cellType, index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,17 +26,16 @@ suite('Notebook Actions', function (): void {
|
||||
|
||||
// Normal use case
|
||||
let mockNotebookComponent = TypeMoq.Mock.ofType<INotebookEditor>(NotebookComponentStub);
|
||||
mockNotebookComponent.setup(c => c.addCell(TypeMoq.It.isAny())).returns(cellType => {
|
||||
mockNotebookComponent.setup(c => c.addCell(TypeMoq.It.isAny(), TypeMoq.It.isAnyNumber())).returns(cellType => {
|
||||
actualCellType = cellType;
|
||||
});
|
||||
|
||||
let result = await action.run(mockNotebookComponent.object);
|
||||
assert.ok(result, 'Add Cell Action should succeed');
|
||||
assert.doesNotThrow(() => action.run(mockNotebookComponent.object));
|
||||
assert.strictEqual(actualCellType, testCellType);
|
||||
|
||||
// Handle error case
|
||||
mockNotebookComponent.reset();
|
||||
mockNotebookComponent.setup(c => c.addCell(TypeMoq.It.isAny())).throws(new Error('Test Error'));
|
||||
mockNotebookComponent.setup(c => c.addCell(TypeMoq.It.isAny(), TypeMoq.It.isAnyNumber())).throws(new Error('Test Error'));
|
||||
await assert.rejects(action.run(mockNotebookComponent.object));
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user