Prechádzať zdrojové kódy

Fix test regressions.

A. Darian 9 rokov pred
rodič
commit
9a6e6fe1f6

+ 6 - 0
src/notebook/cells/widget.ts

@@ -205,6 +205,9 @@ class BaseCellWidget extends Widget {
     return this._trusted;
   }
   set trusted(value: boolean) {
+    if (!this._model) {
+      return;
+    }
     this._trustedCursor.setValue(value);
     this._trusted = value;
   }
@@ -261,6 +264,9 @@ class BaseCellWidget extends Widget {
    * Handle `update_request` messages.
    */
   protected onUpdateRequest(message: Message): void {
+    if (!this._model) {
+      return;
+    }
     // Handle read only state.
     let option = this._readOnly ? 'nocursor' : false;
     this.editor.editor.setOption('readOnly', option);

+ 27 - 51
test/src/notebook/cells/widget.spec.ts

@@ -66,33 +66,14 @@ class LogCell extends BaseCellWidget {
 }
 
 
-describe('jupyter-js-notebook', () => {
+describe('notebook/cells', () => {
 
   describe('BaseCellWidget', () => {
 
-    describe('.createCellEditor()', () => {
-
-      it('should create a cell editor widget', () => {
-        let editor = BaseCellWidget.createCellEditor(new CellModel());
-        expect(editor).to.be.a(CellEditorWidget);
-      });
-
-    });
-
-    describe('.createInputArea()', () => {
-
-      it('should create an input area widget', () => {
-        let editor = BaseCellWidget.createCellEditor(new CellModel());
-        let input = BaseCellWidget.createInputArea(editor);
-        expect(input).to.be.a(InputAreaWidget);
-      });
-
-    });
-
     describe('#constructor()', () => {
 
       it('should create a base cell widget', () => {
-        let widget = new BaseCellWidget(new CellModel());
+        let widget = new BaseCellWidget();
         expect(widget).to.be.a(BaseCellWidget);
       });
 
@@ -102,7 +83,9 @@ describe('jupyter-js-notebook', () => {
 
       it('should be settable', () => {
         let model = new CellModel();
-        let widget = new BaseCellWidget(model);
+        let widget = new BaseCellWidget();
+        expect(widget.model).to.be(null);
+        widget.model = model;
         expect(widget.model).to.be(model);
         widget.model = new CellModel();
         expect(widget.model).not.to.be(model);
@@ -113,12 +96,12 @@ describe('jupyter-js-notebook', () => {
     describe('#editor', () => {
 
       it('should be a cell editor widget', () => {
-        let widget = new BaseCellWidget(new CellModel());
+        let widget = new BaseCellWidget();
         expect(widget.editor).to.be.a(CellEditorWidget);
       });
 
       it('should be read-only', () => {
-        let widget = new BaseCellWidget(new CellModel());
+        let widget = new BaseCellWidget();
         expect(() => { widget.editor = null; }).to.throwError();
       });
 
@@ -127,23 +110,23 @@ describe('jupyter-js-notebook', () => {
     describe('#mimetype', () => {
 
       it('should be a string', () => {
-        let widget = new BaseCellWidget(new CellModel());
+        let widget = new BaseCellWidget();
         expect(typeof widget.mimetype).to.be('string');
       });
 
       it('should default to text/plain', () => {
-        let widget = new BaseCellWidget(new CellModel());
+        let widget = new BaseCellWidget();
         expect(widget.mimetype).to.be('text/plain');
       });
 
       it('should supporting being set to other types', () => {
-        let widget = new BaseCellWidget(new CellModel());
+        let widget = new BaseCellWidget();
         widget.mimetype = 'test/test';
         expect(widget.mimetype).to.be('test/test');
       });
 
       it('should not allow being set to empty or null strings', () => {
-        let widget = new BaseCellWidget(new CellModel());
+        let widget = new BaseCellWidget();
         widget.mimetype = null;
         expect(widget.mimetype).to.be('text/plain');
         widget.mimetype = '';
@@ -155,17 +138,17 @@ describe('jupyter-js-notebook', () => {
     describe('#readOnly', () => {
 
       it('should be a boolean', () => {
-        let widget = new BaseCellWidget(new CellModel());
+        let widget = new BaseCellWidget();
         expect(typeof widget.readOnly).to.be('boolean');
       });
 
       it('should default to false', () => {
-        let widget = new BaseCellWidget(new CellModel());
+        let widget = new BaseCellWidget();
         expect(widget.readOnly).to.be(false);
       });
 
       it('should be settable', () => {
-        let widget = new BaseCellWidget(new CellModel());
+        let widget = new BaseCellWidget();
         widget.readOnly = true;
         expect(widget.readOnly).to.be(true);
       });
@@ -175,17 +158,18 @@ describe('jupyter-js-notebook', () => {
     describe('#trusted', () => {
 
       it('should be a boolean', () => {
-        let widget = new BaseCellWidget(new CellModel());
+        let widget = new BaseCellWidget();
         expect(typeof widget.trusted).to.be('boolean');
       });
 
       it('should default to false', () => {
-        let widget = new BaseCellWidget(new CellModel());
+        let widget = new BaseCellWidget();
         expect(widget.trusted).to.be(false);
       });
 
       it('should be settable', () => {
-        let widget = new BaseCellWidget(new CellModel());
+        let widget = new BaseCellWidget();
+        widget.model = new CellModel();
         widget.trusted = true;
         expect(widget.trusted).to.be(true);
       });
@@ -195,7 +179,7 @@ describe('jupyter-js-notebook', () => {
     describe('#focus()', () => {
 
       it('should focus the cell editor', () => {
-        let widget = new BaseCellWidget(new CellModel());
+        let widget = new BaseCellWidget();
         widget.attach(document.body);
         expect(widget.editor.editor.hasFocus()).to.be(false);
         widget.focus();
@@ -208,7 +192,7 @@ describe('jupyter-js-notebook', () => {
     describe('#setPrompt()', () => {
 
       it('should not throw an error (full test in input area)', () => {
-        let widget = new BaseCellWidget(new CellModel());
+        let widget = new BaseCellWidget();
         expect(() => { widget.setPrompt(void 0); }).to.not.throwError();
         expect(() => { widget.setPrompt(null); }).to.not.throwError();
         expect(() => { widget.setPrompt(''); }).to.not.throwError();
@@ -221,7 +205,7 @@ describe('jupyter-js-notebook', () => {
     describe('#toggleInput()', () => {
 
       it('should toggle whether the input is shown', () => {
-        let widget = new BaseCellWidget(new CellModel());
+        let widget = new BaseCellWidget();
         let input = widget.node.getElementsByClassName(INPUT_CLASS)[0];
         widget.attach(document.body);
         expect(window.getComputedStyle(input).display).to.not.be('none');
@@ -236,13 +220,13 @@ describe('jupyter-js-notebook', () => {
     describe('#dispose()', () => {
 
       it('should dispose of the resources held by the widget', () => {
-        let widget = new BaseCellWidget(new CellModel());
+        let widget = new BaseCellWidget();
         widget.dispose();
         expect(widget.isDisposed).to.be(true);
       });
 
       it('should be safe to call multiple times', () => {
-        let widget = new BaseCellWidget(new CellModel());
+        let widget = new BaseCellWidget();
         widget.dispose();
         widget.dispose();
         expect(widget.isDisposed).to.be(true);
@@ -253,7 +237,7 @@ describe('jupyter-js-notebook', () => {
     describe('#onAfterAttach()', () => {
 
       it('should run when widget is attached', () => {
-        let widget = new LogCell(new CellModel());
+        let widget = new LogCell();
         expect(widget.methods).to.not.contain('onAfterAttach');
         widget.attach(document.body);
         expect(widget.methods).to.contain('onAfterAttach');
@@ -265,7 +249,7 @@ describe('jupyter-js-notebook', () => {
     describe('#onUpdateRequest()', () => {
 
       it('should update the widget', () => {
-        let widget = new LogCell(new CellModel());
+        let widget = new LogCell();
         expect(widget.methods).to.not.contain('onUpdateRequest');
         sendMessage(widget, Widget.MsgUpdateRequest);
         expect(widget.methods).to.contain('onUpdateRequest');
@@ -276,7 +260,8 @@ describe('jupyter-js-notebook', () => {
     describe('#onMetadataChanged()', () => {
 
       it('should fire when model metadata changes', () => {
-        let widget = new LogCell(new CellModel());
+        let widget = new LogCell();
+        widget.model = new CellModel();
         expect(widget.methods).to.not.contain('onMetadataChanged');
         widget.model.metadataChanged.emit({
           name: 'foo',
@@ -292,15 +277,6 @@ describe('jupyter-js-notebook', () => {
 
   describe('CodeCellWidget', () => {
 
-    describe('.createOutput()', () => {
-
-      it('should create an input area widget', () => {
-        let editor = CodeCellWidget.createInputArea(new CodeCellModel());
-        expect(editor).to.be.a(CellEditorWidget);
-      });
-
-    });
-
   });
 
 });