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