23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo originalURL = (win && win.location.toString()) || '',
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo win && win.history.replaceState(null, null, originalURL);
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo// -- Global Suite -------------------------------------------------------------
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolosuite = Y.AppTestSuite || (Y.AppTestSuite = new Y.Test.Suite('App Framework'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo// -- App Base Suite -----------------------------------------------------------
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo setUp: function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo tearDown: function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo// -- App Base: Lifecycle ------------------------------------------------------
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo tearDown: function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`container` should default to the `<body>`': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(Y.one('body'), app.get('container'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo 'A specified `container` should be used during construction': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo app = this.app = new Y.App({container: container});
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(container, app.get('container'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`viewContainer` should be a new `<div/>` by default': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app.get('viewContainer').test('div'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo 'A specified `viewContainer` should be used during construction': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo var viewContainer = Y.Node.create('<div/>'),
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo app = this.app = new Y.App({viewContainer: viewContainer});
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(viewContainer, app.get('viewContainer'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`activeView` should be undefined by default': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(null, app.get('activeView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`activeView` should not be overrideable in the constructor config': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(null, app.get('activeView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`linkSelector` should be `"a"` by default': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame('a', app.get('linkSelector'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`serverRouting` should default to undefined': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(undefined, app.get('serverRouting'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`serverRouting` should be overrideable via the constructor': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(true, app.get('serverRouting'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`views` property should be empty by default': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`views` should be a copy of the `views` object on the prototype': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isFalse(app.views === MyApp.prototype.views);
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isFalse(Y.Object.isEmpty(app.views));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(app.views.home.preserve, MyApp.prototype.views.home.preserve);
da3fe82a6733256f64c8351879bba6730371b972Ryan Grove 'Destroying an app with `{remove: true}` should destroy its `container` and `viewContainer`': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo app.render().get('container').appendTo('body');
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(container, app.get('container'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(viewContainer, app.get('viewContainer'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(container.inDoc(Y.config.doc));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(Y.one('body').contains(container));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(viewContainer.inDoc(Y.config.doc));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(Y.one('body').contains(viewContainer));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(container.contains(viewContainer));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isFalse(Y.one('body').contains(container));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isFalse(container.inDoc(Y.config.doc));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isFalse(container.contains(viewContainer));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isFalse(Y.one('body').contains(viewContainer));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isFalse(viewContainer.inDoc(Y.config.doc));
da3fe82a6733256f64c8351879bba6730371b972Ryan Grove 'Destroying an app with `{remove: true}` with the `<body>` for a container should only remove its CSS classes, not the body from the DOM': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(Y.one('body').compareTo(app.get('container')));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(Y.one('body').inDoc(Y.config.doc));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isFalse(Y.one('body').hasClass(Y.App.Base.CSS_CLASS));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isFalse(Y.one('body').hasClass(Y.App.Base.VIEWS_CSS_CLASS));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo// -- App Base: Attributes -----------------------------------------------------
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo setUp: function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo tearDown: function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`activeView` should be read-only': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(null, app.get('activeView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(null, app.get('activeView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`activeView` should be modifiable via the `showView()` method': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(null, app.get('activeView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(view, app.get('activeView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`container` and `viewContainer` should be able to be the same node': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(Y.one('body'), app.get('container'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(Y.one('body'), app.get('viewContainer'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(app.get('container'), app.get('viewContainer'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app.get('container').compareTo(app.get('viewContainer')));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`container` should be stamped with the App CSS class': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app.get('container').hasClass(Y.App.Base.CSS_CLASS));
a1262766ab9d2c64f7c30e87687ef2a458631203Ryan Grove '`viewContainer` should be stamped with the App Views CSS class when the app is rendered': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app.get('viewContainer').hasClass(Y.App.Base.VIEWS_CSS_CLASS));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`viewContainer` should only be settable during initialization': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areNotSame(viewContainer, app.get('viewContainer'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`serverRouting` should only be settable during initialization': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(undefined, app.get('serverRouting'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(undefined, app.get('serverRouting'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`serverRouting` should only be settable with a user-specified value during initialization': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo var app = this.app = new Y.App({serverRouting: true});
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(true, app.get('serverRouting'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(true, app.get('serverRouting'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo 'Setting `serverRouting` to `false` should force `html5` to default to `false` in HTML5 browsers': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo var app = this.app = new Y.App({serverRouting: false});
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(false, app.get('serverRouting'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo 'Setting `serverRouting` to `false` should force `html5` to default to `false` in non-HTML5 browsers': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo var app = this.app = new Y.App({serverRouting: false});
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(false, app.get('serverRouting'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo 'Setting `serverRouting` to `true` should allow `html5` to default to `true` in HTML5 browsers': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo var app = this.app = new Y.App({serverRouting: true});
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(true, app.get('serverRouting'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo 'Setting `serverRouting` to `true` should allow `html5` to default to `false` in non-HTML5 browsers': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo var app = this.app = new Y.App({serverRouting: true});
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(true, app.get('serverRouting'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo 'Setting `serverRouting` to `undefined` should allow `html5` to default to `true` in HTML5 browsers': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo var app = this.app = new Y.App({serverRouting: undefined});
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(undefined, app.get('serverRouting'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo 'Setting `serverRouting` to `undefined` should allow `html5` to default to `false` in non-HTML5 browsers': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo var app = this.app = new Y.App({serverRouting: undefined});
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(undefined, app.get('serverRouting'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`html5` should be overridable on construction even when `serverRouting` is false': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(false, app.get('serverRouting'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo// -- App Base: Events ---------------------------------------------------------
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo setUp: function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo tearDown: function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`navigate` should fire when `serverRouting` is falsy, even when `html5` is `false`': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(1, eventCalls, 'Event should fire once.');
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(1, routeCalls, 'Route should dispatch once.');
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo// -- App Base: Methods --------------------------------------------------------
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo tearDown: function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`createView()` should always return a new `Y.View` instance': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isInstanceOf(Y.View, app.createView());
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`createView()` should return a new instance of a named, registered view': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo var MyView = Y.Base.create('myView', Y.View, []),
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isInstanceOf(MyView, app.createView('myview'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`createView()` should apply the specified `config` to the new `Y.View` instance': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo view = app.createView(null, {container: container});
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(container, view.get('container'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`createView()` should apply the specified `config` to the new instance of a named, registered view': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo var MyView = Y.Base.create('myView', Y.View, []),
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo view = app.createView('myview', {container: container});
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(container, view.get('container'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`getViewInfo()` should return the metadata for a named, registered view': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo app = this.app = new Y.App({views: {myview: myviewInfo}});
091fd26b4b1680660e7fc48e1a45f9f52f9c0239Eric Ferraiuolo Assert.areSame(myviewInfo.type, app.getViewInfo('myview').type);
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`getViewInfo()` should return the metadata for a view constructed by `createView()`': function () {
091fd26b4b1680660e7fc48e1a45f9f52f9c0239Eric Ferraiuolo var TestView = Y.Base.create('testView', Y.View, []),
091fd26b4b1680660e7fc48e1a45f9f52f9c0239Eric Ferraiuolo app = this.app = new Y.App({views: {myview: {type: TestView}}}),
091fd26b4b1680660e7fc48e1a45f9f52f9c0239Eric Ferraiuolo Assert.areSame(app.views.myview, app.getViewInfo(view));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`render()` should append the `viewContainer` into the `container`': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isFalse(container.contains(viewContainer));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(container.contains(viewContainer));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`render()` should properly handle the `container` already containing the `viewContainer': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(container.contains(viewContainer));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(container.contains(viewContainer));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`render()` should properly handle the `container` and `viewContainer` being the same node': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(node, app.get('viewContainer'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app.get('container').compareTo(app.get('viewContainer')));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app.get('container').compareTo(app.get('viewContainer')));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`render()` should append the `activeView` to the `viewContainer`': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // Makes sure the view isn't contained.
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isFalse(app.get('viewContainer').contains(view.get('container')));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(view, app.get('activeView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app.get('viewContainer').contains(view.get('container')));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo// -- App Base: Views ----------------------------------------------------------
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo setUp: function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo this.TestView = Y.TestView = Y.Base.create('testView', Y.View, []);
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo tearDown: function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo 'A registered view with falsy `type` should default to `Y.View`': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isInstanceOf(Y.View, app.createView('unspecifiedView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isInstanceOf(Y.View, app.createView('undefinedView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isInstanceOf(Y.View, app.createView('nullView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isInstanceOf(Y.View, app.createView('falseView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isInstanceOf(Y.View, app.createView('zeroView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isInstanceOf(Y.View, app.createView('nanView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo 'A registered view with a function `type` should return an instance of that function': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isInstanceOf(Y.View, app.createView('test'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isInstanceOf(this.TestView, app.createView('test'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo 'A registered view with a string `type` should look on the `Y` object for the constructor': function () {
3b9ae81d79bb89b03617ad79cbc4753708e4e78cEric Ferraiuolo Y.namespace('Foo.Bar').View = Y.Base.create('fooTestView', Y.View, []);
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isInstanceOf(Y.View, app.createView('test'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isInstanceOf(Y.TestView, app.createView('test'));
3b9ae81d79bb89b03617ad79cbc4753708e4e78cEric Ferraiuolo Assert.isInstanceOf(Y.View, app.createView('bigNamespace'));
3b9ae81d79bb89b03617ad79cbc4753708e4e78cEric Ferraiuolo Assert.isInstanceOf(Y.Foo.Bar.View, app.createView('bigNamespace'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo 'A View instance should be preserved when registered with `preserve` as `true`': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // Sets `activeView` to a new instance of the `test` registered view.
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app.get('viewContainer').contains(view.get('container')));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // Sets the `activeView` to something else.
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areNotSame(app.get('activeView'), view);
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isFalse(app.get('viewContainer').contains(view.get('container')));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // Sets the `activeView` back to the registered `test` view, which
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // should be the same instance as before.
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(app.get('activeView'), view);
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app.get('viewContainer').contains(view.get('container')));
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo 'A view registered with a specified `instance` should be preserved when `preserve` is `true`': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(view, app.get('activeView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areNotSame(view, app.get('activeView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(view, app.get('activeView'));
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo 'A View instance should not be preserved when registered with `preserve` as `false`': function () {
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo // Sets `activeView` to a new instance of the `test` registered view.
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.isTrue(app.get('viewContainer').contains(view.get('container')));
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.areSame(view, app.getViewInfo(view).instance);
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.areSame(view, app.getViewInfo('test').instance);
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo // Sets the `activeView` to something else.
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.areNotSame(app.get('activeView'), view);
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.isFalse(app.get('viewContainer').contains(view.get('container')));
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo // Checks that the instance is not preserved.
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.isUndefined(app.getViewInfo('test').instance);
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo // Sets the `activeView` back to the registered `test` view, which
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo // should not be the same instance as before.
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.areNotSame(app.get('activeView'), view);
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.isFalse(app.get('viewContainer').contains(view.get('container')));
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo 'A registered view should not be preserved by default': function () {
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo // Sets `activeView` to a new instance of the `test` registered view.
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.isTrue(app.get('viewContainer').contains(view.get('container')));
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.areSame(view, app.getViewInfo(view).instance);
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.areSame(view, app.getViewInfo('test').instance);
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo // Sets the `activeView` to something else.
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.areNotSame(app.get('activeView'), view);
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.isFalse(app.get('viewContainer').contains(view.get('container')));
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo // Checks that the instance is not preserved.
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.isUndefined(app.getViewInfo('test').instance);
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo // Sets the `activeView` back to the registered `test` view, which
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo // should not be the same instance as before.
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.areNotSame(app.get('activeView'), view);
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.isFalse(app.get('viewContainer').contains(view.get('container')));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo 'Parent/child view relationships should be determinable from the `views` metadata': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app._isParentView('parent', 'child'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isFalse(app._isParentView('child', 'parent'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app._isChildView('child', 'parent'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isFalse(app._isChildView('parent', 'child'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo 'Parent/child view relationships should be determinable from view instances': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app._isParentView(parent, child));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app._isParentView(parent, 'child'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app._isParentView('parent', child));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app._isChildView(child, parent));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app._isChildView(child, 'parent'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app._isChildView('child', parent));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`Y.App` subclasses should be able to specify view metadata on the `prototype`': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo var MyApp = Y.Base.create('myApp', Y.App, [], {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isFalse(Y.Object.isEmpty(app.views));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isInstanceOf(this.TestView, app.createView('test'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo 'The `views` metadata on the `prototype` should be merged with the specified `views` during construction': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo var MyApp = Y.Base.create('myApp', Y.App, [], {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo ObjectAssert.hasKeys(['test', 'parent', 'child'], app.views);
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(this.TestView, app.views.test.type);
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(Y.View, app.views.parent.type);
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame('parent', app.views.child.parent);
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app._isParentView('parent', 'child'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app._isChildView('child', 'parent'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`showView()` should set the specified view instance or name as the `activeView`': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(view, app.get('activeView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isInstanceOf(this.TestView, app.get('activeView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(app.views.test, app.getViewInfo(app.get('activeView')));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`showView()` should construct a registered view instance with the specified `config`': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isInstanceOf(this.TestView, app.get('activeView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(node, app.get('activeView').get('container'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`showView()` should accept a `null` `view`': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(1, app.get('viewContainer').get('children').size());
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(0, app.get('viewContainer').get('children').size());
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`showView()` should prepend the new `activeView` when `options.prepend` is `true`': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isInstanceOf(Y.View, app.get('activeView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(view, app.get('activeView'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app.get('viewContainer').contains(view.get('container')));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(2, app.get('viewContainer').get('children').size());
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(app.get('viewContainer').get('firstChild'), view.get('container'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`options` passed to `showView()` should be mixed into the `activeViewChange` event facade': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo app.after('activeViewChange', function (e) {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`showView()` should accept a `callback` as either the third or fourth param': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo noop = function () {};
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo app.showView(new Y.View(), null, null, callback);
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo app.showView(new Y.View(), null, noop, callback);
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`showView()` should call the specified `callback` with `this` context': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo app.showView(new Y.View(), null, function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`showView()` should pass the new `activeView` to the `callback`': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo app.showView(view, null, function (activeView) {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(activeView, app.get('activeView'));
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo '`showView()` should call the specified `callback` even when the `activeView` did not change': function () {
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.areSame(view, app.get('activeView'), '`view` is not the `activeView`.');
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo app.showView(view, null, function (activeView) {
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.areSame(activeView, view, '`view` and `activeView` are not the same.');
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.areSame(activeView, app.get('activeView'), '`activeView` and the app\'s `activeView` are not the same.');
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.areSame(1, calls, '`showView()` callback was not called.')
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`activeViewChange` event should be preventable': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo app.after('activeViewChange', function (e) {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo 'An `activeView` should bubble events to the app': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo app.showView(new Y.View(), null, function (view) {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo 'The previous `activeView` should no longer bubble events to the app': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isTrue(app.get('viewContainer').contains(view.get('container')));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo app.after('activeViewChange', function (e) {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.isFalse(app.get('viewContainer').contains(view.get('container')));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo 'A preserved view should not be destroyed when its no longer the `activeView`': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo app.after('activeViewChange', function (e) {
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo 'A non preserved view should be destroyed when its no longer the `activeView`': function () {
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo app.after('activeViewChange', function (e) {
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.areSame(3, calls, '`activeView` did not change 3 times.');
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.isTrue(view.get('destroyed'), '`view` was not destoryed.');
ba1a094bc8f55643f23906fb13a0b59a7ca63619Eric Ferraiuolo Assert.isTrue(testView.get('destroyed'), '`testView` was not destroyed.');
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo// -- App Base: Navigation -----------------------------------------------------
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`_save()` should throw an error when the specified URL is not of the same origin': true
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo setUp: function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo tearDown: function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`_upgradeURL()` should upgrade a path-like hash-based URL to a full URL': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areNotSame(hash, app._upgradeURL(hash));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`_upgradeURL()` should not upgrade a hash-based URL which is not path-like': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(hash, app._upgradeURL(hash));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`_upgradeURL()` should strip any hash-prefix from the hash-based URL': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areNotSame(hash, app._upgradeURL(hash));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`_upgradeURL()` should not upgrade URLs of a different origin': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo url = 'http://random.host.example.com/#/foo/',
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areNotSame(resolvedURL, upgradedURL);
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`navigate()` should upgrade hash-based URLs when `serverRouting` is falsy': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo noop = function () {},
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(e.url, this._resolveURL('/foo/'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`navigate()` should upgrade hash-based URLs when `serverRouting` is `true`': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // Force-fake HTML5
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo noop = function () {},
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(e.url, this._resolveURL('/foo/'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`navigate()` should force the firing of the `navigate` event when `serverRouting` is falsy': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo noop = function () {},
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`navigate()` should replace the history entry when the new and current URLs are the "same"': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo noop = function () {},
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areSame(e.url, this._upgradeURL(this._getURL()));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`navigate()` should not override user-specified values for `force` and `replace`': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo noop = function () {},
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo Assert.areNotSame(e.url, this._upgradeURL(this._getURL()));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo '`_save()` should throw an error when the specified URL is not of the same origin': function () {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo var app = this.app = new Y.App({serverRouting: true}),
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo app._save('http://some.random.host.example.com/foo/bar/');
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo}, '@VERSION@', {