1 /* test module for the player widget */ |
|
2 |
|
3 function test_player_widget() { |
|
4 module("player widget testing", |
|
5 {setup : function() { |
|
6 this.Popcorn = Popcorn("#popcorn-div"); |
|
7 |
|
8 this.dt = new IriSP.DataLoader(); |
|
9 this.ser = new IriSP.MockSerializer(this.dt, "/url"); /* dummy serializer */ |
|
10 this.lay = new IriSP.LayoutManager('widget-div'); |
|
11 |
|
12 this.config = { |
|
13 width:650, |
|
14 height:1, |
|
15 mode:'radio', |
|
16 container:'widget-div', |
|
17 debug:true, |
|
18 css:'../src/css/LdtPlayer.css'} |
|
19 }, |
|
20 teardown: function() { |
|
21 /* free the popcorn object because it has signal handlers attached to it */ |
|
22 this.Popcorn = Popcorn("#popcorn-div"); |
|
23 } |
|
24 |
|
25 }); |
|
26 |
|
27 test("test player initialisation", function() { |
|
28 var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser); |
|
29 player.draw(); |
|
30 |
|
31 equal(IriSP.jQuery("#widget-div").length, 1, "test if the div has been added correctly"); |
|
32 }); |
|
33 |
|
34 test("test play button event handler", function() { |
|
35 var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser); |
|
36 |
|
37 var spy_callback = this.spy(); |
|
38 var spy_callback2 = this.spy(); |
|
39 this.Popcorn.listen("play", spy_callback); |
|
40 this.Popcorn.listen("pause", spy_callback2); |
|
41 sinon.spy(player, "playHandler"); |
|
42 |
|
43 player.draw(); |
|
44 |
|
45 player.selector.find(".ldt-CtrlPlay").trigger("click"); |
|
46 player.selector.find(".ldt-CtrlPlay").trigger("click"); |
|
47 ok(player.playHandler.calledTwice, "play handler called"); |
|
48 }); |
|
49 |
|
50 test("test mute button event handler", function() { |
|
51 var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser); |
|
52 |
|
53 var spy_callback = this.spy(); |
|
54 var spy_handler = sinon.spy(player, "muteHandler"); |
|
55 this.Popcorn.listen("volumechange", spy_callback); |
|
56 |
|
57 player.draw(); |
|
58 |
|
59 player.selector.find(".ldt-CtrlSound").trigger("click"); |
|
60 ok(this.Popcorn.muted(), "the player is muted"); |
|
61 |
|
62 player.selector.find(".ldt-CtrlSound").trigger("click"); |
|
63 ok(!this.Popcorn.muted(), "the player is un muted"); |
|
64 ok(spy_handler.called, "handling function has been called"); |
|
65 }); |
|
66 |
|
67 test("test search button event handler", function() { |
|
68 var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser); |
|
69 |
|
70 var searchTerm = "blah"; |
|
71 |
|
72 var spy_callback = this.spy(); |
|
73 var spy_open = this.spy(); |
|
74 var spy_closed = this.spy(); |
|
75 var spy_cleared = this.spy(); |
|
76 var spy_handler = sinon.spy(player, "searchButtonHandler"); |
|
77 |
|
78 player._Popcorn.listen("IriSP.search", spy_callback); |
|
79 player._Popcorn.listen("IriSP.search.open", spy_open); |
|
80 player._Popcorn.listen("IriSP.search.closed", spy_closed); |
|
81 player._Popcorn.listen("IriSP.search.cleared", spy_cleared); |
|
82 |
|
83 player.draw(); |
|
84 |
|
85 player.selector.find(".ldt-CtrlSearch").trigger("click"); |
|
86 player.selector.find(".LdtSearchInput").attr('value', searchTerm); |
|
87 player.selector.find(".LdtSearchInput").trigger('keyup'); |
|
88 |
|
89 ok(spy_handler.called, "search button handling function has been called"); |
|
90 ok(spy_open.called, "open signal has been sent"); |
|
91 ok(spy_callback.called, "search typeahead function has been called"); |
|
92 ok(spy_callback.calledWith(searchTerm), "popcorn message sent with the right parameters"); |
|
93 |
|
94 player.selector.find(".LdtSearchInput").attr('value', ""); |
|
95 player.selector.find(".LdtSearchInput").trigger('keyup'); |
|
96 ok(spy_cleared.called, "clear message has been sent"); |
|
97 |
|
98 player.selector.find(".ldt-CtrlSearch").trigger("click"); |
|
99 ok(spy_closed.called, "closed signal has been sent"); |
|
100 |
|
101 }); |
|
102 |
|
103 test("test mouseover handler", function() { |
|
104 var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser); |
|
105 |
|
106 var spy_callback = this.spy(); |
|
107 this.Popcorn.listen("IriSP.PlayerWidget.MouseOver", spy_callback); |
|
108 this.Popcorn.listen("IriSP.PlayerWidget.MouseOut", spy_callback); |
|
109 |
|
110 player.draw(); |
|
111 var elem = player.selector.get(0); |
|
112 |
|
113 if( document.createEvent ) { |
|
114 var evObj = document.createEvent('MouseEvents'); |
|
115 evObj.initEvent( 'mouseover', true, false ); |
|
116 elem.dispatchEvent(evObj); |
|
117 } else if( document.createEventObject ) { |
|
118 elem.fireEvent('onmouseover'); |
|
119 } |
|
120 |
|
121 ok(spy_callback.called, "the MouseOver event has been fired"); |
|
122 |
|
123 if( document.createEvent ) { |
|
124 var evObj = document.createEvent('MouseEvents'); |
|
125 evObj.initEvent( 'mouseout', true, false ); |
|
126 elem.dispatchEvent(evObj); |
|
127 } else if( document.createEventObject ) { |
|
128 elem.fireEvent('onmouseout'); |
|
129 } |
|
130 |
|
131 ok(spy_callback.calledTwice, "the MouseOver event has been fired"); |
|
132 }); |
|
133 |
|
134 }; |
|