Преглед изворни кода

More notebook test fixes.

Also, change the notebook activeCell to be undefined before the model is set or after it is disposed for consistency.
Jason Grout пре 7 година
родитељ
комит
ae892b4ccf

+ 7 - 4
packages/notebook/src/widget.ts

@@ -861,8 +861,11 @@ class Notebook extends StaticNotebook {
 
   /**
    * Get the active cell widget.
+   *
+   * #### Notes
+   * This is a cell or undefined if there is no active cell.
    */
-  get activeCell(): Cell {
+  get activeCell(): Cell | undefined {
     return this._activeCell;
   }
 
@@ -870,10 +873,10 @@ class Notebook extends StaticNotebook {
    * Dispose of the resources held by the widget.
    */
   dispose(): void {
-    if (this._activeCell === null) {
+    if (this.isDisposed) {
       return;
     }
-    this._activeCell = null;
+    this._activeCell = undefined;
     super.dispose();
   }
 
@@ -1910,7 +1913,7 @@ class Notebook extends StaticNotebook {
 
 
   private _activeCellIndex = -1;
-  private _activeCell: Cell = null;
+  private _activeCell: Cell | undefined = undefined;
   private _mode: NotebookMode = 'command';
   private _drag: Drag = null;
   private _dragData: { pressX: number, pressY: number, index: number } = null;

+ 6 - 37
tests/test-notebook/src/panel.spec.ts

@@ -48,21 +48,11 @@ describe('@jupyterlab/notebook', () => {
   describe('NotebookPanel', () => {
 
     let context: Context<INotebookModel>;
-    let manager: ServiceManager.IManager;
-  
-    before(async () => {
-      manager = new ServiceManager();
-      await manager.ready;
-    });
-  
-    after(() => {
-      manager.dispose();
-    });
-  
+
     beforeEach(async () => {
-      context = await createNotebookContext('', manager);
+      context = await createNotebookContext();
     });
-  
+
     afterEach(async () => {
       await context.session.shutdown();
       context.dispose();
@@ -128,14 +118,13 @@ describe('@jupyterlab/notebook', () => {
     describe('#dispose()', () => {
 
       it('should dispose of the resources used by the widget', () => {
-        let panel = new NotebookPanel(options);
-        panel.context = context;
+        let panel = createNotebookPanel(context);
         panel.dispose();
         expect(panel.isDisposed).to.be(true);
       });
 
       it('should be safe to call more than once', () => {
-        let panel = new NotebookPanel(options);
+        let panel = createNotebookPanel(context);
         panel.dispose();
         panel.dispose();
         expect(panel.isDisposed).to.be(true);
@@ -143,27 +132,7 @@ describe('@jupyterlab/notebook', () => {
 
     });
 
-
-    describe('#onModelStateChanged()', () => {
-
-      it('should be called when the model state changes', () => {
-        let panel = createPanel(context);
-        panel.methods = [];
-        panel.model.dirty = false;
-        expect(panel.methods).to.contain('onModelStateChanged');
-      });
-
-      it('should update the title className based on the dirty state', () => {
-        let panel = createPanel(context);
-        panel.model.dirty = true;
-        expect(panel.title.className).to.contain('jp-mod-dirty');
-        panel.model.dirty = false;
-        expect(panel.title.className).to.not.contain('jp-mod-dirty');
-      });
-
-    });
-
-    describe('.ContentFactory', () => {
+    describe.skip('.ContentFactory', () => {
       // TODO: make notebook panel still take a content factory for a notebook, and use that for a default notebook? This also moves all creation options to the notebook panel that are now just part of the content widget. That would be more backwards compatible, even if it departs a bit from our story about document widgets.
       describe('#constructor', () => {
 

+ 15 - 19
tests/test-notebook/src/tracker.spec.ts

@@ -37,22 +37,19 @@ class TestTracker extends NotebookTracker {
 }
 
 
-describe('notebook/tracker', () => {
+describe('@jupyterlab/notebook', () => {
 
-  describe('NotebookTracker', () => {
+  describe.only('NotebookTracker', () => {
 
     let context: Context<INotebookModel>;
 
-    beforeEach(() => {
-      return createNotebookContext().then(c => {
-        context = c;
-      });
+    beforeEach(async () => {
+      context = await createNotebookContext();
     });
 
-    afterEach(() => {
-      return context.session.shutdown().then(() => {
-        context.dispose();
-      });
+    afterEach(async () => {
+      await context.session.shutdown();
+      context.dispose();
     });
 
     describe('#constructor()', () => {
@@ -73,17 +70,17 @@ describe('notebook/tracker', () => {
 
       it('should be `null` if a tracked notebook has no active cell', () => {
         let tracker = new NotebookTracker({ namespace });
-        let panel = createNotebookPanel();
+        let panel = createNotebookPanel(context);
+        panel.content.model.cells.clear();
         tracker.add(panel);
         expect(tracker.activeCell).to.be(null);
       });
 
       it('should be the active cell if a tracked notebook has one', () => {
         let tracker = new NotebookTracker({ namespace });
-        let panel = createNotebookPanel();
+        let panel = createNotebookPanel(context);
         tracker.add(panel);
-        panel.context = context;
-        panel.notebook.model.fromJSON(DEFAULT_CONTENT);
+        panel.content.model.fromJSON(DEFAULT_CONTENT);
         expect(tracker.activeCell).to.be.a(Cell);
         panel.dispose();
       });
@@ -94,14 +91,13 @@ describe('notebook/tracker', () => {
 
       it('should emit a signal when the active cell changes', () => {
         let tracker = new NotebookTracker({ namespace });
-        let panel = createNotebookPanel();
+        let panel = createNotebookPanel(context);
         let count = 0;
         tracker.activeCellChanged.connect(() => { count++; });
-        panel.context = context;
-        panel.notebook.model.fromJSON(DEFAULT_CONTENT);
+        panel.content.model.fromJSON(DEFAULT_CONTENT);
         tracker.add(panel);
         expect(count).to.be(1);
-        panel.notebook.activeCellIndex = 1;
+        panel.content.activeCellIndex = 1;
         expect(count).to.be(2);
         panel.dispose();
       });
@@ -112,7 +108,7 @@ describe('notebook/tracker', () => {
 
       it('should be called when the active cell changes', () => {
         let tracker = new TestTracker({ namespace });
-        let panel = createNotebookPanel();
+        let panel = createNotebookPanel(context);
         tracker.add(panel);
         expect(tracker.methods).to.contain('onCurrentChanged');
       });