浏览代码

Merge pull request #1162 from afshin/edge-request-test-tweak

Make edge request console content widget test more robust.
Steven Silvester 8 年之前
父节点
当前提交
1e505c03cc
共有 2 个文件被更改,包括 39 次插入22 次删除
  1. 11 12
      src/console/content.ts
  2. 28 10
      test/src/console/content.spec.ts

+ 11 - 12
src/console/content.ts

@@ -359,10 +359,10 @@ class ConsoleContent extends Widget {
   /**
    * Handle an edge requested signal.
    */
-  protected onEdgeRequest(editor: ICellEditorWidget, location: EdgeLocation): void {
+  protected onEdgeRequest(editor: ICellEditorWidget, location: EdgeLocation): Promise<void> {
     let prompt = this.prompt;
     if (location === 'top') {
-      this._history.back(prompt.model.source).then(value => {
+      return this._history.back(prompt.model.source).then(value => {
         if (!value) {
           return;
         }
@@ -373,17 +373,16 @@ class ConsoleContent extends Widget {
         prompt.model.source = value;
         prompt.editor.setCursorPosition(0);
       });
-    } else {
-      this._history.forward(prompt.model.source).then(value => {
-        let text = value || this._history.placeholder;
-        if (prompt.model.source === text) {
-          return;
-        }
-        this._setByHistory = true;
-        prompt.model.source = text;
-        prompt.editor.setCursorPosition(text.length);
-      });
     }
+    return this._history.forward(prompt.model.source).then(value => {
+      let text = value || this._history.placeholder;
+      if (prompt.model.source === text) {
+        return;
+      }
+      this._setByHistory = true;
+      prompt.model.source = text;
+      prompt.editor.setCursorPosition(text.length);
+    });
   }
 
   /**

+ 28 - 10
test/src/console/content.spec.ts

@@ -49,8 +49,15 @@ import {
 
 
 class TestContent extends ConsoleContent {
+  readonly edgeRequested: ISignal<this, void>;
+
   methods: string[] = [];
 
+  dispose(): void {
+    super.dispose();
+    clearSignalData(this);
+  }
+
   protected newPrompt(): void {
     super.newPrompt();
     this.methods.push('newPrompt');
@@ -66,9 +73,11 @@ class TestContent extends ConsoleContent {
     this.methods.push('onAfterAttach');
   }
 
-  protected onEdgeRequest(editor: ICellEditorWidget, location: EdgeLocation): void {
-    super.onEdgeRequest(editor, location);
-    this.methods.push('onEdgeRequest');
+  protected onEdgeRequest(editor: ICellEditorWidget, location: EdgeLocation): Promise<void> {
+    return super.onEdgeRequest(editor, location).then(() => {
+      this.methods.push('onEdgeRequest');
+      this.edgeRequested.emit(void 0);
+    });
   }
 
   protected onTextChange(editor: ICellEditorWidget, args: ITextChange): void {
@@ -83,6 +92,9 @@ class TestContent extends ConsoleContent {
 }
 
 
+defineSignal(TestContent.prototype, 'edgeRequested');
+
+
 class TestHistory extends ConsoleHistory {
   readonly ready: ISignal<this, void>;
 
@@ -93,7 +105,6 @@ class TestHistory extends ConsoleHistory {
 
   protected onHistory(value: KernelMessage.IHistoryReplyMsg): void {
     super.onHistory(value);
-    console.log('HERE I AM');
     this.ready.emit(void 0);
   }
 }
@@ -426,22 +437,29 @@ describe('console/content', () => {
       it('should be called upon an editor edge request', done => {
         Session.startNew({ path: utils.uuid() }).then(session => {
           let history = new TestHistory({ kernel: session.kernel });
+          let code = 'print("onEdgeRequest")';
+          let force = true;
           history.ready.connect(() => {
             let widget = new TestContent({
               history, renderer, rendermime, session
             });
-            Widget.attach(widget, document.body);
-            requestAnimationFrame(() => {
-              let old = widget.prompt.model.source;
-              expect(widget.methods).to.not.contain('onEdgeRequest');
-              widget.prompt.editor.edgeRequested.emit('top');
+            widget.edgeRequested.connect(() => {
               expect(widget.methods).to.contain('onEdgeRequest');
               requestAnimationFrame(() => {
-                expect(widget.prompt.model.source).to.not.be(old);
+                expect(widget.prompt.model.source).to.be(code);
                 widget.dispose();
                 done();
               });
             });
+            Widget.attach(widget, document.body);
+            requestAnimationFrame(() => {
+              widget.prompt.model.source = code;
+              widget.execute(force).then(() => {
+                expect(widget.prompt.model.source).to.not.be(code);
+                expect(widget.methods).to.not.contain('onEdgeRequest');
+                widget.prompt.editor.edgeRequested.emit('top');
+              }).catch(done);
+            });
           });
         }).catch(done);
       });