Browse Source

We should also trigger a model content change signal on cell move.

Ian Rose 6 years ago
parent
commit
b1de889866
2 changed files with 24 additions and 2 deletions
  1. 1 1
      packages/notebook/src/model.ts
  2. 23 1
      tests/test-notebook/src/model.spec.ts

+ 1 - 1
packages/notebook/src/model.ts

@@ -281,7 +281,7 @@ class NotebookModel extends DocumentModel implements INotebookModel {
       });
       break;
     default:
-      return;
+      break;
     }
     let factory = this.contentFactory;
     // Add code cell if there are no cells remaining.

+ 23 - 1
tests/test-notebook/src/model.spec.ts

@@ -122,7 +122,7 @@ describe('@jupyterlab/notebook', () => {
 
       context('cells `changed` signal', () => {
 
-        it('should emit a `contentChanged` signal', () => {
+        it('should emit a `contentChanged` signal upon cell addition', () => {
           let model = new NotebookModel();
           let cell = model.contentFactory.createCodeCell({});
           let called = false;
@@ -131,6 +131,28 @@ describe('@jupyterlab/notebook', () => {
           expect(called).to.be(true);
         });
 
+        it('should emit a `contentChanged` signal upon cell removal', () => {
+          let model = new NotebookModel();
+          let cell = model.contentFactory.createCodeCell({});
+          model.cells.push(cell);
+          let called = false;
+          model.contentChanged.connect(() => { called = true; });
+          model.cells.remove(0);
+          expect(called).to.be(true);
+        });
+
+        it('should emit a `contentChanged` signal upon cell move', () => {
+          let model = new NotebookModel();
+          let cell0 = model.contentFactory.createCodeCell({});
+          let cell1 = model.contentFactory.createCodeCell({});
+          model.cells.push(cell0);
+          model.cells.push(cell1);
+          let called = false;
+          model.contentChanged.connect(() => { called = true; });
+          model.cells.move(0, 1);
+          expect(called).to.be(true);
+        });
+
         it('should set the dirty flag', () => {
           let model = new NotebookModel();
           let cell = model.contentFactory.createCodeCell({});