unittests/tests/widgets/segmentsWidget.js
changeset 944 8a6c9e3d0158
parent 907 27b248a13355
parent 943 a882cc0c936f
child 945 7d9f6fd6f904
equal deleted inserted replaced
907:27b248a13355 944:8a6c9e3d0158
     1 /* segmentsWidget.js */
       
     2 
       
     3 function test_segments_widget() {
       
     4   module("segments 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             
       
    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("#popcorn-div");
       
    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_timeupdate = this.spy();
       
    44     var spy_segmentClick = this.spy();
       
    45     var spy_handler = sinon.spy(widget, "clickHandler");
       
    46     this.Popcorn.listen("timeupdate", spy_timeupdate);    
       
    47     
       
    48     var selector = IriSP.jQuery("#widget-div :not(first-child)");
       
    49     var random = Math.round(Math.random() * selector.length) + 1;
       
    50     selector.eq(12).click();
       
    51         
       
    52     ok(spy_timeupdate.called, "the timeupdate signal has been sent");         
       
    53     ok(spy_handler.called, "handling function has been called");           
       
    54   });
       
    55 
       
    56   test("test search highlight features", function() {
       
    57   
       
    58     var tag_id = "#s_" + "82613B88-9578-DC2C-D7D0-B2C5BE0B7BDA".toUpperCase();
       
    59     
       
    60     var widget = new IriSP.SegmentsWidget(this.Popcorn, this.config, this.ser);
       
    61     widget.draw();    
       
    62 
       
    63     var oldStyle = IriSP.jQuery("#widget-div").children(tag_id).attr("style");
       
    64     widget._Popcorn.trigger("IriSP.search", "sociologie");
       
    65     var newStyle = IriSP.jQuery("#widget-div").children(tag_id).attr("style");
       
    66     notEqual(oldStyle, newStyle, "the segment style has been modified");
       
    67   });
       
    68 };