Browse Source

update tests

Steven Silvester 8 years ago
parent
commit
4b6e37a11d

+ 18 - 4
test/src/docmanager/mockcontext.ts

@@ -41,8 +41,12 @@ class MockContext<T extends IDocumentModel> implements IDocumentContext<T> {
     return Private.pathChangedSignal.bind(this);
   }
 
-  get dirtyCleared(): ISignal<IDocumentContext<IDocumentModel>, void> {
-    return Private.dirtyClearedSignal.bind(this);
+  get contentsModelChanged(): ISignal<IDocumentContext<T>, IContentsModel> {
+    return Private.contentsModelChanged.bind(this);
+  }
+
+  get populated(): ISignal<IDocumentContext<IDocumentModel>, void> {
+    return Private.populatedSignal.bind(this);
   }
 
   get id(): string {
@@ -69,6 +73,10 @@ class MockContext<T extends IDocumentModel> implements IDocumentContext<T> {
     return KERNELSPECS;
   }
 
+  get isPopulated(): boolean {
+    return true;
+  }
+
   get isDisposed(): boolean {
     return this._model === null;
   }
@@ -129,8 +137,14 @@ namespace Private {
   const pathChangedSignal = new Signal<IDocumentContext<IDocumentModel>, string>();
 
   /**
-   * A signal emitted when the model is saved or reverted.
+   * A signal emitted when the context is fully populated for the first time.
+   */
+  export
+  const populatedSignal = new Signal<IDocumentContext<IDocumentModel>, void>();
+
+  /**
+   * A signal emitted when the contentsModel changes.
    */
   export
-  const dirtyClearedSignal = new Signal<IDocumentContext<IDocumentModel>, void>();
+  const contentsModelChanged = new Signal<IDocumentContext<IDocumentModel>, IContentsModel>();
 }

+ 0 - 27
test/src/docregistry/default.spec.ts

@@ -78,20 +78,6 @@ describe('docmanager/default', () => {
 
     });
 
-    describe('#beforeClose()', () => {
-
-      it('should take an action on a widget before closing it', (done) => {
-        let factory = new WidgetFactory();
-        let model = new DocumentModel();
-        let context = new MockContext(model);
-        let widget = factory.createNew(context);
-        factory.beforeClose(widget, context).then(() => {
-          done();
-        });
-      });
-
-    });
-
   });
 
   describe('Base64ModelFactory', () => {
@@ -359,19 +345,6 @@ describe('docmanager/default', () => {
 
     });
 
-    describe('#initialize()', () => {
-
-      it('should clear the dirty flag', () => {
-        let model = new DocumentModel();
-        model.fromString('foo');
-        expect(model.dirty).to.be(true);
-        model.initialize();
-        expect(model.dirty).to.be(false);
-        expect(model.toString()).to.be('foo');
-      });
-
-    });
-
   });
 
   describe('TextModelFactory', () => {

+ 0 - 15
test/src/notebook/notebook/model.spec.ts

@@ -430,21 +430,6 @@ describe('notebook/notebook', () => {
 
     });
 
-    describe('#initialize()', () => {
-
-      it('should initialize the model state', () => {
-        let model = new NotebookModel();
-        let cell = model.factory.createCodeCell();
-        model.cells.add(cell);
-        expect(model.dirty).to.be(true);
-        expect(model.cells.canUndo).to.be(true);
-        model.initialize();
-        expect(model.dirty).to.be(false);
-        expect(model.cells.canUndo).to.be(false);
-      });
-
-    });
-
     describe('#getMetadata()', () => {
 
       it('should get a metadata cursor for the notebook', () => {

+ 20 - 0
test/src/notebook/notebook/panel.spec.ts

@@ -86,6 +86,11 @@ class LogNotebookPanel extends NotebookPanel {
     super.onPathChanged(sender, path);
     this.methods.push('onPathChanged');
   }
+
+  protected onPopulated(sender: IDocumentContext<INotebookModel>, args: void): void {
+    super.onPopulated(sender, args);
+    this.methods.push('onPopulated');
+  }
 }
 
 
@@ -339,6 +344,21 @@ describe('notebook/notebook/panel', () => {
 
     });
 
+    describe('#onPopulated()', () => {
+
+      it('should initialize the model state', () => {
+        let panel = new LogNotebookPanel({ rendermime, clipboard });
+        let model = new NotebookModel();
+        model.fromJSON(DEFAULT_CONTENT);
+        expect(model.cells.canUndo).to.be(true);
+        let context = new MockContext<NotebookModel>(model);
+        panel.context = context;
+        expect(panel.methods).to.contain('onPopulated');
+        expect(model.cells.canUndo).to.be(false);
+      });
+
+    });
+
     describe('#onModelStateChanged()', () => {
 
       it('should be called when the model state changes', () => {