unittests/tests/widgets/segmentsWidget.js
branchpopcorn-port
changeset 234 43b198dc932d
child 304 a938013fc6ea
equal deleted inserted replaced
233:126de77ee73e 234:43b198dc932d
       
     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     this.config = {
       
    12 						metadata:{
       
    13 							format:'cinelab',
       
    14 							src:'test.json',
       
    15 							load:'json'},
       
    16 							width:650,
       
    17 							height:1,
       
    18 							mode:'radio',
       
    19 							container:'widget-div',
       
    20 							debug:true,
       
    21 							css:'../src/css/LdtPlayer.css'}
       
    22     },  
       
    23   teardown: function() {
       
    24     /* free the popcorn object because it has signal handlers attached to it */
       
    25     this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4");
       
    26   }});
       
    27   
       
    28   test("test widget initialization", function() {  
       
    29     var widget = new IriSP.SegmentsWidget(this.Popcorn, this.config, this.ser);    
       
    30     widget.draw();
       
    31   
       
    32     equal(IriSP.jQuery("#widget-div").length, 1, "test if the div has been added correctly");
       
    33     // the + 1 is because we have a z-index div to indicate progress in the video.
       
    34     equal(IriSP.jQuery("#widget-div").children().length, this.ser._data.annotations.length + 1, "test if children have been added correctly");
       
    35     equal(IriSP.jQuery("#widget-div").children(":first").css("z-index"), 100, "test if slider div is created correctly.");
       
    36     equal(IriSP.jQuery("#widget-div").css("overflow"), "auto", "test if the divs are floated correctly.");
       
    37   });
       
    38   
       
    39   test("test click on a random segment", function() {
       
    40     var widget = new IriSP.SegmentsWidget(this.Popcorn, this.config, this.ser);
       
    41     widget.draw();
       
    42     
       
    43     var spy_callback = this.spy();
       
    44     var spy_handler = sinon.spy(widget, "clickHandler");
       
    45     this.Popcorn.listen("timeupdate", spy_callback);    
       
    46     
       
    47     var selector = IriSP.jQuery("#widget-div :not(first-child)");
       
    48     var random = Math.round(Math.random() * selector.length) + 1;
       
    49     selector.eq(random).click();
       
    50         
       
    51     ok(spy_callback.called, "the currenttime was changed");         
       
    52     ok(spy_handler.called, "handling function has been called");           
       
    53   });
       
    54   
       
    55   test("test search highlight features", function() {
       
    56   
       
    57     var tag_id = "#s_" + "82613B88-9578-DC2C-D7D0-B2C5BE0B7BDA".toUpperCase();
       
    58     
       
    59     var widget = new IriSP.SegmentsWidget(this.Popcorn, this.config, this.ser);
       
    60     widget.draw();    
       
    61 
       
    62     var oldStyle = IriSP.jQuery("#widget-div").children(tag_id).attr("style");
       
    63     widget._Popcorn.trigger("IriSP.search", "sociologie");
       
    64     var newStyle = IriSP.jQuery("#widget-div").children(tag_id).attr("style");
       
    65     notEqual(oldStyle, newStyle, "the segment style has been modified");
       
    66   });
       
    67 };