unittests/tests/segmentsWidget.js
author hamidouk
Wed, 09 Nov 2011 17:06:23 +0100
branchpopcorn-port
changeset 217 ec3e6d34462c
parent 164 d335ee5533c5
child 219 12a72b00f4ab
permissions -rw-r--r--
fixed css positioning bug.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
     1
/* segmentsWidget.js */
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
     2
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
     3
function test_segments_widget() {
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
     4
  module("segments widget testing", 
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
     5
  {setup : function() {    
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
     6
    this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4");
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
     7
    
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
     8
    this.dt = new IriSP.DataLoader();
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
     9
    this.ser = new IriSP.MockSerializer(this.dt, "/url"); /* dummy serializer */
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    10
            
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    11
    this.config = {
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    12
						metadata:{
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    13
							format:'cinelab',
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    14
							src:'test.json',
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    15
							load:'json'},
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    16
							width:650,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    17
							height:1,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    18
							mode:'radio',
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    19
							container:'widget-div',
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    20
							debug:true,
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    21
							css:'../src/css/LdtPlayer.css'}
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    22
    },  
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    23
  teardown: function() {
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    24
    /* free the popcorn object because it has signal handlers attached to it */
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    25
    this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4");
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    26
  }});
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    27
  
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    28
  test("test widget initialization", function() {  
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    29
    var widget = new IriSP.SegmentsWidget(this.Popcorn, this.config, this.ser);    
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    30
    widget.draw();
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    31
  
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    32
    equal(IriSP.jQuery("#widget-div").length, 1, "test if the div has been added correctly");
217
ec3e6d34462c fixed css positioning bug.
hamidouk
parents: 164
diff changeset
    33
    // the + 1 is because we have a z-index div to indicate progress in the video.
ec3e6d34462c fixed css positioning bug.
hamidouk
parents: 164
diff changeset
    34
    equal(IriSP.jQuery("#widget-div").children().length, this.ser._data.annotations.length + 1, "test if children have been added correctly");
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    35
  });
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    36
  
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    37
  test("test click on a random segment", function() {
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    38
    var widget = new IriSP.SegmentsWidget(this.Popcorn, this.config, this.ser);
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    39
    widget.draw();
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    40
    
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    41
    var spy_callback = this.spy();
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    42
    var spy_handler = sinon.spy(widget, "clickHandler");
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    43
    this.Popcorn.listen("timeupdate", spy_callback);    
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    44
    
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    45
    var selector = IriSP.jQuery("#widget-div :not(first-child)");
157
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    46
    var random = Math.round(Math.random() * selector.length) + 1;
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    47
    selector.eq(random).click();
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    48
        
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    49
    ok(spy_callback.called, "the currenttime was changed");         
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    50
    ok(spy_handler.called, "handling function has been called");           
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    51
  });
157
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    52
  
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    53
  test("test search highlight features", function() {
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    54
  
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    55
    var tag_id = "#s_" + "82613B88-9578-DC2C-D7D0-B2C5BE0B7BDA".toUpperCase();
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    56
    
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    57
    var widget = new IriSP.SegmentsWidget(this.Popcorn, this.config, this.ser);
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    58
    widget.draw();    
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    59
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    60
    var oldStyle = IriSP.jQuery("#widget-div").children(tag_id).attr("style");
157
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    61
    widget._Popcorn.trigger("IriSP.search", "sociologie");
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    62
    var newStyle = IriSP.jQuery("#widget-div").children(tag_id).attr("style");
157
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    63
    notEqual(oldStyle, newStyle, "the segment style has been modified");
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    64
  });
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    65
};