Steven Silvester 8 år sedan
förälder
incheckning
8a09825990
2 ändrade filer med 204 tillägg och 90 borttagningar
  1. 157 43
      test/src/application/shell.spec.ts
  2. 47 47
      test/src/index.ts

+ 157 - 43
test/src/application/shell.spec.ts

@@ -3,17 +3,44 @@
 
 import expect = require('expect.js');
 
+import {
+  Message
+} from 'phosphor/lib/core/messaging';
+
+import {
+  Widget
+} from 'phosphor/lib/ui/widget';
+
+import {
+  simulate
+} from 'simulate-event';
+
 import {
   ApplicationShell
 } from '../../../lib/application';
 
 
+class ContentWidget extends Widget {
+
+  activated = false;
+
+  onActivateRequest(msg: Message): void {
+    this.activated = true;
+  }
+}
+
+
 describe('ApplicationShell', () => {
 
   let shell: ApplicationShell;
 
   beforeEach(() => {
     shell = new ApplicationShell();
+    Widget.attach(shell, document.body);
+  });
+
+  afterEach(() => {
+    shell.dispose();
   });
 
   describe('#constructor()', () => {
@@ -27,7 +54,14 @@ describe('ApplicationShell', () => {
   describe('#currentWidget', () => {
 
     it('should be the current widget in the shell main area', () => {
-
+      expect(shell.currentWidget).to.be(null);
+      let widget = new Widget();
+      widget.node.tabIndex = -1;
+      widget.id = 'foo';
+      shell.addToMainArea(widget);
+      expect(shell.currentWidget).to.be(null);
+      simulate(widget.node, 'focus');
+      expect(shell.currentWidget).to.be(widget);
     });
 
   });
@@ -35,7 +69,11 @@ describe('ApplicationShell', () => {
   describe('#mainAreaIsEmpty', () => {
 
     it('should test whether the main area is empty', () => {
-
+      expect(shell.mainAreaIsEmpty).to.be(true);
+      let widget = new Widget();
+      widget.id = 'foo';
+      shell.addToMainArea(widget);
+      expect(shell.mainAreaIsEmpty).to.be(false);
     });
 
   });
@@ -43,7 +81,11 @@ describe('ApplicationShell', () => {
   describe('#topAreaIsEmpty', () => {
 
     it('should test whether the top area is empty', () => {
-
+      expect(shell.topAreaIsEmpty).to.be(true);
+      let widget = new Widget();
+      widget.id = 'foo';
+      shell.addToTopArea(widget);
+      expect(shell.topAreaIsEmpty).to.be(false);
     });
 
   });
@@ -51,7 +93,11 @@ describe('ApplicationShell', () => {
   describe('#leftAreaIsEmpty', () => {
 
     it('should test whether the left area is empty', () => {
-
+      expect(shell.leftAreaIsEmpty).to.be(true);
+      let widget = new Widget();
+      widget.id = 'foo';
+      shell.addToLeftArea(widget);
+      expect(shell.leftAreaIsEmpty).to.be(false);
     });
 
   });
@@ -59,7 +105,11 @@ describe('ApplicationShell', () => {
   describe('#rightAreaIsEmpty', () => {
 
     it('should test whether the right area is empty', () => {
-
+      expect(shell.rightAreaIsEmpty).to.be(true);
+      let widget = new Widget();
+      widget.id = 'foo';
+      shell.addToRightArea(widget);
+      expect(shell.rightAreaIsEmpty).to.be(false);
     });
 
   });
@@ -67,15 +117,23 @@ describe('ApplicationShell', () => {
   describe('#addToTopArea()', () => {
 
     it('should add a widget to the top area', () => {
-
+      let widget = new Widget();
+      widget.id = 'foo';
+      shell.addToTopArea(widget);
+      expect(shell.topAreaIsEmpty).to.be(false);
     });
 
     it('should be a no-op if the widget has no id', () => {
-
+      let widget = new Widget();
+      shell.addToTopArea(widget);
+      expect(shell.topAreaIsEmpty).to.be(true);
     });
 
     it('should accept options', () => {
-
+      let widget = new Widget();
+      widget.id = 'foo';
+      shell.addToTopArea(widget, { rank: 10 });
+      expect(shell.topAreaIsEmpty).to.be(false);
     });
 
   });
@@ -83,15 +141,23 @@ describe('ApplicationShell', () => {
   describe('#addToLeftArea()', () => {
 
     it('should add a widget to the left area', () => {
-
+      let widget = new Widget();
+      widget.id = 'foo';
+      shell.addToLeftArea(widget);
+      expect(shell.leftAreaIsEmpty).to.be(false);
     });
 
     it('should be a no-op if the widget has no id', () => {
-
+      let widget = new Widget();
+      shell.addToLeftArea(widget);
+      expect(shell.leftAreaIsEmpty).to.be(true);
     });
 
     it('should accept options', () => {
-
+      let widget = new Widget();
+      widget.id = 'foo';
+      shell.addToLeftArea(widget, { rank: 10 });
+      expect(shell.leftAreaIsEmpty).to.be(false);
     });
 
   });
@@ -99,15 +165,23 @@ describe('ApplicationShell', () => {
   describe('#addToRightArea()', () => {
 
     it('should add a widget to the right area', () => {
-
+      let widget = new Widget();
+      widget.id = 'foo';
+      shell.addToRightArea(widget);
+      expect(shell.rightAreaIsEmpty).to.be(false);
     });
 
     it('should be a no-op if the widget has no id', () => {
-
+      let widget = new Widget();
+      shell.addToRightArea(widget);
+      expect(shell.rightAreaIsEmpty).to.be(true);
     });
 
     it('should accept options', () => {
-
+      let widget = new Widget();
+      widget.id = 'foo';
+      shell.addToRightArea(widget, { rank: 10 });
+      expect(shell.rightAreaIsEmpty).to.be(false);
     });
 
   });
@@ -115,15 +189,16 @@ describe('ApplicationShell', () => {
   describe('#addToMainArea()', () => {
 
     it('should add a widget to the main area', () => {
-
+      let widget = new Widget();
+      widget.id = 'foo';
+      shell.addToMainArea(widget);
+      expect(shell.mainAreaIsEmpty).to.be(false);
     });
 
     it('should be a no-op if the widget has no id', () => {
-
-    });
-
-    it('should accept options', () => {
-
+      let widget = new Widget();
+      shell.addToMainArea(widget);
+      expect(shell.mainAreaIsEmpty).to.be(true);
     });
 
   });
@@ -131,11 +206,20 @@ describe('ApplicationShell', () => {
   describe('#activateLeft()', () => {
 
     it('should activate a widget in the left area', () => {
-
+      let widget = new Widget();
+      widget.id = 'foo';
+      shell.addToLeftArea(widget);
+      expect(widget.isVisible).to.be(false);
+      shell.activateLeft('foo');
+      expect(widget.isVisible).to.be(true);
     });
 
     it('should be a no-op if the widget is not in the left area', () => {
-
+      let widget = new Widget();
+      widget.id = 'foo';
+      expect(widget.isVisible).to.be(false);
+      shell.activateLeft('foo');
+      expect(widget.isVisible).to.be(false);
     });
 
   });
@@ -143,35 +227,45 @@ describe('ApplicationShell', () => {
   describe('#activateRight()', () => {
 
     it('should activate a widget in the right area', () => {
-
+      let widget = new Widget();
+      widget.id = 'foo';
+      shell.addToRightArea(widget);
+      expect(widget.isVisible).to.be(false);
+      shell.activateRight('foo');
+      expect(widget.isVisible).to.be(true);
     });
 
     it('should be a no-op if the widget is not in the right area', () => {
-
-    });
-
-  });
-
-  describe('#activateTop()', () => {
-
-    it('should activate a widget in the top area', () => {
-
-    });
-
-    it('should be a no-op if the widget is not in the top area', () => {
-
+      let widget = new Widget();
+      widget.id = 'foo';
+      expect(widget.isVisible).to.be(false);
+      shell.activateRight('foo');
+      expect(widget.isVisible).to.be(false);
     });
 
   });
 
   describe('#activateMain()', () => {
 
-    it('should activate a widget in the main area', () => {
-
+    it('should activate a widget in the main area', (done) => {
+      let widget = new ContentWidget();
+      widget.id = 'foo';
+      shell.addToMainArea(widget);
+      shell.activateMain('foo');
+      requestAnimationFrame(() => {
+        expect(widget.activated).to.be(true);
+        done();
+      });
     });
 
-    it('should be a no-op if the widget is not in the main area', () => {
-
+    it('should be a no-op if the widget is not in the main area', (done) => {
+      let widget = new ContentWidget();
+      widget.id = 'foo';
+      shell.activateMain('foo');
+      requestAnimationFrame(() => {
+        expect(widget.activated).to.be(false);
+        done();
+      });
     });
 
   });
@@ -179,7 +273,13 @@ describe('ApplicationShell', () => {
   describe('#collapseLeft()', () => {
 
     it('should collapse all widgets in the left area', () => {
-
+      let widget = new Widget();
+      widget.id = 'foo';
+      shell.addToLeftArea(widget);
+      shell.activateLeft('foo');
+      expect(widget.isVisible).to.be(true);
+      shell.collapseLeft();
+      expect(widget.isVisible).to.be(false);
     });
 
   });
@@ -187,7 +287,13 @@ describe('ApplicationShell', () => {
   describe('#collapseRight()', () => {
 
     it('should collapse all widgets in the right area', () => {
-
+      let widget = new Widget();
+      widget.id = 'foo';
+      shell.addToRightArea(widget);
+      shell.activateRight('foo');
+      expect(widget.isVisible).to.be(true);
+      shell.collapseRight();
+      expect(widget.isVisible).to.be(false);
     });
 
   });
@@ -195,7 +301,15 @@ describe('ApplicationShell', () => {
   describe('#closeAll()', () => {
 
     it('should close all of the widgets in the main area', () => {
-
+      let foo = new Widget();
+      foo.id = 'foo';
+      shell.addToMainArea(foo);
+      let bar = new Widget();
+      bar.id = 'bar';
+      shell.addToMainArea(bar);
+      shell.closeAll();
+      expect(foo.isAttached).to.be(false);
+      expect(bar.isAttached).to.be(false);
     });
 
   });

+ 47 - 47
test/src/index.ts

@@ -1,72 +1,72 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
-// import './application/loader.spec';
+import './application/loader.spec';
 import './application/shell.spec';
 
-// import './commandlinker/commandlinker.spec';
+import './commandlinker/commandlinker.spec';
 
-// import './common/activitymonitor.spec';
-// import './common/instancetracker.spec';
-// import './common/observablestring.spec';
-// import './common/observablevector.spec';
-// import './common/vdom.spec';
+import './common/activitymonitor.spec';
+import './common/instancetracker.spec';
+import './common/observablestring.spec';
+import './common/observablevector.spec';
+import './common/vdom.spec';
 
-// import './completer/handler.spec';
-// import './completer/model.spec';
-// import './completer/widget.spec';
+import './completer/handler.spec';
+import './completer/model.spec';
+import './completer/widget.spec';
 
-// import './console/content.spec';
-// import './console/foreign.spec';
-// import './console/history.spec';
-// import './console/panel.spec';
+import './console/content.spec';
+import './console/foreign.spec';
+import './console/history.spec';
+import './console/panel.spec';
 
-// import './csvwidget/table.spec';
-// import './csvwidget/toolbar.spec';
-// import './csvwidget/widget.spec';
+import './csvwidget/table.spec';
+import './csvwidget/toolbar.spec';
+import './csvwidget/widget.spec';
 
-// import './dialog/dialog.spec';
+import './dialog/dialog.spec';
 
-// import './docmanager/manager.spec';
-// import './docmanager/savehandler.spec';
-// import './docmanager/widgetmanager.spec';
+import './docmanager/manager.spec';
+import './docmanager/savehandler.spec';
+import './docmanager/widgetmanager.spec';
 
-// import './docregistry/context.spec';
-// import './docregistry/default.spec';
-// import './docregistry/registry.spec';
+import './docregistry/context.spec';
+import './docregistry/default.spec';
+import './docregistry/registry.spec';
 
-// import './filebrowser/crumbs.spec';
-// import './filebrowser/model.spec';
+import './filebrowser/crumbs.spec';
+import './filebrowser/model.spec';
 
-// import './inspector/inspector.spec';
+import './inspector/inspector.spec';
 
-// import './markdownwidget/widget.spec';
+import './markdownwidget/widget.spec';
 
-// import './renderers/renderers.spec';
-// import './renderers/latex.spec';
+import './renderers/renderers.spec';
+import './renderers/latex.spec';
 
-// import './rendermime/rendermime.spec';
+import './rendermime/rendermime.spec';
 
-// import './notebook/cells/editor.spec';
-// import './notebook/cells/model.spec';
-// import './notebook/cells/widget.spec';
+import './notebook/cells/editor.spec';
+import './notebook/cells/model.spec';
+import './notebook/cells/widget.spec';
 
-// import './notebook/common/undo.spec';
+import './notebook/common/undo.spec';
 
-// import './notebook/notebook/actions.spec';
-// import './notebook/notebook/default-toolbar.spec';
-// import './notebook/notebook/model.spec';
-// import './notebook/notebook/modelfactory.spec';
-// import './notebook/notebook/panel.spec';
-// import './notebook/notebook/trust.spec';
-// import './notebook/notebook/widget.spec';
-// import './notebook/notebook/widgetfactory.spec';
+import './notebook/notebook/actions.spec';
+import './notebook/notebook/default-toolbar.spec';
+import './notebook/notebook/model.spec';
+import './notebook/notebook/modelfactory.spec';
+import './notebook/notebook/panel.spec';
+import './notebook/notebook/trust.spec';
+import './notebook/notebook/widget.spec';
+import './notebook/notebook/widgetfactory.spec';
 
-// import './notebook/output-area/model.spec';
-// import './notebook/output-area/widget.spec';
+import './notebook/output-area/model.spec';
+import './notebook/output-area/widget.spec';
 
-// import './notebook/tracker.spec';
+import './notebook/tracker.spec';
 
-// import './toolbar/toolbar.spec';
+import './toolbar/toolbar.spec';
 
 import 'phosphor/styles/base.css';