unittests/tests/segmentsWidget.js
author hamidouk
Fri, 28 Oct 2011 16:51:35 +0200
branchpopcorn-port
changeset 164 d335ee5533c5
parent 157 73bce42a3ed3
child 217 ec3e6d34462c
permissions -rw-r--r--
cosmetic changes.
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");
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    33
    equal(IriSP.jQuery("#widget-div").children().length, this.ser._data.annotations.length, "test if children have been added correctly");
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    34
  });
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    35
  
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    36
  test("test click on a random segment", function() {
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    37
    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
    38
    widget.draw();
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    39
    
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    40
    var spy_callback = this.spy();
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    41
    var spy_handler = sinon.spy(widget, "clickHandler");
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    42
    this.Popcorn.listen("timeupdate", spy_callback);    
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    43
    
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    44
    var selector = IriSP.jQuery("#widget-div :not(first-child)");
157
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    45
    var random = Math.round(Math.random() * selector.length) + 1;
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    46
    selector.eq(random).click();
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    47
        
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    48
    ok(spy_callback.called, "the currenttime was changed");         
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    49
    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
    50
  });
157
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    51
  
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    52
  test("test search highlight features", function() {
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    53
  
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    54
    var tag_id = "#s_" + "82613B88-9578-DC2C-D7D0-B2C5BE0B7BDA".toUpperCase();
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    55
    
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    56
    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
    57
    widget.draw();    
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    58
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    59
    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
    60
    widget._Popcorn.trigger("IriSP.search", "sociologie");
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    61
    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
    62
    notEqual(oldStyle, newStyle, "the segment style has been modified");
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 104
diff changeset
    63
  });
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    64
};