Revision 92bbc5b9 snf-cyclades-app/synnefo/ui/static/snf/js/tests.js
b/snf-cyclades-app/synnefo/ui/static/snf/js/tests.js | ||
---|---|---|
48 | 48 |
'glance':'/images/v1.1' |
49 | 49 |
}; |
50 | 50 |
|
51 |
snf.user = {'token': 'TESTTOKEN'} |
|
52 |
|
|
51 | 53 |
module("VM Model") |
52 | 54 |
|
53 | 55 |
test("model change events", function(){ |
... | ... | |
57 | 59 |
var v1 = new models.VM({'imageRef':1}); |
58 | 60 |
v1.bind("change", function(){ |
59 | 61 |
ok(1, "change event triggered") |
60 |
equals(v1.get("status"), "BUILD")
|
|
61 |
equals(v1.get("state"), "BUILD_COPY")
|
|
62 |
equal(v1.get("status"), "BUILD") |
|
63 |
equal(v1.get("state"), "BUILD_COPY") |
|
62 | 64 |
}) |
63 | 65 |
v1.set({'status':'BUILD', 'progress':80, 'imageRef': 1}); |
64 | 66 |
v1.unbind(); |
65 | 67 |
|
66 | 68 |
v1.bind("change", function(){ |
67 | 69 |
ok(1, "change event triggered") |
68 |
equals(v1.get("status"), "BUILD")
|
|
69 |
equals(v1.get("state"), "DESTROY")
|
|
70 |
equal(v1.get("status"), "BUILD") |
|
71 |
equal(v1.get("state"), "DESTROY") |
|
70 | 72 |
}) |
71 | 73 |
v1.set({'state':'DESTROY'}); |
72 | 74 |
v1.unbind(); |
73 | 75 |
|
74 | 76 |
v1.bind("change", function() { |
75 | 77 |
ok(1, "change event triggered") |
76 |
equals(v1.get("status"), "BUILD")
|
|
77 |
equals(v1.get("state"), "BUILD_COPY")
|
|
78 |
equal(v1.get("status"), "BUILD") |
|
79 |
equal(v1.get("state"), "BUILD_COPY") |
|
78 | 80 |
}) |
79 | 81 |
v1.set({'status':'BUILD', 'progress':80, 'imageRef': 1}); |
80 |
equals(v1.get("status"), "BUILD")
|
|
81 |
equals(v1.get("state"), "DESTROY")
|
|
82 |
equal(v1.get("status"), "BUILD") |
|
83 |
equal(v1.get("state"), "DESTROY") |
|
82 | 84 |
v1.unbind(); |
83 | 85 |
}) |
84 | 86 |
|
... | ... | |
87 | 89 |
|
88 | 90 |
var v1 = new vm(); |
89 | 91 |
v1.set({status: 'BUILD_COPY'}) |
90 |
equals(v1.get("state"), 'BUILD_COPY', "State is set");
|
|
92 |
equal(v1.get("state"), 'BUILD_COPY', "State is set"); |
|
91 | 93 |
v1.set({status: 'DESTROY'}) |
92 |
equals(v1.get("state"), 'DESTROY', "From buld to destroy");
|
|
94 |
equal(v1.get("state"), 'DESTROY', "From buld to destroy"); |
|
93 | 95 |
v1.set({status: 'BUILD'}) |
94 |
equals(v1.get("state"), 'DESTROY', "Keep destroy state");
|
|
96 |
equal(v1.get("state"), 'DESTROY', "Keep destroy state"); |
|
95 | 97 |
|
96 | 98 |
v1 = new vm(); |
97 | 99 |
v1.set({status: 'ACTIVE'}) |
98 |
equals(v1.get("state"), 'ACTIVE', "State is set");
|
|
100 |
equal(v1.get("state"), 'ACTIVE', "State is set"); |
|
99 | 101 |
|
100 | 102 |
v1.set({status: 'SHUTDOWN'}) |
101 |
equals(v1.get("state"), 'SHUTDOWN', "From active to shutdown (should change)");
|
|
103 |
equal(v1.get("state"), 'SHUTDOWN', "From active to shutdown (should change)"); |
|
102 | 104 |
|
103 | 105 |
v1.set({status: 'ACTIVE'}) |
104 |
equals(v1.get("state"), 'SHUTDOWN', "From shutdown to active (should not change)");
|
|
106 |
equal(v1.get("state"), 'SHUTDOWN', "From shutdown to active (should not change)"); |
|
105 | 107 |
|
106 | 108 |
v1.set({status: 'STOPPED'}) |
107 |
equals(v1.get("state"), 'STOPPED', "From shutdown to stopped (should change)");
|
|
109 |
equal(v1.get("state"), 'STOPPED', "From shutdown to stopped (should change)"); |
|
108 | 110 |
|
109 | 111 |
v1.set({status: 'ACTIVE'}) |
110 |
equals(v1.get("state"), 'ACTIVE', "From stopped to active (should change)");
|
|
112 |
equal(v1.get("state"), 'ACTIVE', "From stopped to active (should change)"); |
|
111 | 113 |
v1.set({'status': 'STOPPED'}) |
112 |
equals(v1.get('state'), 'STOPPED', "From shutdown to stopped should change");
|
|
114 |
equal(v1.get('state'), 'STOPPED', "From shutdown to stopped should change"); |
|
113 | 115 |
|
114 | 116 |
v1.set({'status': 'DESTROY'}) |
115 |
equals(v1.get('state'), 'DESTROY', "From stopped to destory should set state to DESTROY");
|
|
117 |
equal(v1.get('state'), 'DESTROY', "From stopped to destory should set state to DESTROY"); |
|
116 | 118 |
v1.set({'status': 'ACTIVE'}) |
117 |
equals(v1.get('state'), 'DESTROY', "From destroy to active should keep state to DESTROY");
|
|
119 |
equal(v1.get('state'), 'DESTROY', "From destroy to active should keep state to DESTROY"); |
|
118 | 120 |
v1.set({'status': 'REBOOT'}) |
119 |
equals(v1.get('state'), 'DESTROY', "From destroy to active should keep state to DESTROY");
|
|
121 |
equal(v1.get('state'), 'DESTROY', "From destroy to active should keep state to DESTROY"); |
|
120 | 122 |
v1.set({'status': 'DELETED'}) |
121 |
equals(v1.get('state'), 'DELETED', "Destroy should be kept until DELETE or ERROR");
|
|
123 |
equal(v1.get('state'), 'DELETED', "Destroy should be kept until DELETE or ERROR"); |
|
122 | 124 |
|
123 | 125 |
v1 = new vm({status:'BUILD'}); |
124 |
equals(v1.get('state'), 'BUILD', "new vm with build as initial status")
|
|
125 |
equals(v1.get('status'), 'BUILD', "new vm with build as initial status")
|
|
126 |
equal(v1.get('state'), 'BUILD', "new vm with build as initial status") |
|
127 |
equal(v1.get('status'), 'BUILD', "new vm with build as initial status") |
|
126 | 128 |
v1.set({status:'ACTIVE'}) |
127 |
equals(v1.get('state'), 'ACTIVE', "active state has been set")
|
|
128 |
equals(v1.get('status'), 'ACTIVE', "active status has been set")
|
|
129 |
equal(v1.get('state'), 'ACTIVE', "active state has been set") |
|
130 |
equal(v1.get('status'), 'ACTIVE', "active status has been set") |
|
129 | 131 |
}) |
130 | 132 |
|
131 | 133 |
|
... | ... | |
133 | 135 |
synnefo.storage.images.add({id:1,metadata:{values:{size:100}}}); |
134 | 136 |
var vm = models.VM; |
135 | 137 |
var v1 = new vm({'status':'BUILD','progress':0, 'imageRef':1}); |
136 |
equals(v1.get('state'), 'BUILD_INIT', "progress 0 sets state to BUILD_INIT");
|
|
137 |
equals(v1.get('status'), 'BUILD', "progress 0 sets status to BUILD");
|
|
138 |
equals(v1.get('progress_message'), 'init', "message 'init'");
|
|
138 |
equal(v1.get('state'), 'BUILD_INIT', "progress 0 sets state to BUILD_INIT"); |
|
139 |
equal(v1.get('status'), 'BUILD', "progress 0 sets status to BUILD"); |
|
140 |
equal(v1.get('progress_message'), 'init', "message 'init'"); |
|
139 | 141 |
v1.set({status:'BUILD', progress:50}); |
140 |
equals(v1.get('state'), 'BUILD_COPY', "progress 50 sets state to BUILD_COPY");
|
|
141 |
equals(v1.get('status'), 'BUILD', "progress 50 sets status to BUILD");
|
|
142 |
equals(v1.get('progress_message'), '50.00 MB, 100.00 MB, 50', "message: 'final'");
|
|
142 |
equal(v1.get('state'), 'BUILD_COPY', "progress 50 sets state to BUILD_COPY"); |
|
143 |
equal(v1.get('status'), 'BUILD', "progress 50 sets status to BUILD"); |
|
144 |
equal(v1.get('progress_message'), '50.00 MB, 100.00 MB, 50', "message: 'final'"); |
|
143 | 145 |
v1.set({status:'BUILD', progress:100}); |
144 |
equals(v1.get('state'), 'BUILD_FINAL', "progress 100 sets state to BUILD_FINAL");
|
|
145 |
equals(v1.get('status'), 'BUILD', "progress 100 sets status to BUILD");
|
|
146 |
equal(v1.get('state'), 'BUILD_FINAL', "progress 100 sets state to BUILD_FINAL"); |
|
147 |
equal(v1.get('status'), 'BUILD', "progress 100 sets status to BUILD"); |
|
146 | 148 |
v1.set({status:'ACTIVE', progress:100}); |
147 |
equals(v1.get('state'), 'ACTIVE', "ACTIVE set transition to ACTIVE");
|
|
148 |
equals(v1.get('status'), 'ACTIVE', "ACTIVE set transition to ACTIVE");
|
|
149 |
equals(v1.get('progress_message'), 'final', "message: 'final'");
|
|
149 |
equal(v1.get('state'), 'ACTIVE', "ACTIVE set transition to ACTIVE"); |
|
150 |
equal(v1.get('status'), 'ACTIVE', "ACTIVE set transition to ACTIVE"); |
|
151 |
equal(v1.get('progress_message'), 'final', "message: 'final'"); |
|
150 | 152 |
}) |
151 | 153 |
|
152 | 154 |
test("active inactive states", function(){ |
... | ... | |
158 | 160 |
for (v in active) { |
159 | 161 |
v = active[v]; |
160 | 162 |
v1.set({status: v}) |
161 |
equals(v1.is_active(), true, v + " status is active")
|
|
163 |
equal(v1.is_active(), true, v + " status is active") |
|
162 | 164 |
} |
163 | 165 |
|
164 | 166 |
var v1 = new vm(); |
... | ... | |
166 | 168 |
for (v in inactive) { |
167 | 169 |
v = inactive[v]; |
168 | 170 |
v1.set({status: v}) |
169 |
equals(v1.is_active(), false, v1.state() + " status is not active")
|
|
171 |
equal(v1.is_active(), false, v1.state() + " status is not active") |
|
170 | 172 |
} |
171 | 173 |
|
172 | 174 |
}) |
... | ... | |
177 | 179 |
var vm = new models.VM({status:'BUILD'}); |
178 | 180 |
vm.bind("transition", function(data) { |
179 | 181 |
ok(true, "Transition triggered"); |
180 |
equals(data.from, "BUILD")
|
|
181 |
equals(data.to, "ACTIVE");
|
|
182 |
equal(data.from, "BUILD") |
|
183 |
equal(data.to, "ACTIVE"); |
|
182 | 184 |
}) |
183 | 185 |
// trigger 1 time |
184 | 186 |
vm.set({status:'BUILD'}); |
... | ... | |
189 | 191 |
vm = new models.VM({status:'BUILD'}); |
190 | 192 |
vm.bind("transition", function(data) { |
191 | 193 |
ok(true, "Transition triggered"); |
192 |
equals(data.from, "BUILD")
|
|
193 |
equals(data.to, "ACTIVE");
|
|
194 |
equal(data.from, "BUILD") |
|
195 |
equal(data.to, "ACTIVE"); |
|
194 | 196 |
}) |
195 | 197 |
// trigger 1 time |
196 | 198 |
vm.set({status:'ACTIVE'}); |
... | ... | |
200 | 202 |
vm = new models.VM({status:'SHUTDOWN'}); |
201 | 203 |
vm.bind("transition", function(data) { |
202 | 204 |
ok(true, "Transition triggered"); |
203 |
equals(data.from, "SHUTDOWN")
|
|
204 |
equals(data.to, "STOPPED");
|
|
205 |
equal(data.from, "SHUTDOWN") |
|
206 |
equal(data.to, "STOPPED"); |
|
205 | 207 |
}) |
206 | 208 |
// trigger 1 time |
207 | 209 |
vm.set({status:'STOPPED'}); |
... | ... | |
257 | 259 |
ok(1, "NOT EXPECTED: change triggered on new entry while collection was empty"); |
258 | 260 |
}); |
259 | 261 |
collection.fetch({'async': false}); |
260 |
equals(collection.length, 1, "2: collection contains 1 model");
|
|
262 |
equal(collection.length, 1, "2: collection contains 1 model"); |
|
261 | 263 |
collection.unbind(); |
262 | 264 |
$.mockjaxClear(); |
263 | 265 |
|
... | ... | |
280 | 282 |
ok(1, "3: change triggered on new entry while collection was empty"); |
281 | 283 |
}); |
282 | 284 |
collection.fetch({'async': false, refresh:true}); |
283 |
equals(collection.length, 1, "4 collection contains 1 model");
|
|
285 |
equal(collection.length, 1, "4 collection contains 1 model"); |
|
284 | 286 |
collection.unbind(); |
285 | 287 |
$.mockjaxClear(); |
286 | 288 |
|
... | ... | |
303 | 305 |
ok(1, "NOT EXPECTED: change triggered when new model arrived"); |
304 | 306 |
}) |
305 | 307 |
collection.fetch({async:false, refresh:true}); |
306 |
equals(collection.length, 2, "6 new model added");
|
|
308 |
equal(collection.length, 2, "6 new model added"); |
|
307 | 309 |
collection.unbind(); |
308 | 310 |
$.mockjaxClear(); |
309 | 311 |
|
... | ... | |
326 | 328 |
}) |
327 | 329 |
|
328 | 330 |
collection.fetch({async:false, refresh:true}); |
329 |
equals(collection.length, 1, "8 one model removed");
|
|
331 |
equal(collection.length, 1, "8 one model removed"); |
|
330 | 332 |
collection.unbind(); |
331 | 333 |
$.mockjaxClear(); |
332 | 334 |
|
... | ... | |
348 | 350 |
ok(1, "WRONG: remove triggered on 304"); |
349 | 351 |
}); |
350 | 352 |
collection.fetch({async:false, refresh:true}); |
351 |
equals(collection.length, 1, "9 one model removed");
|
|
353 |
equal(collection.length, 1, "9 one model removed"); |
|
352 | 354 |
collection.unbind(); |
353 | 355 |
$.mockjaxClear(); |
354 | 356 |
}) |
... | ... | |
383 | 385 |
var vm1 = vms.add({imageRef:1, name:"vm1"}).last(); |
384 | 386 |
var vm2 = vms.add({imageRef:2, name:"vm2"}).last(); |
385 | 387 |
|
386 |
equals(img, vm1.get_image()); |
|
388 |
vm1.get_image(function(i){ |
|
389 |
equal(i, img); |
|
390 |
}); |
|
387 | 391 |
|
388 | 392 |
// reset is not called on 304 |
389 | 393 |
$.mockjax({ |
... | ... | |
394 | 398 |
}); |
395 | 399 |
|
396 | 400 |
|
397 |
equals(images.length, 1, "1 image exists"); |
|
398 |
vm2.get_image(); |
|
399 |
equals(images.get(2).get("name"), "image 2", "image data parsed"); |
|
400 |
equals(images.length, 2); |
|
401 |
equal(images.length, 1, "1 image exists"); |
|
402 |
vm2.get_image(function(i){ |
|
403 |
equal(images.get(2).get("name"), "image 2", "image data parsed"); |
|
404 |
equal(images.length, 2); |
|
405 |
}); |
|
401 | 406 |
}) |
402 | 407 |
|
403 | 408 |
test("Test DELETE state flavor retrieval", function() { |
... | ... | |
411 | 416 |
var vm1 = vms.add({flavorRef:1, name:"vm1"}).last(); |
412 | 417 |
var vm2 = vms.add({flavorRef:2, name:"vm2"}).last(); |
413 | 418 |
|
414 |
equals(flv, vm1.get_flavor());
|
|
419 |
equal(flv, vm1.get_flavor()); |
|
415 | 420 |
|
416 | 421 |
// reset is not called on 304 |
417 | 422 |
$.mockjax({ |
... | ... | |
422 | 427 |
}); |
423 | 428 |
|
424 | 429 |
|
425 |
equals(flavors.length, 1, "1 flavor exists");
|
|
430 |
equal(flavors.length, 1, "1 flavor exists"); |
|
426 | 431 |
vm2.get_flavor(); |
427 |
equals(flavors.get(2).get("ram"), 2048, "flavor data parsed");
|
|
428 |
equals(flavors.length, 2);
|
|
432 |
equal(flavors.get(2).get("ram"), 2048, "flavor data parsed"); |
|
433 |
equal(flavors.length, 2); |
|
429 | 434 |
}) |
430 | 435 |
|
431 | 436 |
test("actions list object", function(){ |
... | ... | |
434 | 439 |
var count = 0; |
435 | 440 |
|
436 | 441 |
l.add("destroy"); |
437 |
equals(l.has_action("destroy"), true);
|
|
438 |
equals(l.contains("destroy"), true);
|
|
442 |
equal(l.has_action("destroy"), true); |
|
443 |
equal(l.contains("destroy"), true); |
|
439 | 444 |
|
440 | 445 |
l.add("destroy", 1, {}); |
441 |
equals(l.has_action("destroy"), true);
|
|
442 |
equals(l.contains("destroy", 1, {}), true);
|
|
446 |
equal(l.has_action("destroy"), true); |
|
447 |
equal(l.contains("destroy", 1, {}), true); |
|
443 | 448 |
|
444 | 449 |
l.remove("destroy", 1, {}); |
445 |
equals(l.contains("destroy", 1, {}), false);
|
|
450 |
equal(l.contains("destroy", 1, {}), false); |
|
446 | 451 |
|
447 | 452 |
m.bind("change:actions", function() { count ++}); |
448 | 453 |
l.add("destroy"); |
449 | 454 |
|
450 |
equals(count, 0);
|
|
455 |
equal(count, 0); |
|
451 | 456 |
l.add("destroy", 1, {}); |
452 |
equals(count, 1);
|
|
457 |
equal(count, 1); |
|
453 | 458 |
}); |
454 | 459 |
|
455 | 460 |
module("update handlers") |
... | ... | |
483 | 488 |
h.stop(); |
484 | 489 |
start(); |
485 | 490 |
// 4 calls, limit reached |
486 |
equals(counter, 4, "normal calls");
|
|
487 |
equals(h.interval, opts.max, "limit reached");
|
|
491 |
equal(counter, 4, "normal calls"); |
|
492 |
equal(h.interval, opts.max, "limit reached"); |
|
488 | 493 |
|
489 | 494 |
stop(); |
490 | 495 |
h.start(false); |
... | ... | |
492 | 497 |
window.setTimeout(function(){ |
493 | 498 |
// 11 calls, limit reached |
494 | 499 |
start(); |
495 |
equals(counter, 11, "faster calls");
|
|
496 |
equals(h.interval, opts.max, "limit reached");
|
|
500 |
equal(counter, 11, "faster calls"); |
|
501 |
equal(h.interval, opts.max, "limit reached"); |
|
497 | 502 |
h.stop(); |
498 | 503 |
stop(); |
499 | 504 |
window.setTimeout(function(){ |
500 | 505 |
// no additional calls because we stopped it |
501 | 506 |
start(); |
502 |
equals(counter, 11, "no additional calls")
|
|
507 |
equal(counter, 11, "no additional calls") |
|
503 | 508 |
}, 50 + add) |
504 | 509 |
}, 50 + add) |
505 | 510 |
}, 43 + add) |
Also available in: Unified diff