37 var ser = new IriSP.JSONSerializer(this.dt, "/url"); |
37 var ser = new IriSP.JSONSerializer(this.dt, "/url"); |
38 |
38 |
39 ser.sync(spy_callback); |
39 ser.sync(spy_callback); |
40 |
40 |
41 equals(this.xhr.requests.length, 1, "the mock ajax object should have received the request"); |
41 equals(this.xhr.requests.length, 1, "the mock ajax object should have received the request"); |
|
42 equals(this.xhr.requests[0].url, "/url", "the requested url is correct"); |
|
43 |
42 this.xhr.requests[0].respond(200, { "Content-Type": "application/json" }, |
44 this.xhr.requests[0].respond(200, { "Content-Type": "application/json" }, |
43 response_string); |
45 response_string); |
44 |
46 |
45 ok(spy_callback.calledOnce, "callback called"); |
47 ok(spy_callback.calledOnce, "callback called"); |
46 ok(spy_callback.calledWith(response_array), "callback called with correct value"); |
48 ok(spy_callback.calledWith(response_array), "callback called with correct value"); |
59 ok(order_preserved, "the annotation sub-array is sorted by begin time"); |
61 ok(order_preserved, "the annotation sub-array is sorted by begin time"); |
60 }); |
62 }); |
61 |
63 |
62 test("currentMedia should return the current media", function() { |
64 test("currentMedia should return the current media", function() { |
63 var ser = new IriSP.JSONSerializer(this.dt, "/url"); |
65 var ser = new IriSP.JSONSerializer(this.dt, "/url"); |
64 /* FIXME: actually get something instead of monkey-patching the struct */ |
66 |
65 ser._data = {} |
67 ser._data = {} |
66 ser._data.medias = [0]; |
68 ser._data.medias = [0]; |
67 equal(ser.currentMedia(), 0, "currentMedia() returns the correct value"); |
69 equal(ser.currentMedia(), 0, "currentMedia() returns the correct value"); |
68 }); |
70 }); |
|
71 |
|
72 test("test annotation search", function() { |
|
73 var ser = new IriSP.JSONSerializer(this.dt, "../test/test.json"); |
|
74 |
|
75 ser._data = { annotations : [ |
|
76 {"content": { |
|
77 "description": "professeur", |
|
78 "title": "garrigou" |
|
79 }}, |
|
80 { "content": { |
|
81 "description": "interview", |
|
82 "title": "Revue de presse - Hervé Gardette" |
|
83 }}, |
|
84 {"content": { |
|
85 "description": "concept", |
|
86 "title": "idée" |
|
87 }}, |
|
88 { "content": { |
|
89 "description": "", |
|
90 "title": "sans titre" |
|
91 }} |
|
92 ]}; |
|
93 |
|
94 equal(ser.searchAnnotations("GarriGOU", "", "").length, 1, "requesting on title works"); |
|
95 equal(ser.searchAnnotations("", "IntErView", "").length, 1, "requesting on description works"); |
|
96 equal(ser.searchAnnotations("", "", "").length, 4, "empty request works"); |
|
97 equal(ser.searchAnnotations("idée", "concept", "").length, 1, "specific request works"); |
|
98 |
|
99 |
|
100 }); |
69 }; |
101 }; |