|
100
|
1 |
/* segmentsWidget.js */ |
|
|
2 |
|
|
|
3 |
function test_segments_widget() { |
|
|
4 |
module("segments widget testing", |
|
|
5 |
{setup : function() { |
|
|
6 |
this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4"); |
|
|
7 |
|
|
|
8 |
this.dt = new IriSP.DataLoader(); |
|
|
9 |
this.ser = new IriSP.MockSerializer(this.dt, "/url"); /* dummy serializer */ |
|
|
10 |
|
|
|
11 |
|
|
|
12 |
IriSP.jQuery("#widget-div").append("<div id='Ldt-Annotations'></div>"); |
|
|
13 |
this.config = { |
|
|
14 |
metadata:{ |
|
|
15 |
format:'cinelab', |
|
|
16 |
src:'test.json', |
|
|
17 |
load:'json'}, |
|
|
18 |
gui:{ |
|
|
19 |
width:650, |
|
|
20 |
height:1, |
|
|
21 |
mode:'radio', |
|
|
22 |
container:'widget-div', |
|
|
23 |
debug:true, |
|
|
24 |
css:'../src/css/LdtPlayer.css'}, |
|
|
25 |
}; |
|
|
26 |
}, |
|
|
27 |
teardown: function() { |
|
|
28 |
/* 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"); |
|
|
30 |
} |
|
|
31 |
}); |
|
|
32 |
|
|
|
33 |
test("test widget initialization", function() { |
|
|
34 |
var widget = new IriSP.SegmentsWidget(this.Popcorn, this.config, this.ser); |
|
|
35 |
widget.draw(); |
|
|
36 |
|
|
|
37 |
equal(IriSP.jQuery("#Ldt-Annotations").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"); |
|
|
39 |
}); |
|
|
40 |
|
|
104
|
41 |
test("test click on a random segment", function() { |
|
|
42 |
var widget = new IriSP.SegmentsWidget(this.Popcorn, this.config, this.ser); |
|
100
|
43 |
widget.draw(); |
|
104
|
44 |
|
|
|
45 |
var spy_callback = this.spy(); |
|
|
46 |
var spy_handler = sinon.spy(widget, "clickHandler"); |
|
|
47 |
this.Popcorn.listen("timeupdate", spy_callback); |
|
|
48 |
|
|
|
49 |
var selector = IriSP.jQuery("#Ldt-Annotations :not(first-child)"); |
|
|
50 |
var random = Math.round(Math.random() * selector.length); |
|
|
51 |
selector.eq(random).click(); |
|
|
52 |
|
|
|
53 |
ok(spy_callback.called, "the currenttime was changed"); |
|
|
54 |
ok(spy_handler.called, "handling function has been called"); |
|
100
|
55 |
}); |
|
|
56 |
}; |