Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added more Y.App unit tests to increase coverage to maximum.

  • Loading branch information...
commit ba1a094bc8f55643f23906fb13a0b59a7ca63619 1 parent db7877b
Eric Ferraiuolo ericf authored
Showing with 119 additions and 1 deletion.
  1. +119 −1 src/app/tests/app-base-test.js
120 src/app/tests/app-base-test.js
View
@@ -600,7 +600,7 @@ appBaseSuite.add(new Y.Test.Case({
Assert.isTrue(app.get('viewContainer').contains(view.get('container')));
},
- 'A view registered with a specified `instance` should be preserved when `preseve` is `true`': function () {
+ 'A view registered with a specified `instance` should be preserved when `preserve` is `true`': function () {
var view = new Y.View(),
app = this.app = new Y.App({
views: {
@@ -623,6 +623,80 @@ appBaseSuite.add(new Y.Test.Case({
Assert.areSame(view, app.get('activeView'));
},
+ 'A View instance should not be preserved when registered with `preserve` as `false`': function () {
+ var app = this.app = new Y.App({
+ views: {
+ test: {preserve: false}
+ }
+ }),
+ view;
+
+ Assert.isNull(app.get('activeView'));
+
+ // Sets `activeView` to a new instance of the `test` registered view.
+ app.showView('test');
+ view = app.get('activeView');
+
+ Assert.isNotNull(view);
+ Assert.isTrue(app.get('viewContainer').contains(view.get('container')));
+ Assert.areSame(view, app.getViewInfo(view).instance);
+ Assert.areSame(view, app.getViewInfo('test').instance);
+
+ // Sets the `activeView` to something else.
+ app.showView(new Y.View());
+
+ Assert.areNotSame(app.get('activeView'), view);
+ Assert.isFalse(app.get('viewContainer').contains(view.get('container')));
+
+ // Checks that the instance is not preserved.
+ Assert.isUndefined(app.getViewInfo(view));
+ Assert.isUndefined(app.getViewInfo('test').instance);
+
+ // Sets the `activeView` back to the registered `test` view, which
+ // should not be the same instance as before.
+ app.showView('test');
+
+ Assert.areNotSame(app.get('activeView'), view);
+ Assert.isFalse(app.get('viewContainer').contains(view.get('container')));
+ },
+
+ 'A registered view should not be preserved by default': function () {
+ var app = this.app = new Y.App({
+ views: {
+ test: {}
+ }
+ }),
+ view;
+
+ Assert.isNull(app.get('activeView'));
+
+ // Sets `activeView` to a new instance of the `test` registered view.
+ app.showView('test');
+ view = app.get('activeView');
+
+ Assert.isNotNull(view);
+ Assert.isTrue(app.get('viewContainer').contains(view.get('container')));
+ Assert.areSame(view, app.getViewInfo(view).instance);
+ Assert.areSame(view, app.getViewInfo('test').instance);
+
+ // Sets the `activeView` to something else.
+ app.showView(new Y.View());
+
+ Assert.areNotSame(app.get('activeView'), view);
+ Assert.isFalse(app.get('viewContainer').contains(view.get('container')));
+
+ // Checks that the instance is not preserved.
+ Assert.isUndefined(app.getViewInfo(view));
+ Assert.isUndefined(app.getViewInfo('test').instance);
+
+ // Sets the `activeView` back to the registered `test` view, which
+ // should not be the same instance as before.
+ app.showView('test');
+
+ Assert.areNotSame(app.get('activeView'), view);
+ Assert.isFalse(app.get('viewContainer').contains(view.get('container')));
+ },
+
'Parent/child view relationships should be determinable from the `views` metadata': function () {
var app = this.app = new Y.App({
views: {
@@ -829,6 +903,24 @@ appBaseSuite.add(new Y.Test.Case({
Assert.areSame(1, calls);
},
+ '`showView()` should call the specified `callback` even when the `activeView` did not change': function () {
+ var app = this.app = new Y.App(),
+ view = new Y.View(),
+ calls = 0;
+
+ app.showView(view);
+ Assert.areSame(view, app.get('activeView'), '`view` is not the `activeView`.');
+
+ app.showView(view, null, function (activeView) {
+ calls += 1;
+
+ Assert.areSame(activeView, view, '`view` and `activeView` are not the same.');
+ Assert.areSame(activeView, app.get('activeView'), '`activeView` and the app\'s `activeView` are not the same.');
+ });
+
+ Assert.areSame(1, calls, '`showView()` callback was not called.')
+ },
+
'`activeViewChange` event should be preventable': function () {
var app = this.app = new Y.App(),
calls = 0;
@@ -911,6 +1003,32 @@ appBaseSuite.add(new Y.Test.Case({
Assert.areSame(3, calls);
Assert.isTrue(view.get('destroyed'));
Assert.isFalse(testView.get('destroyed'));
+ },
+
+ 'A non preserved view should be destroyed when its no longer the `activeView`': function () {
+ var calls = 0,
+ view = new Y.View(),
+ app = this.app = new Y.App({
+ views: {
+ test: {}
+ }
+ }),
+ testView;
+
+ app.after('activeViewChange', function (e) {
+ calls += 1;
+ });
+
+ app.showView(view);
+
+ app.showView('test');
+ testView = app.get('activeView');
+
+ app.showView(null);
+
+ Assert.areSame(3, calls, '`activeView` did not change 3 times.');
+ Assert.isTrue(view.get('destroyed'), '`view` was not destoryed.');
+ Assert.isTrue(testView.get('destroyed'), '`testView` was not destroyed.');
}
}));
Please sign in to comment.
Something went wrong with that request. Please try again.