3
3
function injectData(app, data) {
4
var d = data || {'result': [['service', 'add', {'charm': 'cs:precise/wordpress-6', 'id': 'wordpress', 'exposed': false}], ['service', 'add', {'charm': 'cs:precise/mysql-6', 'id': 'mysql'}], ['relation', 'add', {'interface': 'reversenginx', 'scope': 'global', 'endpoints': [['wordpress', {'role': 'peer', 'name': 'loadbalancer'}]], 'id': 'relation-0000000000'}], ['relation', 'add', {'interface': 'mysql', 'scope': 'global', 'endpoints': [['mysql', {'role': 'server', 'name': 'db'}], ['wordpress', {'role': 'client', 'name': 'db'}]], 'id': 'relation-0000000001'}], ['machine', 'add', {'agent-state': 'running', 'instance-state': 'running', 'id': 0, 'instance-id': 'local', 'dns-name': 'localhost'}], ['unit', 'add', {'machine': 0, 'agent-state': 'started', 'public-address': '192.168.122.113', 'id': 'wordpress/0'}], ['unit', 'add', {'machine': 0, 'agent-state': 'started', 'public-address': '192.168.122.222', 'id': 'mysql/0'}]], 'op': 'delta'};
5
app.env.dispatch_result(d);
7
{'charm': 'cs:precise/wordpress-6',
8
'id': 'wordpress', 'exposed': false}],
9
['service', 'add', {'charm': 'cs:precise/mysql-6', 'id': 'mysql'}],
11
{'interface': 'reversenginx', 'scope': 'global',
12
'endpoints': [['wordpress', {'role': 'peer', 'name': 'loadbalancer'}]],
13
'id': 'relation-0000000000'}],
15
{'interface': 'mysql',
16
'scope': 'global', 'endpoints':
17
[['mysql', {'role': 'server', 'name': 'db'}],
18
['wordpress', {'role': 'client', 'name': 'db'}]],
19
'id': 'relation-0000000001'}],
21
{'agent-state': 'running', 'instance-state': 'running',
22
'id': 0, 'instance-id': 'local', 'dns-name': 'localhost'}],
24
{'machine': 0, 'agent-state': 'started',
25
'public-address': '192.168.122.113', 'id': 'wordpress/0'}],
27
{'machine': 0, 'agent-state': 'started',
28
'public-address': '192.168.122.222', 'id': 'mysql/0'}]],
30
app.env.dispatch_result(d);
9
34
describe('Application', function() {
10
35
var Y, app, container;
12
37
before(function(done) {
13
Y = YUI(GlobalConfig).use('juju-gui', function (Y) {
38
Y = YUI(GlobalConfig).use('juju-gui', function(Y) {
14
39
container = Y.Node.create('<div id="test" class="container"></div>');
15
40
app = new Y.juju.App({
16
41
container: container,
17
42
viewContainer: container
25
50
it('should produce a valid index', function() {
26
var container = app.get('container');
28
container.getAttribute('id').should.equal('test');
29
container.getAttribute('class').should.include('container');
51
var container = app.get('container');
53
container.getAttribute('id').should.equal('test');
54
container.getAttribute('class').should.include('container');
32
57
it('should be able to render the environment view with default data',
34
59
app.showView('environment', {db: app.db});
35
60
container.one('svg').should.not.equal(null);
38
63
it('should be able to route objects to internal URLs', function() {
39
// take handles to database objects and ensure we can route to the view
40
// needed to show them
41
var wordpress = app.db.services.getById('wordpress'),
42
wp0 = app.db.units.get_units_for_service(wordpress)[0],
43
wp_charm = app.db.charms.create({charm_id: wordpress.get('charm')});
45
// 'service/wordpress/' is the primary and so other URL are not returned
46
app.getModelURL(wordpress).should.equal('/service/wordpress/');
47
// however passing 'intent' can force selection of another
48
app.getModelURL(wordpress, 'config').should.equal(
49
'/service/wordpress/config');
51
// service units use argument rewriting (thus not /u/wp/0)
52
app.getModelURL(wp0).should.equal('/unit/wordpress-0/');
54
// charms also require a mapping but only a name, not a function
55
app.getModelURL(wp_charm).should.equal('/charms/' + wp_charm.get('name'));
64
// take handles to database objects and ensure we can route to the view
65
// needed to show them
66
var wordpress = app.db.services.getById('wordpress'),
67
wp0 = app.db.units.get_units_for_service(wordpress)[0],
68
wp_charm = app.db.charms.create({charm_id: wordpress.get('charm')});
70
// 'service/wordpress/' is the primary and so other URL are not returned
71
app.getModelURL(wordpress).should.equal('/service/wordpress/');
72
// however passing 'intent' can force selection of another
73
app.getModelURL(wordpress, 'config').should.equal(
74
'/service/wordpress/config');
76
// service units use argument rewriting (thus not /u/wp/0)
77
app.getModelURL(wp0).should.equal('/unit/wordpress-0/');
79
// charms also require a mapping but only a name, not a function
80
app.getModelURL(wp_charm).should.equal('/charms/' + wp_charm.get('name'));