diff --git a/src/sql/workbench/contrib/notebook/browser/notebookEditor.ts b/src/sql/workbench/contrib/notebook/browser/notebookEditor.ts index 9ba5c18f84..a08fd87804 100644 --- a/src/sql/workbench/contrib/notebook/browser/notebookEditor.ts +++ b/src/sql/workbench/contrib/notebook/browser/notebookEditor.ts @@ -368,7 +368,7 @@ export class NotebookEditor extends EditorPane implements IFindNotebookControlle currentMatch: false, loop: true }; - this._notebookModel.cells.forEach(cell => { + this._notebookModel.cells?.forEach(cell => { this._register(cell.onCellModeChanged((state) => { this._onFindStateChange(changeEvent).catch(onUnexpectedError); })); diff --git a/src/sql/workbench/contrib/notebook/test/browser/notebookEditor.test.ts b/src/sql/workbench/contrib/notebook/test/browser/notebookEditor.test.ts index 0fb441076e..88f96701f9 100644 --- a/src/sql/workbench/contrib/notebook/test/browser/notebookEditor.test.ts +++ b/src/sql/workbench/contrib/notebook/test/browser/notebookEditor.test.ts @@ -56,15 +56,15 @@ import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/u import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService'; import { workbenchInstantiationService } from 'vs/workbench/test/browser/workbenchTestServices'; import { IProductService } from 'vs/platform/product/common/productService'; +import { IHostColorSchemeService } from 'vs/workbench/services/themes/common/hostColorSchemeService'; +import { ColorScheme } from 'vs/platform/theme/common/theme'; +import { CellModel } from 'sql/workbench/services/notebook/browser/models/cell'; class NotebookModelStub extends stubs.NotebookModelStub { public contentChangedEmitter = new Emitter(); private _kernelChangedEmitter = new Emitter(); private _onActiveCellChanged = new Emitter(); - get cells(): ICellModel[] { - return this.cells; - } public get contentChanged(): Event { return this.contentChangedEmitter.event; } @@ -84,8 +84,12 @@ class NotebookModelStub extends stubs.NotebookModelStub { } } -suite.skip('Test class NotebookEditor:', () => { +suite('Test class NotebookEditor:', () => { let instantiationService = workbenchInstantiationService(); + instantiationService.stub(IHostColorSchemeService, { + colorScheme: ColorScheme.DARK, + onDidChangeColorScheme: new Emitter().event + }); let workbenchThemeService = instantiationService.createInstance(WorkbenchThemeService); let notebookEditor: NotebookEditor; let testTitle: string; @@ -169,7 +173,7 @@ suite.skip('Test class NotebookEditor:', () => { }); } - test.skip('Verifies that getCellEditor() returns a valid text editor object for valid guid input', async () => { + test('Verifies that getCellEditor() returns a valid text editor object for valid guid input', async () => { await setupNotebookEditor(notebookEditor, untitledNotebookInput); const result = notebookEditor.getCellEditor(cellTextEditorGuid); assert.strictEqual(result, queryTextEditor, 'notebookEditor.getCellEditor() should return an expected QueryTextEditor when a guid corresponding to that editor is passed in.'); @@ -451,6 +455,7 @@ suite.skip('Test class NotebookEditor:', () => { }); untitledNotebookInput.notebookFindModel.notebookModel = undefined; // clear preexisting notebookModel const notebookModel = await notebookEditor.getNotebookModel(); + notebookModel['_cells'] = [new CellModel({ cell_type: 'code', source: '' }, { isTrusted: true, notebook: notebookModel })]; notebookEditor['registerModelChanges'](); notebookModel.cells[0]['_onCellModeChanged'].fire(true); //fire cellModeChanged event on the first sell of our test notebookModel notebookModel.contentChangedEmitter.fire({ changeType: NotebookChangeType.Saved }); diff --git a/src/sql/workbench/contrib/notebook/test/testCommon.ts b/src/sql/workbench/contrib/notebook/test/testCommon.ts index 6629fb16ca..8596acda2f 100644 --- a/src/sql/workbench/contrib/notebook/test/testCommon.ts +++ b/src/sql/workbench/contrib/notebook/test/testCommon.ts @@ -21,9 +21,9 @@ export class NotebookEditorStub extends stubs.NotebookEditorStub { model: INotebookModel | undefined; cells?: ICellModel[] = []; - public readonly id = this.notebookParams?.notebookUri?.toString(); + public readonly id: string; - public readonly modelReady: Promise = Promise.resolve(this.model); + public readonly modelReady: Promise; // Normally one needs to provide either the editor or the instantiationService as the constructor parameter constructor({ cellGuid, instantiationService, editor, model, notebookParams }: { cellGuid?: string; instantiationService?: IInstantiationService; editor?: QueryTextEditor; model?: INotebookModel, notebookParams?: INotebookParams } = {}) { @@ -31,6 +31,8 @@ export class NotebookEditorStub extends stubs.NotebookEditorStub { this.model = model; this.notebookParams = notebookParams; this.cellEditors = [new CellEditorProviderStub({ cellGuid: cellGuid, instantiationService: instantiationService, editor: editor })]; + this.id = this.notebookParams?.notebookUri?.toString(); + this.modelReady = Promise.resolve(this.model); } }