unittests/tests/widgets/playerWidget.js
branchpopcorn-port
changeset 234 43b198dc932d
child 250 41683e7cb17a
equal deleted inserted replaced
233:126de77ee73e 234:43b198dc932d
       
     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.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     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.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4");
       
    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     ok(spy_callback2.calledOnce, "test if pause callback has been called");                                                                    
       
    49   });
       
    50   
       
    51   test("test mute button event handler", function() {
       
    52     var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser);
       
    53 
       
    54     var spy_callback = this.spy();
       
    55     var spy_handler = sinon.spy(player, "muteHandler");
       
    56     this.Popcorn.listen("volumechange", spy_callback);    
       
    57     
       
    58     player.draw();
       
    59        
       
    60     // IriSP.jQuery("#ldt-CtrlSound").trigger("click");    
       
    61     player.selector.find(".Ldt-Control2 button:first").next().trigger("click");    
       
    62     ok(this.Popcorn.muted(), "the player is muted");
       
    63     
       
    64     player.selector.find("#ldt-CtrlSound").trigger("click");
       
    65     ok(!this.Popcorn.muted(), "the player is un muted");         
       
    66     ok(spy_handler.called, "handling function has been called");                                                                                                                                        
       
    67   });
       
    68   
       
    69   test("test search button event handler", function() {
       
    70   var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser);
       
    71   
       
    72   var searchTerm = "blah";
       
    73   
       
    74   var spy_callback = this.spy();
       
    75   var spy_open = this.spy();
       
    76   var spy_closed = this.spy();
       
    77   var spy_cleared = this.spy();
       
    78   var spy_handler = sinon.spy(player, "searchButtonHandler");
       
    79   
       
    80   player._Popcorn.listen("IriSP.search", spy_callback);    
       
    81   player._Popcorn.listen("IriSP.search.open", spy_open);    
       
    82   player._Popcorn.listen("IriSP.search.closed", spy_closed);    
       
    83   player._Popcorn.listen("IriSP.search.cleared", spy_cleared);    
       
    84   
       
    85   player.draw();
       
    86      
       
    87   player.selector.find("#ldt-CtrlSearch").trigger("click");
       
    88   player.selector.find("#LdtSearchInput").attr('value', searchTerm); 
       
    89   player.selector.find("#LdtSearchInput").trigger('keyup');
       
    90   
       
    91   ok(spy_handler.called, "search button handling function has been called");  
       
    92   ok(spy_open.called, "open signal has been sent");  
       
    93   ok(spy_callback.called, "search typeahead function has been called");
       
    94   ok(spy_callback.calledWith(searchTerm), "popcorn message sent with the right parameters");
       
    95 
       
    96   player.selector.find("#LdtSearchInput").attr('value', ""); 
       
    97   player.selector.find("#LdtSearchInput").trigger('keyup');
       
    98   ok(spy_cleared.called, "clear message has been sent");
       
    99   
       
   100   player.selector.find("#ldt-CtrlSearch").trigger("click");
       
   101   ok(spy_closed.called, "closed signal has been sent");  
       
   102   
       
   103   });
       
   104   
       
   105 };