3
describe('SubApplication App Extension', function() {
4
var Y, juju, app, mocks, MockApp;
6
before(function(done) {
7
Y = YUI(GlobalConfig).use(['juju-routing',
8
'juju-gui', 'app-subapp-extension'],
10
juju = Y.namespace('juju');
11
MockApp = Y.Base.create('mock-app', Y.App,
12
[Y.juju.SubAppRegistration], {});
18
beforeEach(function() {
25
{ path: '/', callbacks: 'showRootView', namespace: 'charmStore' },
26
{ path: '/charm/:id', callbacks: 'showCharmDetailView',
27
namespace: 'charmStore' }
30
{ path: '*', callbacks: 'check_user_credentials' },
31
{ path: '*', callbacks: 'show_notifications_view' },
32
{ path: '/charms/', callbacks: 'show_charm_collection' },
33
{ path: '/charms/*charm_store_path/', callbacks: 'show_charm' }
37
function subAppMock() {}
38
subAppMock.prototype.getSubAppRoutes = function() {
39
return mocks.subAppRoutes;
41
subAppMock.prototype.get = function(attribute) {
42
if (attribute === 'urlNamespace') { return 'charmStore'; }
44
Y.mock.subapp = subAppMock;
46
mocks.subAppProperty = {
52
it('should add subapps to the parent app', function() {
53
app.set('routes', mocks.parentAppRoutes);
54
app.addSubApp(mocks.subAppProperty.type, mocks.subAppProperty.config);
55
var subapps = app.get('subApps');
56
assert(typeof subapps.charmStore === 'object');
59
it('should extract the routes from the subapp', function() {
60
app.set('subApps', [new Y.mock.subapp()]);
61
assert.deepEqual(app._extractRoutes(), mocks.subAppRoutes,
62
'Routes do not match');
65
it('should augment the parent routes with the subapp routes', function() {
66
var augmentedRoutes, numberOfRoutes;
68
numberOfRoutes = mocks.subAppRoutes.length + mocks.parentAppRoutes.length;
69
app.set('routes', mocks.parentAppRoutes);
71
augmentedRoutes = app._augmentRoutes(mocks.subAppRoutes),
73
assert.equal(augmentedRoutes.length, numberOfRoutes,
74
'Number of routes does not match');