Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(237)

Side by Side Diff: test/test_model.js

Issue 13373050: Adds relation details viewlet to inspector
Patch Set: Adds relation details viewlet to inspector Created 11 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/test_fakebackend.js ('k') | test/test_model_handlers.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 This file is part of the Juju GUI, which lets users view and manage Juju 2 This file is part of the Juju GUI, which lets users view and manage Juju
3 environments within a graphical interface (https://launchpad.net/juju-gui). 3 environments within a graphical interface (https://launchpad.net/juju-gui).
4 Copyright (C) 2012-2013 Canonical Ltd. 4 Copyright (C) 2012-2013 Canonical Ltd.
5 5
6 This program is free software: you can redistribute it and/or modify it under 6 This program is free software: you can redistribute it and/or modify it under
7 the terms of the GNU Affero General Public License version 3, as published by 7 the terms of the GNU Affero General Public License version 3, as published by
8 the Free Software Foundation. 8 the Free Software Foundation.
9 9
10 This program is distributed in the hope that it will be useful, but WITHOUT 10 This program is distributed in the hope that it will be useful, but WITHOUT
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 it('must convert timestamps into time objects on BrowserCharm', function() { 85 it('must convert timestamps into time objects on BrowserCharm', function() {
86 var time = 1349797266.032, 86 var time = 1349797266.032,
87 date = new Date(time), 87 date = new Date(time),
88 charm = new models.BrowserCharm( 88 charm = new models.BrowserCharm(
89 { id: 'cs:precise/foo-9', last_change: {created: time / 1000} }); 89 { id: 'cs:precise/foo-9', last_change: {created: time / 1000} });
90 charm.get('last_change').created.should.eql(date); 90 charm.get('last_change').created.should.eql(date);
91 }); 91 });
92 }); 92 });
93 93
94 describe('juju models', function() { 94 describe('juju models', function() {
95 var models; 95 var models, yui;
96 96
97 before(function(done) { 97 before(function(done) {
98 YUI(GlobalConfig).use('juju-models', 'juju-charm-models', function(Y) { 98 YUI(GlobalConfig).use('juju-models', 'juju-charm-models', function(Y) {
99 models = Y.namespace('juju.models'); 99 models = Y.namespace('juju.models');
100 yui = Y;
100 done(); 101 done();
101 }); 102 });
102 }); 103 });
103 104
104 beforeEach(function() { 105 beforeEach(function() {
105 window._gaq = []; 106 window._gaq = [];
106 }); 107 });
107 108
108 it('service unit list should be able to get units of a given service', 109 it('service unit list should be able to get units of a given service',
109 function() { 110 function() {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 sul.add([my0, my1]); 147 sul.add([my0, my1]);
147 148
148 var wp0 = new models.ServiceUnit({ 149 var wp0 = new models.ServiceUnit({
149 id: 'wordpress/0', 150 id: 'wordpress/0',
150 agent_state: 'pending'}); 151 agent_state: 'pending'});
151 var wp1 = new models.ServiceUnit({ 152 var wp1 = new models.ServiceUnit({
152 id: 'wordpress/1', 153 id: 'wordpress/1',
153 agent_state: 'error'}); 154 agent_state: 'error'});
154 sul.add([wp0, wp1]); 155 sul.add([wp0, wp1]);
155 156
156 sul.get_informative_states_for_service(mysql).should.eql( 157 assert.deepEqual(sul.get_informative_states_for_service(mysql),
157 {'pending': 2}); 158 [{'pending': 2}, {}]);
158 sul.get_informative_states_for_service(wordpress).should.eql( 159 assert.deepEqual(sul.get_informative_states_for_service(wordpress),
159 {'pending': 1, 'error': 1}); 160 [{'pending': 1, 'error': 1}, {}]);
160 }); 161 });
161 162
162 it('service unit list should update analytics when units are added', 163 it('service unit list should update analytics when units are added',
163 function() { 164 function() {
164 var sl = new models.ServiceList(); 165 var sl = new models.ServiceList();
165 var sul = new models.ServiceUnitList(); 166 var sul = new models.ServiceUnitList();
166 var mysql = new models.Service({id: 'mysql'}); 167 var mysql = new models.Service({id: 'mysql'});
167 sl.add([mysql]); 168 sl.add([mysql]);
168 var my0 = new models.ServiceUnit({ 169 var my0 = new models.ServiceUnit({
169 id: 'mysql/0', 170 id: 'mysql/0',
170 agent_state: 'pending'}); 171 agent_state: 'pending'});
171 var my1 = new models.ServiceUnit({ 172 var my1 = new models.ServiceUnit({
172 id: 'mysql/1', 173 id: 'mysql/1',
173 agent_state: 'pending'}); 174 agent_state: 'pending'});
174 175
175 window._gaq.should.eql([]); 176 window._gaq.should.eql([]);
176 sul.add([my0]); 177 sul.add([my0]);
177 sul.update_service_unit_aggregates(mysql); 178 sul.update_service_unit_aggregates(mysql);
178 window._gaq.pop().should.eql(['_trackEvent', 'Service Stats', 'Update', 179 window._gaq.pop().should.eql(['_trackEvent', 'Service Stats', 'Update',
179 'mysql', 1]); 180 'mysql', 1]);
180 sul.add([my1]); 181 sul.add([my1]);
181 sul.update_service_unit_aggregates(mysql); 182 sul.update_service_unit_aggregates(mysql);
182 window._gaq.pop().should.eql(['_trackEvent', 'Service Stats', 'Update', 183 window._gaq.pop().should.eql(['_trackEvent', 'Service Stats', 'Update',
183 'mysql', 2]); 184 'mysql', 2]);
184 // Calling update with no additions does not create a new trackEvent. 185 // Calling update with no additions does not create a new trackEvent.
185 sul.update_service_unit_aggregates(mysql); 186 sul.update_service_unit_aggregates(mysql);
186 window._gaq.should.eql([]); 187 window._gaq.should.eql([]);
187 }); 188 });
188 189
190 it('services have unit and relation modellists', function() {
191 var service = new models.Service();
192 assert.equal(service.get('units') instanceof models.ServiceUnitList, true);
193 assert.equal(service.get('relations') instanceof models.RelationList, true);
194 });
195
196 it('relation changes on service update aggregateRelations', function(done) {
197 var service = new models.Service();
198 var relations = service.get('relations');
199 var handler = relations.on(
200 '*:add', function() {
201 // This means that it will update the aggregate
202 // relations for databinding
203 handler.detach();
204 var isObject = yui.Lang.isObject;
205 assert.equal(isObject(service.get('aggregateRelations')), true);
206 done();
207 });
208 relations.add(new models.Relation());
209 });
210
189 it('service unit objects should parse the service name from unit id', 211 it('service unit objects should parse the service name from unit id',
190 function() { 212 function() {
191 var service_unit = {id: 'mysql/0'}; 213 var service_unit = {id: 'mysql/0'};
192 var db = new models.Database(); 214 var db = new models.Database();
193 db.units.add(service_unit); 215 db.units.add(service_unit);
194 service_unit.service.should.equal('mysql'); 216 service_unit.service.should.equal('mysql');
195 }); 217 });
196 218
197 it('service unit objects should report their number correctly', 219 it('service unit objects should report their number correctly',
198 function() { 220 function() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 db.resolveModelByName('env').should.equal(db.environment); 263 db.resolveModelByName('env').should.equal(db.environment);
242 264
243 var machine = db.machines.add({machine_id: '0'}); 265 var machine = db.machines.add({machine_id: '0'});
244 db.resolveModelByName('0').should.equal(machine); 266 db.resolveModelByName('0').should.equal(machine);
245 }); 267 });
246 268
247 it('should update service units on change', function() { 269 it('should update service units on change', function() {
248 var db = new models.Database(); 270 var db = new models.Database();
249 var mysql = new models.Service({id: 'mysql'}); 271 var mysql = new models.Service({id: 'mysql'});
250 db.services.add([mysql]); 272 db.services.add([mysql]);
251 assert.isUndefined(mysql.get('units')); 273 assert.equal(mysql.get('units') instanceof models.ServiceUnitList, true);
252 db.onDelta({data: {result: [ 274 db.onDelta({data: {result: [
253 ['unit', 'add', {id: 'mysql/0', agent_state: 'pending'}], 275 ['unit', 'add', {id: 'mysql/0', agent_state: 'pending'}],
254 ['unit', 'add', {id: 'mysql/1', agent_state: 'pending'}] 276 ['unit', 'add', {id: 'mysql/1', agent_state: 'pending'}]
255 ]}}); 277 ]}});
256 assert.equal(mysql.get('units').size(), 2); 278 assert.equal(mysql.get('units').size(), 2);
257 db.onDelta({data: {result: [ 279 db.onDelta({data: {result: [
258 ['unit', 'remove', 'mysql/1'] 280 ['unit', 'remove', 'mysql/1']
259 ]}}); 281 ]}});
260 assert.equal(mysql.get('units').size(), 1); 282 assert.equal(mysql.get('units').size(), 1);
261 }); 283 });
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 function() { 315 function() {
294 var db = new models.Database(); 316 var db = new models.Database();
295 var my0 = {id: 'mysql/0', agent_state: 'pending'}; 317 var my0 = {id: 'mysql/0', agent_state: 'pending'};
296 db.units.add([my0]); 318 db.units.add([my0]);
297 db.onDelta({data: {result: [ 319 db.onDelta({data: {result: [
298 ['unit', 'add', {id: 'mysql/0', agent_state: 'another'}] 320 ['unit', 'add', {id: 'mysql/0', agent_state: 'another'}]
299 ]}}); 321 ]}});
300 my0.agent_state.should.equal('another'); 322 my0.agent_state.should.equal('another');
301 }); 323 });
302 324
303 it('onDelta should reset relation_errors', 325 // We no longer use relation_errors but this test should remain until it's
326 // completely removed from the codebase.
327 it.skip('onDelta should reset relation_errors',
304 function() { 328 function() {
305 var db = new models.Database(); 329 var db = new models.Database();
306 var my0 = {id: 'mysql/0', relation_errors: {'cache': ['memcached']}}; 330 var my0 = {id: 'mysql/0', relation_errors: {'cache': ['memcached']}};
307 db.units.add([my0]); 331 db.units.add([my0]);
308 // Note that relation_errors is not set. 332 // Note that relation_errors is not set.
309 db.onDelta({data: {result: [ 333 db.onDelta({data: {result: [
310 ['unit', 'change', {id: 'mysql/0'}] 334 ['unit', 'change', {id: 'mysql/0'}]
311 ]}}); 335 ]}});
312 my0.relation_errors.should.eql({}); 336 my0.relation_errors.should.eql({});
313 }); 337 });
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 assert.isFalse(mysql.hasErrors(), mysql.get('id')); 1093 assert.isFalse(mysql.hasErrors(), mysql.get('id'));
1070 }); 1094 });
1071 1095
1072 it('can be filtered so that it returns only visible models', function() { 1096 it('can be filtered so that it returns only visible models', function() {
1073 var filtered = list.visible(); 1097 var filtered = list.visible();
1074 assert.strictEqual(2, filtered.size()); 1098 assert.strictEqual(2, filtered.size());
1075 assert.deepEqual([django, wordpress], filtered.toArray()); 1099 assert.deepEqual([django, wordpress], filtered.toArray());
1076 }); 1100 });
1077 1101
1078 }); 1102 });
OLDNEW
« no previous file with comments | « test/test_fakebackend.js ('k') | test/test_model_handlers.js » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b