|
@@ -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);
|
|
|
});
|
|
|
|
|
|
});
|