LEFT | RIGHT |
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 function injectData(app, data) { | 3 function injectData(app, data) { |
4 var d = data || { | 4 var d = data || { |
5 'result': [ | 5 'result': [ |
6 ['service', 'add', | 6 ['service', 'add', |
7 {'charm': 'cs:precise/wordpress-6', | 7 {'charm': 'cs:precise/wordpress-6', |
8 'id': 'wordpress', 'exposed': false}], | 8 'id': 'wordpress', 'exposed': false}], |
9 ['service', 'add', {'charm': 'cs:precise/mysql-6', 'id': 'mysql'}], | 9 ['service', 'add', {'charm': 'cs:precise/mysql-6', 'id': 'mysql'}], |
10 ['relation', 'add', | 10 ['relation', 'add', |
(...skipping 13 matching lines...) Expand all Loading... |
24 {'machine': 0, 'agent-state': 'started', | 24 {'machine': 0, 'agent-state': 'started', |
25 'public-address': '192.168.122.113', 'id': 'wordpress/0'}], | 25 'public-address': '192.168.122.113', 'id': 'wordpress/0'}], |
26 ['unit', 'add', | 26 ['unit', 'add', |
27 {'machine': 0, 'agent-state': 'started', | 27 {'machine': 0, 'agent-state': 'started', |
28 'public-address': '192.168.122.222', 'id': 'mysql/0'}]], | 28 'public-address': '192.168.122.222', 'id': 'mysql/0'}]], |
29 'op': 'delta'}; | 29 'op': 'delta'}; |
30 app.env.dispatch_result(d); | 30 app.env.dispatch_result(d); |
31 return app; | 31 return app; |
32 } | 32 } |
33 | 33 |
34 describe('Application basics', function() { | 34 YUI(GlobalConfig).use(['juju-gui', 'juju-tests-utils'], function(Y) { |
35 var Y, app, container; | 35 describe('Application basics', function() { |
36 | 36 var app, container; |
37 before(function(done) { | 37 |
38 Y = YUI(GlobalConfig).use(['juju-gui', 'juju-tests-utils'], function(Y) { | 38 beforeEach(function() { |
39 done(); | 39 container = Y.one('#main') |
40 }); | 40 .appendChild(Y.Node.create('<div/>')) |
41 }); | 41 .set('id', 'test-container') |
42 | 42 .addClass('container') |
43 beforeEach(function(done) { | 43 .append(Y.Node.create('<span/>') |
44 container = Y.one('#main') | 44 .set('id', 'environment-name')) |
45 .appendChild(Y.Node.create('<div/>')) | 45 .append(Y.Node.create('<span/>') |
46 .set('id', 'test-container') | 46 .set('id', 'provider-type')) |
47 .addClass('container') | 47 .hide(); |
48 .append(Y.Node.create('<span/>') | 48 app = new Y.juju.App( |
49 .set('id', 'environment-name')) | 49 { container: container, |
50 .append(Y.Node.create('<span/>') | 50 viewContainer: container}); |
51 .set('id', 'provider-type')) | 51 injectData(app); |
52 .hide(); | 52 }); |
53 app = new Y.juju.App( | 53 |
54 { container: container, | 54 afterEach(function() { |
55 viewContainer: container}); | 55 container.remove(true); |
56 injectData(app); | 56 }); |
57 done(); | 57 |
58 }); | 58 it('should produce a valid index', function() { |
59 | 59 var container = app.get('container'); |
60 afterEach(function() { | 60 app.render(); |
61 container.remove(true); | 61 container.getAttribute('id').should.equal('test-container'); |
62 }); | 62 container.getAttribute('class').should.include('container'); |
63 | 63 }); |
64 it('should produce a valid index', function() { | 64 |
65 var container = app.get('container'); | 65 it('should be able to route objects to internal URLs', function() { |
66 app.render(); | 66 // take handles to database objects and ensure we can route to the view |
67 container.getAttribute('id').should.equal('test-container'); | 67 // needed to show them |
68 container.getAttribute('class').should.include('container'); | 68 var wordpress = app.db.services.getById('wordpress'), |
69 }); | 69 wp0 = app.db.units.get_units_for_service(wordpress)[0], |
70 | 70 wp_charm = app.db.charms.add({id: wordpress.get('charm')}); |
71 it('should be able to route objects to internal URLs', function() { | 71 |
72 // take handles to database objects and ensure we can route to the view | 72 // 'service/wordpress/' is the primary and so other URL are not returned |
73 // needed to show them | 73 app.getModelURL(wordpress).should.equal('/service/wordpress/'); |
74 var wordpress = app.db.services.getById('wordpress'), | 74 // however passing 'intent' can force selection of another |
75 wp0 = app.db.units.get_units_for_service(wordpress)[0], | 75 app.getModelURL(wordpress, 'config').should.equal( |
76 wp_charm = app.db.charms.add({id: wordpress.get('charm')}); | 76 '/service/wordpress/config'); |
77 | 77 |
78 // 'service/wordpress/' is the primary and so other URL are not returned | 78 // service units use argument rewriting (thus not /u/wp/0) |
79 app.getModelURL(wordpress).should.equal('/service/wordpress/'); | 79 app.getModelURL(wp0).should.equal('/unit/wordpress-0/'); |
80 // however passing 'intent' can force selection of another | 80 |
81 app.getModelURL(wordpress, 'config').should.equal( | 81 // charms also require a mapping but only a name, not a function |
82 '/service/wordpress/config'); | 82 app.getModelURL(wp_charm).should.equal( |
83 | 83 '/charms/charms/precise/wordpress-6/json'); |
84 // service units use argument rewriting (thus not /u/wp/0) | 84 }); |
85 app.getModelURL(wp0).should.equal('/unit/wordpress-0/'); | 85 |
86 | 86 it('should display the configured environment name', function() { |
87 // charms also require a mapping but only a name, not a function | 87 var environment_name = 'This is the environment name. Deal with it.'; |
88 app.getModelURL(wp_charm).should.equal( | 88 app = new Y.juju.App( |
89 '/charms/charms/precise/wordpress-6/json'); | 89 { container: container, |
90 }); | 90 viewContainer: container, |
91 | 91 environment_name: environment_name}); |
92 it('should display the configured environment name', function() { | 92 assert.equal( |
93 var environment_name = 'This is the environment name. Deal with it.'; | 93 container.one('#environment-name').get('text'), |
94 app = new Y.juju.App( | 94 environment_name); |
95 { container: container, | 95 }); |
96 viewContainer: container, | 96 |
97 environment_name: environment_name}); | 97 it('should show a generic environment name if none configured', function() { |
98 assert.equal( | 98 app = new Y.juju.App( |
99 container.one('#environment-name').get('text'), | 99 { container: container, |
100 environment_name); | 100 viewContainer: container}); |
101 }); | 101 assert.equal( |
102 | 102 container.one('#environment-name').get('text'), |
103 it('should show a generic environment name if none configured', function() { | 103 'Environment'); |
104 app = new Y.juju.App( | 104 }); |
105 { container: container, | 105 |
106 viewContainer: container}); | 106 it('should show the provider type, when available', function() { |
107 assert.equal( | 107 var providerType = 'excellent provider'; |
108 container.one('#environment-name').get('text'), | 108 // Since no provider type has been set yet, none is displayed. |
109 'Environment'); | 109 assert.equal('', container.one('#provider-type').get('text')); |
110 }); | 110 app.env.set('providerType', providerType); |
111 | 111 // The provider type has been displayed. |
112 it('should show the provider type, when available', function() { | 112 assert.equal( |
113 var providerType = 'excellent provider'; | 113 'on ' + providerType, |
114 // Since no provider type has been set yet, none is displayed. | 114 container.one('#provider-type').get('text') |
115 assert.equal('', container.one('#provider-type').get('text')); | 115 ); |
116 app.env.set('providerType', providerType); | 116 }); |
117 // The provider type has been displayed. | 117 |
118 assert.equal( | |
119 'on ' + providerType, | |
120 container.one('#provider-type').get('text') | |
121 ); | |
122 }); | |
123 | |
124 }); | |
125 | |
126 | |
127 describe('Application Connection State', function() { | |
128 var Y, container; | |
129 | |
130 before(function(done) { | |
131 Y = YUI(GlobalConfig).use(['juju-gui', 'juju-tests-utils'], function(Y) { | |
132 container = Y.Node.create('<div id="test" class="container"></div>'); | |
133 done(); | |
134 }); | |
135 | |
136 }); | |
137 | |
138 it('should be able to handle env connection status changes', function() { | |
139 var juju = Y.namespace('juju'), | |
140 conn = new(Y.namespace('juju-tests.utils')).SocketStub(), | |
141 env = new juju.Environment({conn: conn}), | |
142 app = new Y.juju.App({env: env, container: container}), | |
143 reset_called = false, | |
144 noop = function() {return this;}; | |
145 | |
146 | |
147 // mock the db | |
148 app.db = { | |
149 // mock out notifications | |
150 // so app can start normally | |
151 notifications: { | |
152 addTarget: noop, | |
153 after: noop, | |
154 filter: noop, | |
155 map: noop, | |
156 on: noop, | |
157 size: function() {return 0;} | |
158 }, | |
159 reset: function() { | |
160 reset_called = true; | |
161 } | |
162 }; | |
163 env.connect(); | |
164 conn.open(); | |
165 reset_called.should.equal(true); | |
166 | |
167 // trigger a second time and verify | |
168 reset_called = false; | |
169 conn.open(); | |
170 reset_called.should.equal(true); | |
171 }); | |
172 | |
173 }); | |
174 | |
175 describe('Application prefetching', function() { | |
176 var Y, models, conn, env, app, container, charm_store, data, juju; | |
177 | |
178 before(function(done) { | |
179 Y = YUI(GlobalConfig).use( | |
180 'juju-models', 'juju-gui', 'datasource-local', 'juju-tests-utils', | |
181 'json-stringify', | |
182 function(Y) { | |
183 models = Y.namespace('juju.models'); | |
184 done(); | |
185 }); | |
186 }); | |
187 | |
188 beforeEach(function() { | |
189 conn = new (Y.namespace('juju-tests.utils')).SocketStub(), | |
190 env = new Y.juju.Environment({conn: conn}); | |
191 env.connect(); | |
192 conn.open(); | |
193 container = Y.Node.create('<div id="test" class="container"></div>'); | |
194 data = []; | |
195 app = new Y.juju.App( | |
196 { container: container, | |
197 viewContainer: container, | |
198 env: env, | |
199 charm_store: {} }); | |
200 | |
201 app.updateEndpoints = function() {}; | |
202 env.get_endpoints = function() {}; | |
203 }); | |
204 | |
205 afterEach(function() { | |
206 container.destroy(); | |
207 app.destroy(); | |
208 }); | |
209 | |
210 it('must prefetch charm and service for service pages', function() { | |
211 injectData(app); | |
212 var _ = expect( | |
213 app.db.charms.getById('cs:precise/wordpress-6')).to.not.exist; | |
214 app.show_service({params: {id: 'wordpress'}, query: {}}); | |
215 // The app made a request of juju for the service info. | |
216 conn.messages[conn.messages.length - 2].op.should.equal('get_service'); | |
217 // The app also requested juju (not the charm store--see discussion in | |
218 // app/models/charm.js) for the charm info. | |
219 conn.last_message().op.should.equal('get_charm'); | |
220 // Tests of the actual load machinery are in the model and env tests, and | |
221 // so are not repeated here. | |
222 }); | 118 }); |
223 }); | 119 }); |
| 120 |
| 121 YUI(GlobalConfig).use(['juju-gui', 'juju-tests-utils'], function(Y) { |
| 122 describe('Application Connection State', function() { |
| 123 var container; |
| 124 |
| 125 before(function() { |
| 126 container = Y.Node.create('<div id="test" class="container"></div>'); |
| 127 }); |
| 128 |
| 129 it('should be able to handle env connection status changes', function() { |
| 130 var juju = Y.namespace('juju'), |
| 131 conn = new(Y.namespace('juju-tests.utils')).SocketStub(), |
| 132 env = new juju.Environment({conn: conn}), |
| 133 app = new Y.juju.App({env: env, container: container}), |
| 134 reset_called = false, |
| 135 noop = function() {return this;}; |
| 136 |
| 137 |
| 138 // mock the db |
| 139 app.db = { |
| 140 // mock out notifications |
| 141 // so app can start normally |
| 142 notifications: { |
| 143 addTarget: noop, |
| 144 after: noop, |
| 145 filter: noop, |
| 146 map: noop, |
| 147 on: noop, |
| 148 size: function() {return 0;} |
| 149 }, |
| 150 reset: function() { |
| 151 reset_called = true; |
| 152 } |
| 153 }; |
| 154 env.connect(); |
| 155 conn.open(); |
| 156 reset_called.should.equal(true); |
| 157 |
| 158 // trigger a second time and verify |
| 159 reset_called = false; |
| 160 conn.open(); |
| 161 reset_called.should.equal(true); |
| 162 }); |
| 163 |
| 164 }); |
| 165 }); |
| 166 |
| 167 YUI(GlobalConfig).use(['juju-models', 'juju-gui', 'datasource-local', |
| 168 'juju-tests-utils', 'json-stringify'], function(Y) { |
| 169 describe('Application prefetching', function() { |
| 170 var models, conn, env, app, container, charm_store, data, juju; |
| 171 |
| 172 before(function() { |
| 173 models = Y.namespace('juju.models'); |
| 174 }); |
| 175 |
| 176 beforeEach(function() { |
| 177 conn = new (Y.namespace('juju-tests.utils')).SocketStub(), |
| 178 env = new Y.juju.Environment({conn: conn}); |
| 179 env.connect(); |
| 180 conn.open(); |
| 181 container = Y.Node.create('<div id="test" class="container"></div>'); |
| 182 data = []; |
| 183 app = new Y.juju.App( |
| 184 { container: container, |
| 185 viewContainer: container, |
| 186 env: env, |
| 187 charm_store: {} }); |
| 188 |
| 189 app.updateEndpoints = function() {}; |
| 190 env.get_endpoints = function() {}; |
| 191 }); |
| 192 |
| 193 afterEach(function() { |
| 194 container.destroy(); |
| 195 app.destroy(); |
| 196 }); |
| 197 |
| 198 it('must prefetch charm and service for service pages', function() { |
| 199 injectData(app); |
| 200 var _ = expect( |
| 201 app.db.charms.getById('cs:precise/wordpress-6')).to.not.exist; |
| 202 app.show_service({params: {id: 'wordpress'}, query: {}}); |
| 203 // The app made a request of juju for the service info. |
| 204 conn.messages[conn.messages.length - 2].op.should.equal('get_service'); |
| 205 // The app also requested juju (not the charm store--see discussion in |
| 206 // app/models/charm.js) for the charm info. |
| 207 conn.last_message().op.should.equal('get_charm'); |
| 208 // Tests of the actual load machinery are in the model and env tests, and |
| 209 // so are not repeated here. |
| 210 }); |
| 211 }); |
| 212 }); |
LEFT | RIGHT |