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