Skip to content

Commit

Permalink
update docs and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Silvester committed Dec 20, 2019
1 parent 01493cd commit 188bff1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/notebook/src/model.ts
Expand Up @@ -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();
Expand Down
20 changes: 20 additions & 0 deletions tests/test-notebook/src/model.spec.ts
Expand Up @@ -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({});

Expand Down

0 comments on commit 188bff1

Please sign in to comment.