app-base-test.js revision a1262766ab9d2c64f7c30e87687ef2a458631203
var ArrayAssert = Y.ArrayAssert,
ObjectAssert = Y.ObjectAssert,
function resetURL() {
if (html5) {
} else {
}
}
// -- Global Suite -------------------------------------------------------------
// -- App Base Suite -----------------------------------------------------------
name: 'App Base',
setUp: function () {
resetURL();
},
tearDown: function () {
resetURL();
}
});
// -- App Base: Lifecycle ------------------------------------------------------
name: 'Lifecycle',
tearDown: function () {
delete this.app;
},
'`container` should default to the `<body>`': function () {
},
'A specified `container` should be used during construction': function () {
},
'`viewContainer` should be a new `<div/>` by default': function () {
},
'A specified `viewContainer` should be used during construction': function () {
},
'`activeView` should be undefined by default': function () {
},
'`activeView` should not be overrideable in the constructor config': function () {
activeView: new Y.View()
});
},
'`linkSelector` should be `"a"` by default': function () {
},
'`serverRouting` should default to undefined': function () {
},
'`serverRouting` should be overrideable via the constructor': function () {
serverRouting: true
});
},
'`views` property should be empty by default': function () {
},
'`views` should be a copy of the `views` object on the prototype': function () {
views: {
home: {
preserve: true
}
}
});
},
'Destroying an app with `{remove: true}` should destroy its `container` and `viewContainer`': function () {
app;
});
},
'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 () {
container : 'body',
viewContainer: 'body'
});
}
}));
// -- App Base: Attributes -----------------------------------------------------
name: 'Attributes',
setUp: function () {
},
tearDown: function () {
delete this.html5;
delete this.app;
},
'`activeView` should be read-only': function () {
},
'`activeView` should be modifiable via the `showView()` method': function () {
},
'`container` and `viewContainer` should be able to be the same node': function () {
container : 'body',
viewContainer: 'body'
});
},
'`container` should be stamped with the App CSS class': function () {
},
'`viewContainer` should be stamped with the App Views CSS class when the app is rendered': function () {
},
'`viewContainer` should only be settable during initialization': function () {
var viewContainer = new Y.View(),
},
'`serverRouting` should only be settable during initialization': function () {
},
'`serverRouting` should only be settable with a user-specified value during initialization': function () {
},
'Setting `serverRouting` to `false` should force `html5` to default to `false` in HTML5 browsers': function () {
},
'Setting `serverRouting` to `false` should force `html5` to default to `false` in non-HTML5 browsers': function () {
},
'Setting `serverRouting` to `true` should allow `html5` to default to `true` in HTML5 browsers': function () {
},
'Setting `serverRouting` to `true` should allow `html5` to default to `false` in non-HTML5 browsers': function () {
},
'Setting `serverRouting` to `undefined` should allow `html5` to default to `true` in HTML5 browsers': function () {
},
'Setting `serverRouting` to `undefined` should allow `html5` to default to `false` in non-HTML5 browsers': function () {
},
'`html5` should be overridable on construction even when `serverRouting` is false': function () {
serverRouting: false,
html5 : true
});
}
}));
// -- App Base: Events ---------------------------------------------------------
name: 'Events',
setUp: function () {
},
tearDown: function () {
resetURL();
delete this.html5;
delete this.app;
},
'`navigate` should fire when `serverRouting` is falsy, even when `html5` is `false`': function () {
eventCalls = 0,
routeCalls = 0,
test = this;
routeCalls += 1;
});
eventCalls += 1;
});
}, 200);
}
}));
// -- App Base: Methods --------------------------------------------------------
name: 'Methods',
tearDown: function () {
delete this.app;
},
'`createView()` should always return a new `Y.View` instance': function () {
},
'`createView()` should return a new instance of a named, registered view': function () {
app;
views: {
myview: {
}
}
});
},
'`createView()` should apply the specified `config` to the new `Y.View` instance': function () {
},
'`createView()` should apply the specified `config` to the new instance of a named, registered view': function () {
views: {
myview: {
}
}
});
},
'`getViewInfo()` should return the metadata for a named, registered view': function () {
var myviewInfo = {type: function () {}},
},
'`getViewInfo()` should return the metadata for a view constructed by `createView()`': function () {
},
'`render()` should append the `viewContainer` into the `container`': function () {
},
'`render()` should properly handle the `container` already containing the `viewContainer': function () {
});
},
'`render()` should properly handle the `container` and `viewContainer` being the same node': function () {
});
},
'`render()` should append the `activeView` to the `viewContainer`': function () {
// Makes sure the view isn't contained.
}
}));
// -- App Base: Views ----------------------------------------------------------
name: 'Views',
setUp: function () {
},
tearDown: function () {
delete this.app;
delete this.TestView;
delete Y.TestView;
},
'A registered view with falsy `type` should default to `Y.View`': function () {
views: {
unspecifiedView: {},
}
});
},
'A registered view with a function `type` should return an instance of that function': function () {
views: {
}
});
},
'A registered view with a string `type` should look on the `Y` object for the constructor': function () {
views: {
}
});
},
'A View instance should be preserved when registered with `preserve` as `true`': function () {
views: {
}
}),
view;
// Sets `activeView` to a new instance of the `test` registered view.
// Sets the `activeView` to something else.
// Sets the `activeView` back to the registered `test` view, which
// should be the same instance as before.
},
'A view registered with a specified `instance` should be preserved when `preserve` is `true`': function () {
views: {
test: {
preserve: true,
}
}
});
},
'A View instance should not be preserved when registered with `preserve` as `false`': function () {
views: {
}
}),
view;
// Sets `activeView` to a new instance of the `test` registered view.
// Sets the `activeView` to something else.
// Checks that the instance is not preserved.
// Sets the `activeView` back to the registered `test` view, which
// should not be the same instance as before.
},
'A registered view should not be preserved by default': function () {
views: {
test: {}
}
}),
view;
// Sets `activeView` to a new instance of the `test` registered view.
// Sets the `activeView` to something else.
// Checks that the instance is not preserved.
// Sets the `activeView` back to the registered `test` view, which
// should not be the same instance as before.
},
views: {
parent: {},
}
});
},
views: {
parent: {},
}
}),
},
'`Y.App` subclasses should be able to specify view metadata on the `prototype`': function () {
views: {
}
}),
},
'The `views` metadata on the `prototype` should be merged with the specified `views` during construction': function () {
views: {
test: {
preserve: false
},
parent: {
}
}
}),
views: {
}
});
},
'`showView()` should set the specified view instance or name as the `activeView`': function () {
views: {
}
});
},
'`showView()` should construct a registered view instance with the specified `config`': function () {
views: {
}
});
},
'`showView()` should accept a `null` `view`': function () {
},
'`showView()` should prepend the new `activeView` when `options.prepend` is `true`': function () {
},
'`options` passed to `showView()` should be mixed into the `activeViewChange` event facade': function () {
calls = 0,
options = {};
calls += 1;
});
},
'`showView()` should accept a `callback` as either the third or fourth param': function () {
calls = 0,
noop = function () {};
function callback() {
calls += 1;
}
},
'`showView()` should call the specified `callback` with `this` context': function () {
calls = 0;
calls += 1;
});
},
'`showView()` should pass the new `activeView` to the `callback`': function () {
calls = 0;
calls += 1;
});
},
'`showView()` should call the specified `callback` even when the `activeView` did not change': function () {
calls = 0;
calls += 1;
Assert.areSame(activeView, app.get('activeView'), '`activeView` and the app\'s `activeView` are not the same.');
});
},
'`activeViewChange` event should be preventable': function () {
calls = 0;
calls += 1;
e.preventDefault();
});
calls += 1;
});
},
'An `activeView` should bubble events to the app': function () {
calls = 0;
calls += 1;
});
});
},
'The previous `activeView` should no longer bubble events to the app': function () {
calls = 0;
calls += 1;
});
});
},
'A preserved view should not be destroyed when its no longer the `activeView`': function () {
var calls = 0,
views: {
test: {
preserve: true
}
}
});
calls += 1;
});
},
'A non preserved view should be destroyed when its no longer the `activeView`': function () {
var calls = 0,
views: {
test: {}
}
}),
calls += 1;
});
}
}));
// -- App Base: Navigation -----------------------------------------------------
name: 'Naivation',
_should: {
error: {
'`_save()` should throw an error when the specified URL is not of the same origin': true
}
},
setUp: function () {
},
tearDown: function () {
resetURL();
delete this.html5;
delete this.hashPrefix;
delete this.app;
},
'`_upgradeURL()` should upgrade a path-like hash-based URL to a full URL': function () {
hash = '#/foo/',
path = '/foo/',
},
'`_upgradeURL()` should not upgrade a hash-based URL which is not path-like': function () {
hash = '#foo';
},
'`_upgradeURL()` should strip any hash-prefix from the hash-based URL': function () {
hash = '/#!/foo/',
path = '/foo/',
},
'`_upgradeURL()` should not upgrade URLs of a different origin': function () {
url = 'http://random.host.example.com/#/foo/',
path = '/foo/',
},
'`navigate()` should upgrade hash-based URLs when `serverRouting` is falsy': function () {
var calls = 0,
noop = function () {},
serverRouting: false,
routes: [
]
});
calls += 1;
e.preventDefault();
});
},
'`navigate()` should upgrade hash-based URLs when `serverRouting` is `true`': function () {
// Force-fake HTML5
var calls = 0,
noop = function () {},
serverRouting: true,
routes: [
]
});
calls += 1;
e.preventDefault();
});
},
'`navigate()` should force the firing of the `navigate` event when `serverRouting` is falsy': function () {
var calls = 0,
noop = function () {},
routes: [
]
});
calls += 1;
e.preventDefault();
});
},
'`navigate()` should replace the history entry when the new and current URLs are the "same"': function () {
var calls = 0,
noop = function () {},
serverRouting: false,
routes: [
]
});
calls += 1;
e.preventDefault();
});
},
'`navigate()` should not override user-specified values for `force` and `replace`': function () {
var calls = 0,
noop = function () {},
html5 : true,
serverRouting: false,
routes: [
]
});
calls += 1;
e.preventDefault();
});
force : false,
replace: true
});
},
'`_save()` should throw an error when the specified URL is not of the same origin': function () {
calls = 0;
}
}));
}, '@VERSION@', {
});