18 this.requests = []; |
18 this.requests = []; |
19 this.xhr.onCreate = function (request) { |
19 this.xhr.onCreate = function (request) { |
20 this.requests.push(request); |
20 this.requests.push(request); |
21 }; |
21 }; |
22 |
22 |
23 var response_array = [{ media: 12, content: "Hey there" }]; |
23 var response_array = { media: 12, content: "Hey there", |
|
24 annotations: [{"begin": "32", "end" : 64}, {"begin": "08", "end" : 27},{"begin": "02", "end" : 61}] }; |
|
25 |
|
26 /* sorted array is our comparision array */ |
|
27 var sorted_array = IriSP.jQuery.extend({}, response_array); |
|
28 sorted_array.annotations.sort(function(a, b) |
|
29 { var a_begin = +a.begin; |
|
30 var b_begin = +b.begin; |
|
31 return a_begin - b_begin; |
|
32 }); |
|
33 |
24 var response_string = JSON.stringify(response_array); |
34 var response_string = JSON.stringify(response_array); |
25 |
35 |
26 var spy_callback = this.spy(); |
36 var spy_callback = this.spy(); |
27 var ser = new IriSP.JSONSerializer(this.dt, "/url"); |
37 var ser = new IriSP.JSONSerializer(this.dt, "/url"); |
28 |
38 |
33 response_string); |
43 response_string); |
34 |
44 |
35 ok(spy_callback.calledOnce, "callback called"); |
45 ok(spy_callback.calledOnce, "callback called"); |
36 ok(spy_callback.calledWith(response_array), "callback called with correct value"); |
46 ok(spy_callback.calledWith(response_array), "callback called with correct value"); |
37 deepEqual(ser._data, response_array, "the internal variable is initialized to the correct value"); |
47 deepEqual(ser._data, response_array, "the internal variable is initialized to the correct value"); |
|
48 |
|
49 var order_preserved = true; |
|
50 |
|
51 var i = 0; |
|
52 for(i = 0; i < ser._data.length - 1; i++) { |
|
53 if (ser._data.annotations[i].begin > ser._data.annotations[i+1].begin) { |
|
54 order_preserved = false; |
|
55 break; |
|
56 } |
|
57 } |
|
58 |
|
59 ok(order_preserved, "the annotation sub-array is sorted by begin time"); |
38 }); |
60 }); |
39 |
61 |
40 test("currentMedia should return the current media", function() { |
62 test("currentMedia should return the current media", function() { |
41 var ser = new IriSP.JSONSerializer(this.dt, "/url"); |
63 var ser = new IriSP.JSONSerializer(this.dt, "/url"); |
42 /* FIXME: actually get something instead of monkey-patching the struct */ |
64 /* FIXME: actually get something instead of monkey-patching the struct */ |
43 ser._data = {} |
65 ser._data = {} |
44 ser._data.medias = [0]; |
66 ser._data.medias = [0]; |
45 equal(ser.currentMedia(), 0, "currentMedia() returns the correct value"); |
67 equal(ser.currentMedia(), 0, "currentMedia() returns the correct value"); |
46 }); |
68 }); |
47 }; |
69 }; |