~makyo/juju-gui/trunk

« back to all changes in this revision

Viewing changes to test/test_subapp_app_extension.js

Created app subapp extension

R=bcsaller, gary.poster
CC=
https://codereview.appspot.com/7381055

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'use strict';
 
2
 
 
3
describe('SubApplication App Extension', function() {
 
4
  var Y, juju, app, mocks, MockApp;
 
5
 
 
6
  before(function(done) {
 
7
    Y = YUI(GlobalConfig).use(['juju-routing',
 
8
                               'juju-gui', 'app-subapp-extension'],
 
9
    function(Y) {
 
10
      juju = Y.namespace('juju');
 
11
      MockApp = Y.Base.create('mock-app', Y.App,
 
12
          [Y.juju.SubAppRegistration], {});
 
13
      done();
 
14
    });
 
15
 
 
16
  });
 
17
 
 
18
  beforeEach(function() {
 
19
    app = new MockApp();
 
20
 
 
21
    Y.namespace('mock');
 
22
 
 
23
    mocks = {
 
24
      subAppRoutes: [
 
25
        { path: '/', callbacks: 'showRootView', namespace: 'charmStore' },
 
26
        { path: '/charm/:id', callbacks: 'showCharmDetailView',
 
27
          namespace: 'charmStore' }
 
28
      ],
 
29
      parentAppRoutes: [
 
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' }
 
34
      ]
 
35
    };
 
36
 
 
37
    function subAppMock() {}
 
38
    subAppMock.prototype.getSubAppRoutes = function() {
 
39
      return mocks.subAppRoutes;
 
40
    };
 
41
    subAppMock.prototype.get = function(attribute) {
 
42
      if (attribute === 'urlNamespace') { return 'charmStore'; }
 
43
    };
 
44
    Y.mock.subapp = subAppMock;
 
45
 
 
46
    mocks.subAppProperty = {
 
47
      type: Y.mock.subapp,
 
48
      config: {}
 
49
    };
 
50
  });
 
51
 
 
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');
 
57
  });
 
58
 
 
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');
 
63
  });
 
64
 
 
65
  it('should augment the parent routes with the subapp routes', function() {
 
66
    var augmentedRoutes, numberOfRoutes;
 
67
 
 
68
    numberOfRoutes = mocks.subAppRoutes.length + mocks.parentAppRoutes.length;
 
69
    app.set('routes', mocks.parentAppRoutes);
 
70
 
 
71
    augmentedRoutes = app._augmentRoutes(mocks.subAppRoutes),
 
72
 
 
73
    assert.equal(augmentedRoutes.length, numberOfRoutes,
 
74
        'Number of routes does not match');
 
75
  });
 
76
 
 
77
});