浏览代码

Clean up dialog handling

Steven Silvester 8 年之前
父节点
当前提交
29d9dd4049
共有 2 个文件被更改,包括 18 次插入19 次删除
  1. 13 0
      packages/apputils/src/dialog.ts
  2. 5 19
      test/src/apputils/dialog.spec.ts

+ 13 - 0
packages/apputils/src/dialog.ts

@@ -82,6 +82,19 @@ class Dialog extends Widget {
     content.addWidget(footer);
   }
 
+  /**
+   * Dispose of the resources used by the dialog.
+   */
+  dispose(): void {
+    if (this._promise) {
+      let promise = this._promise;
+      this._promise = null;
+      promise.resolve(void 0);
+      ArrayExt.removeFirstOf(Private.launchQueue, promise.promise);
+    }
+    super.dispose();
+  }
+
   /**
    * Launch the dialog as a modal window.
    *

+ 5 - 19
test/src/apputils/dialog.spec.ts

@@ -29,23 +29,9 @@ import {
   Dialog, showDialog
 } from '@jupyterlab/apputils';
 
-
-/**
- * Accept a dialog.
- */
-function acceptDialog(host: HTMLElement = document.body): void {
-  let node = host.getElementsByClassName('jp-Dialog')[0];
-  simulate(node as HTMLElement, 'keydown', { keyCode: 13 });
-}
-
-
-/**
- * Reject a dialog.
- */
-function rejectDialog(host: HTMLElement = document.body): void {
-  let node = host.getElementsByClassName('jp-Dialog')[0];
-  simulate(node as HTMLElement, 'keydown', { keyCode: 27 });
-}
+import {
+  acceptDialog, dismissDialog
+} from '../utils';
 
 
 class TestDialog extends Dialog {
@@ -82,7 +68,7 @@ describe('@jupyterlab/domutils', () => {
       let promise = showDialog().then(result => {
         expect(result.accept).to.equal(false);
       });
-      rejectDialog();
+      dismissDialog();
       return promise;
     });
 
@@ -98,7 +84,7 @@ describe('@jupyterlab/domutils', () => {
       let promise = showDialog(options).then(result => {
         expect(result.accept).to.equal(false);
       });
-      rejectDialog();
+      dismissDialog();
       return promise;
     });