OLD | NEW |
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 (function() { | 3 (function() { |
4 | 4 |
5 describe('juju environment view', function() { | 5 describe('juju environment view', function() { |
6 var views, models, Y, container, service, db, conn, | 6 var views, models, Y, container, service, db, conn, |
7 juju, env, testUtils; | 7 juju, env, testUtils; |
8 | 8 |
9 var environment_delta = { | 9 var environment_delta = { |
10 'result': [ | 10 'result': [ |
11 ['service', 'add', { | 11 ['service', 'add', { |
12 'charm': 'cs:precise/wordpress-6', | 12 'charm': 'cs:precise/wordpress-6', |
13 'id': 'wordpress', | 13 'id': 'wordpress', |
14 'exposed': false | 14 'exposed': false, |
| 15 'annotations': {'gui.x': 100, 'gui.y': 200} |
15 }], | 16 }], |
16 ['service', 'add', { | 17 ['service', 'add', { |
17 'charm': 'cs:precise/mediawiki-3', | 18 'charm': 'cs:precise/mediawiki-3', |
18 'id': 'mediawiki', | 19 'id': 'mediawiki', |
19 'exposed': false | 20 'exposed': false |
20 }], | 21 }], |
21 ['service', 'add', { | 22 ['service', 'add', { |
22 'charm': 'cs:precise/mysql-6', | 23 'charm': 'cs:precise/mysql-6', |
23 'id': 'mysql' | 24 'id': 'mysql' |
24 }], | 25 }], |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 'node-event-simulate', 'juju-gui', 'slider' | 86 'node-event-simulate', 'juju-gui', 'slider' |
86 ], function(Y) { | 87 ], function(Y) { |
87 testUtils = Y.namespace('juju-tests.utils'); | 88 testUtils = Y.namespace('juju-tests.utils'); |
88 views = Y.namespace('juju.views'); | 89 views = Y.namespace('juju.views'); |
89 models = Y.namespace('juju.models'); | 90 models = Y.namespace('juju.models'); |
90 conn = new testUtils.SocketStub(); | 91 conn = new testUtils.SocketStub(); |
91 juju = Y.namespace('juju'); | 92 juju = Y.namespace('juju'); |
92 env = new juju.Environment({conn: conn}); | 93 env = new juju.Environment({conn: conn}); |
93 env.connect(); | 94 env.connect(); |
94 conn.open(); | 95 conn.open(); |
95 env.dispatch_result(environment_delta); | |
96 done(); | 96 done(); |
97 }); | 97 }); |
98 }); | 98 }); |
99 | 99 |
100 after(function(done) { | 100 after(function(done) { |
101 env.destroy(); | 101 env.destroy(); |
102 done(); | 102 done(); |
103 }); | 103 }); |
104 | 104 |
105 beforeEach(function(done) { | 105 beforeEach(function() { |
106 container = Y.Node.create('<div />').setStyle('visibility', 'hidden'); | 106 container = Y.Node.create('<div />').setStyle('visibility', 'hidden'); |
107 Y.one('body').prepend(container); | 107 Y.one('body').prepend(container); |
108 db = new models.Database(); | 108 db = new models.Database(); |
109 db.on_delta({data: environment_delta}); | 109 // Use a clone to avoid any mutation |
110 done(); | 110 // to the input set (as happens with processed |
| 111 // annotations, its a direct reference). |
| 112 db.on_delta({data: Y.clone(environment_delta)}); |
111 }); | 113 }); |
112 | 114 |
113 afterEach(function(done) { | 115 afterEach(function(done) { |
114 container.remove(true); | 116 container.remove(true); |
115 db.destroy(); | 117 db.destroy(); |
116 env._txn_callbacks = {}; | 118 env._txn_callbacks = {}; |
117 conn.messages = []; | 119 conn.messages = []; |
118 done(); | 120 done(); |
119 }); | 121 }); |
120 | 122 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 .should.equal(true); | 391 .should.equal(true); |
390 | 392 |
391 // There should not be any duplicate nodes within the service. | 393 // There should not be any duplicate nodes within the service. |
392 serviceNode.all('.service-status').size().should.equal(1); | 394 serviceNode.all('.service-status').size().should.equal(1); |
393 serviceNode.all('.name').size().should.equal(1); | 395 serviceNode.all('.name').size().should.equal(1); |
394 serviceNode.all('.charm-label').size().should.equal(1); | 396 serviceNode.all('.charm-label').size().should.equal(1); |
395 serviceNode.all('.service-block-image').size().should.equal(1); | 397 serviceNode.all('.service-block-image').size().should.equal(1); |
396 }); | 398 }); |
397 }); | 399 }); |
398 | 400 |
| 401 it('must be able to use position annotations', |
| 402 function() { |
| 403 var view = new views.environment({ |
| 404 container: container, |
| 405 db: db, |
| 406 env: env |
| 407 }); |
| 408 var tmp_data = { |
| 409 op: 'delta', |
| 410 result: [ |
| 411 ['service', 'add', |
| 412 { |
| 413 'subordinate': true, |
| 414 'charm': 'cs:precise/wordpress-6', |
| 415 'id': 'wordpress', |
| 416 'annotations': {'gui.x': 374.1, 'gui.y': 211.2} |
| 417 }]]}; |
| 418 var properTransform = /translate\((\d+\.?\d*),(\d+\.?\d*)\)/; |
| 419 var node, match; |
| 420 |
| 421 view.render(); |
| 422 |
| 423 // Test values from initial load. |
| 424 node = view.topo.modules.ServiceModule.getServiceNode('wordpress'); |
| 425 match = node.getAttribute('transform').match(properTransform); |
| 426 match[1].should.eql('100'); |
| 427 match[2].should.eql('200'); |
| 428 |
| 429 db.on_delta({ data: tmp_data }); |
| 430 view.update(); |
| 431 |
| 432 //On annotation change position should be updated. |
| 433 match = node.getAttribute('transform').match(properTransform); |
| 434 match[1].should.eql('374.1'); |
| 435 match[2].should.eql('211.2'); |
| 436 }); |
| 437 |
399 it('must be able to render subordinate relation indicators', | 438 it('must be able to render subordinate relation indicators', |
400 function() { | 439 function() { |
401 var view = new views.environment({ | 440 var view = new views.environment({ |
402 container: container, | 441 container: container, |
403 db: db, | 442 db: db, |
404 env: env | 443 env: env |
405 }).render(); | 444 }).render(); |
406 var rel_block = container.one('.sub-rel-count').getDOMNode(); | 445 var rel_block = container.one('.sub-rel-count').getDOMNode(); |
407 | 446 |
408 // Get the contents of the subordinate relation count; YUI cannot | 447 // Get the contents of the subordinate relation count; YUI cannot |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 .target(b2) | 905 .target(b2) |
867 .model(relation); | 906 .model(relation); |
868 pair.modelIds().should.not.contain(','); | 907 pair.modelIds().should.not.contain(','); |
869 pair.modelIds().should.equal( | 908 pair.modelIds().should.equal( |
870 'service-mediawiki:app-service-haproxy:proxy'); | 909 'service-mediawiki:app-service-haproxy:proxy'); |
871 }); | 910 }); |
872 | 911 |
873 }); | 912 }); |
874 | 913 |
875 })(); | 914 })(); |
OLD | NEW |