From 188bff167229d1ff61e7247c514b6796d805c66c Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 20 Dec 2019 13:40:38 -0600 Subject: [PATCH] update docs and add tests --- packages/notebook/src/model.ts | 4 ++++ tests/test-notebook/src/model.spec.ts | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/packages/notebook/src/model.ts b/packages/notebook/src/model.ts index 242c2ac38d97..e46b6107ffd7 100644 --- a/packages/notebook/src/model.ts +++ b/packages/notebook/src/model.ts @@ -282,6 +282,10 @@ export class NotebookModel extends DocumentModel implements INotebookModel { /** * Initialize the model with its current state. + * + * # Notes + * Adds an empty code cell if the model is empty + * and clears undo state. */ initialize(): void { super.initialize(); diff --git a/tests/test-notebook/src/model.spec.ts b/tests/test-notebook/src/model.spec.ts index f1f318517a67..8fa8d0b52caf 100644 --- a/tests/test-notebook/src/model.spec.ts +++ b/tests/test-notebook/src/model.spec.ts @@ -345,6 +345,26 @@ describe('@jupyterlab/notebook', () => { }); }); + describe('#initialize()', () => { + it('should add one code cell if the model is empty', () => { + const model = new NotebookModel(); + expect(model.cells.length).to.equal(0); + model.initialize(); + expect(model.cells.length).to.equal(1); + expect(model.cells.get(0).type).to.equal('code'); + }); + + it('should clear undo state', () => { + const model = new NotebookModel(); + const cell = model.contentFactory.createCodeCell({}); + cell.value.text = 'foo'; + model.cells.push(cell); + expect(model.cells.canUndo).to.equal(true); + model.initialize(); + expect(model.cells.canUndo).to.equal(false); + }); + }); + describe('.ContentFactory', () => { let factory = new NotebookModel.ContentFactory({});