unittests/tests/playerWidget.js
author hamidouk
Mon, 14 Nov 2011 12:18:02 +0100
branchpopcorn-port
changeset 233 126de77ee73e
parent 226 d1f0e604bd06
permissions -rw-r--r--
Merge with slider-port
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
74
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
     1
/* test module for the player widget */
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
     2
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
     3
function test_player_widget() {
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
     4
  module("player widget testing", 
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
     5
  {setup : function() {    
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
     6
    this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4");
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
     7
    
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
     8
    this.dt = new IriSP.DataLoader();
83
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
     9
    this.ser = new IriSP.MockSerializer(this.dt, "/url"); /* dummy serializer */
120
35d91e67e972 added a layoutmanager in a test.
hamidouk
parents: 83
diff changeset
    10
    this.lay = new IriSP.LayoutManager('widget-div');
35d91e67e972 added a layoutmanager in a test.
hamidouk
parents: 83
diff changeset
    11
    
74
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    12
    this.config = {
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    13
							width:650,
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    14
							height:1,
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    15
							mode:'radio',
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    16
							container:'widget-div',
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    17
							debug:true,
134
ac70d6993337 changed file to follow function changes.
hamidouk
parents: 120
diff changeset
    18
							css:'../src/css/LdtPlayer.css'}					
83
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    19
    },
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    20
  teardown: function() {
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    21
    /* free the popcorn object because it has signal handlers attached to it */
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    22
    this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4");
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    23
  }
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    24
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    25
  });
74
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    26
  
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    27
  test("test player initialisation", function() {  
83
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    28
    var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser);    
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    29
    player.draw();
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    30
    
163
3ecb643627de some conversions to use this.selector.find instead of .children().
hamidouk
parents: 155
diff changeset
    31
    equal(IriSP.jQuery("#widget-div").length, 1, "test if the div has been added correctly");     
74
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    32
  });
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    33
 
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    34
  test("test play button event handler", function() {
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    35
    var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser);
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    36
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    37
    var spy_callback = this.spy();
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    38
    var spy_callback2 = this.spy();
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    39
    this.Popcorn.listen("play", spy_callback);
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    40
    this.Popcorn.listen("pause", spy_callback2);
83
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    41
    sinon.spy(player, "playHandler");
74
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    42
    
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    43
    player.draw();        
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    44
153
43f6de365ed4 general code cleanup.
hamidouk
parents: 151
diff changeset
    45
    player.selector.find("#ldt-CtrlPlay").trigger("click");    
43f6de365ed4 general code cleanup.
hamidouk
parents: 151
diff changeset
    46
    player.selector.find("#ldt-CtrlPlay").trigger("click");
83
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    47
    ok(player.playHandler.calledTwice, "play handler called");
74
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    48
    ok(spy_callback2.calledOnce, "test if pause callback has been called");                                                                    
83
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    49
  });
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    50
  
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    51
  test("test mute button event handler", function() {
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    52
    var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser);
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    53
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    54
    var spy_callback = this.spy();
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    55
    var spy_handler = sinon.spy(player, "muteHandler");
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    56
    this.Popcorn.listen("volumechange", spy_callback);    
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    57
    
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    58
    player.draw();
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    59
       
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    60
    // IriSP.jQuery("#ldt-CtrlSound").trigger("click");    
153
43f6de365ed4 general code cleanup.
hamidouk
parents: 151
diff changeset
    61
    player.selector.find(".Ldt-Control2 button:first").next().trigger("click");    
83
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    62
    ok(this.Popcorn.muted(), "the player is muted");
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    63
    
153
43f6de365ed4 general code cleanup.
hamidouk
parents: 151
diff changeset
    64
    player.selector.find("#ldt-CtrlSound").trigger("click");
83
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    65
    ok(!this.Popcorn.muted(), "the player is un muted");         
145
b477c9430d36 tests and implementation of the search button for the player.
hamidouk
parents: 134
diff changeset
    66
    ok(spy_handler.called, "handling function has been called");                                                                                                                                        
83
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    67
  });
1fb63a1a8ac3 various changes to unit tests.
hamidouk
parents: 74
diff changeset
    68
  
145
b477c9430d36 tests and implementation of the search button for the player.
hamidouk
parents: 134
diff changeset
    69
  test("test search button event handler", function() {
b477c9430d36 tests and implementation of the search button for the player.
hamidouk
parents: 134
diff changeset
    70
  var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser);
b477c9430d36 tests and implementation of the search button for the player.
hamidouk
parents: 134
diff changeset
    71
  
b477c9430d36 tests and implementation of the search button for the player.
hamidouk
parents: 134
diff changeset
    72
  var searchTerm = "blah";
b477c9430d36 tests and implementation of the search button for the player.
hamidouk
parents: 134
diff changeset
    73
  
b477c9430d36 tests and implementation of the search button for the player.
hamidouk
parents: 134
diff changeset
    74
  var spy_callback = this.spy();
151
dc2ff4c87490 some tweaking to make the search function more user-friendly.
hamidouk
parents: 145
diff changeset
    75
  var spy_open = this.spy();
dc2ff4c87490 some tweaking to make the search function more user-friendly.
hamidouk
parents: 145
diff changeset
    76
  var spy_closed = this.spy();
155
0ee6d3dd57d1 fixed test bug.
hamidouk
parents: 153
diff changeset
    77
  var spy_cleared = this.spy();
145
b477c9430d36 tests and implementation of the search button for the player.
hamidouk
parents: 134
diff changeset
    78
  var spy_handler = sinon.spy(player, "searchButtonHandler");
151
dc2ff4c87490 some tweaking to make the search function more user-friendly.
hamidouk
parents: 145
diff changeset
    79
  
145
b477c9430d36 tests and implementation of the search button for the player.
hamidouk
parents: 134
diff changeset
    80
  player._Popcorn.listen("IriSP.search", spy_callback);    
151
dc2ff4c87490 some tweaking to make the search function more user-friendly.
hamidouk
parents: 145
diff changeset
    81
  player._Popcorn.listen("IriSP.search.open", spy_open);    
dc2ff4c87490 some tweaking to make the search function more user-friendly.
hamidouk
parents: 145
diff changeset
    82
  player._Popcorn.listen("IriSP.search.closed", spy_closed);    
155
0ee6d3dd57d1 fixed test bug.
hamidouk
parents: 153
diff changeset
    83
  player._Popcorn.listen("IriSP.search.cleared", spy_cleared);    
145
b477c9430d36 tests and implementation of the search button for the player.
hamidouk
parents: 134
diff changeset
    84
  
b477c9430d36 tests and implementation of the search button for the player.
hamidouk
parents: 134
diff changeset
    85
  player.draw();
b477c9430d36 tests and implementation of the search button for the player.
hamidouk
parents: 134
diff changeset
    86
     
151
dc2ff4c87490 some tweaking to make the search function more user-friendly.
hamidouk
parents: 145
diff changeset
    87
  player.selector.find("#ldt-CtrlSearch").trigger("click");
dc2ff4c87490 some tweaking to make the search function more user-friendly.
hamidouk
parents: 145
diff changeset
    88
  player.selector.find("#LdtSearchInput").attr('value', searchTerm); 
dc2ff4c87490 some tweaking to make the search function more user-friendly.
hamidouk
parents: 145
diff changeset
    89
  player.selector.find("#LdtSearchInput").trigger('keyup');
145
b477c9430d36 tests and implementation of the search button for the player.
hamidouk
parents: 134
diff changeset
    90
  
b477c9430d36 tests and implementation of the search button for the player.
hamidouk
parents: 134
diff changeset
    91
  ok(spy_handler.called, "search button handling function has been called");  
151
dc2ff4c87490 some tweaking to make the search function more user-friendly.
hamidouk
parents: 145
diff changeset
    92
  ok(spy_open.called, "open signal has been sent");  
dc2ff4c87490 some tweaking to make the search function more user-friendly.
hamidouk
parents: 145
diff changeset
    93
  ok(spy_callback.called, "search typeahead function has been called");
dc2ff4c87490 some tweaking to make the search function more user-friendly.
hamidouk
parents: 145
diff changeset
    94
  ok(spy_callback.calledWith(searchTerm), "popcorn message sent with the right parameters");
dc2ff4c87490 some tweaking to make the search function more user-friendly.
hamidouk
parents: 145
diff changeset
    95
155
0ee6d3dd57d1 fixed test bug.
hamidouk
parents: 153
diff changeset
    96
  player.selector.find("#LdtSearchInput").attr('value', ""); 
0ee6d3dd57d1 fixed test bug.
hamidouk
parents: 153
diff changeset
    97
  player.selector.find("#LdtSearchInput").trigger('keyup');
0ee6d3dd57d1 fixed test bug.
hamidouk
parents: 153
diff changeset
    98
  ok(spy_cleared.called, "clear message has been sent");
0ee6d3dd57d1 fixed test bug.
hamidouk
parents: 153
diff changeset
    99
  
151
dc2ff4c87490 some tweaking to make the search function more user-friendly.
hamidouk
parents: 145
diff changeset
   100
  player.selector.find("#ldt-CtrlSearch").trigger("click");
dc2ff4c87490 some tweaking to make the search function more user-friendly.
hamidouk
parents: 145
diff changeset
   101
  ok(spy_closed.called, "closed signal has been sent");  
145
b477c9430d36 tests and implementation of the search button for the player.
hamidouk
parents: 134
diff changeset
   102
  
b477c9430d36 tests and implementation of the search button for the player.
hamidouk
parents: 134
diff changeset
   103
  });
155
0ee6d3dd57d1 fixed test bug.
hamidouk
parents: 153
diff changeset
   104
  
145
b477c9430d36 tests and implementation of the search button for the player.
hamidouk
parents: 134
diff changeset
   105
};