5 {setup : function() { |
5 {setup : function() { |
6 this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4"); |
6 this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4"); |
7 |
7 |
8 this.dt = new IriSP.DataLoader(); |
8 this.dt = new IriSP.DataLoader(); |
9 this.ser = new IriSP.MockSerializer(this.dt, "/url"); /* dummy serializer */ |
9 this.ser = new IriSP.MockSerializer(this.dt, "/url"); /* dummy serializer */ |
10 |
10 |
11 |
|
12 IriSP.jQuery("#widget-div").append("<div id='Ldt-Annotations'></div>"); |
|
13 this.config = { |
11 this.config = { |
14 metadata:{ |
12 metadata:{ |
15 format:'cinelab', |
13 format:'cinelab', |
16 src:'test.json', |
14 src:'test.json', |
17 load:'json'}, |
15 load:'json'}, |
18 gui:{ |
|
19 width:650, |
16 width:650, |
20 height:1, |
17 height:1, |
21 mode:'radio', |
18 mode:'radio', |
22 container:'widget-div', |
19 container:'widget-div', |
23 debug:true, |
20 debug:true, |
24 css:'../src/css/LdtPlayer.css'}, |
21 css:'../src/css/LdtPlayer.css'} |
25 }; |
22 }, |
26 }, |
|
27 teardown: function() { |
23 teardown: function() { |
28 /* free the popcorn object because it has signal handlers attached to it */ |
24 /* free the popcorn object because it has signal handlers attached to it */ |
29 this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4"); |
25 this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4"); |
30 } |
26 }}); |
31 }); |
|
32 |
27 |
33 test("test widget initialization", function() { |
28 test("test widget initialization", function() { |
34 var widget = new IriSP.SegmentsWidget(this.Popcorn, this.config, this.ser); |
29 var widget = new IriSP.SegmentsWidget(this.Popcorn, this.config, this.ser); |
35 widget.draw(); |
30 widget.draw(); |
36 |
31 |
37 equal(IriSP.jQuery("#Ldt-Annotations").length, 1, "test if the div has been added correctly"); |
32 equal(IriSP.jQuery("#widget-div").length, 1, "test if the div has been added correctly"); |
38 equal(IriSP.jQuery("#Ldt-Annotations").children().length, this.ser._data.annotations.length, "test if children have been added correctly"); |
33 equal(IriSP.jQuery("#widget-div").children().length, this.ser._data.annotations.length, "test if children have been added correctly"); |
39 }); |
34 }); |
40 |
35 |
41 test("test click on a random segment", function() { |
36 test("test click on a random segment", function() { |
42 var widget = new IriSP.SegmentsWidget(this.Popcorn, this.config, this.ser); |
37 var widget = new IriSP.SegmentsWidget(this.Popcorn, this.config, this.ser); |
43 widget.draw(); |
38 widget.draw(); |
44 |
39 |
45 var spy_callback = this.spy(); |
40 var spy_callback = this.spy(); |
46 var spy_handler = sinon.spy(widget, "clickHandler"); |
41 var spy_handler = sinon.spy(widget, "clickHandler"); |
47 this.Popcorn.listen("timeupdate", spy_callback); |
42 this.Popcorn.listen("timeupdate", spy_callback); |
48 |
43 |
49 var selector = IriSP.jQuery("#Ldt-Annotations :not(first-child)"); |
44 var selector = IriSP.jQuery("#widget-div :not(first-child)"); |
50 var random = Math.round(Math.random() * selector.length) + 1; |
45 var random = Math.round(Math.random() * selector.length) + 1; |
51 selector.eq(random).click(); |
46 selector.eq(random).click(); |
52 |
47 |
53 ok(spy_callback.called, "the currenttime was changed"); |
48 ok(spy_callback.called, "the currenttime was changed"); |
54 ok(spy_handler.called, "handling function has been called"); |
49 ok(spy_handler.called, "handling function has been called"); |
59 var tag_id = "#s_" + "82613B88-9578-DC2C-D7D0-B2C5BE0B7BDA".toUpperCase(); |
54 var tag_id = "#s_" + "82613B88-9578-DC2C-D7D0-B2C5BE0B7BDA".toUpperCase(); |
60 |
55 |
61 var widget = new IriSP.SegmentsWidget(this.Popcorn, this.config, this.ser); |
56 var widget = new IriSP.SegmentsWidget(this.Popcorn, this.config, this.ser); |
62 widget.draw(); |
57 widget.draw(); |
63 |
58 |
64 var oldStyle = IriSP.jQuery("#Ldt-Annotations").children(tag_id).attr("style"); |
59 var oldStyle = IriSP.jQuery("#widget-div").children(tag_id).attr("style"); |
65 widget._Popcorn.trigger("IriSP.search", "sociologie"); |
60 widget._Popcorn.trigger("IriSP.search", "sociologie"); |
66 var newStyle = IriSP.jQuery("#Ldt-Annotations").children(tag_id).attr("style"); |
61 var newStyle = IriSP.jQuery("#widget-div").children(tag_id).attr("style"); |
67 notEqual(oldStyle, newStyle, "the segment style has been modified"); |
62 notEqual(oldStyle, newStyle, "the segment style has been modified"); |
68 }); |
63 }); |
69 }; |
64 }; |