unittests/tests/segmentsWidget.js
author hamidouk
Fri, 21 Oct 2011 11:21:35 +0200
branchpopcorn-port
changeset 111 df08c7f9535c
parent 104 d571e9020092
child 157 73bce42a3ed3
permissions -rw-r--r--
added a basic layout manager.
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 */
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    10
    
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    11
    
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    12
    IriSP.jQuery("#widget-div").append("<div id='Ldt-Annotations'></div>");
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    13
    this.config = {
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    14
						metadata:{
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    15
							format:'cinelab',
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    16
							src:'test.json',
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    17
							load:'json'},
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    18
						gui:{
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    19
							width:650,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    20
							height:1,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    21
							mode:'radio',
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    22
							container:'widget-div',
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    23
							debug:true,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    24
							css:'../src/css/LdtPlayer.css'},
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    25
					};
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    26
    },
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    27
  teardown: function() {
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    28
    /* 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
    29
    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
    30
  }
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    31
  });
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    32
  
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    33
  test("test widget initialization", function() {  
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    34
    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
    35
    widget.draw();
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    36
  
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    37
    equal(IriSP.jQuery("#Ldt-Annotations").length, 1, "test if the div has been added correctly");
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    38
    equal(IriSP.jQuery("#Ldt-Annotations").children().length, this.ser._data.annotations.length, "test if children have been added correctly");     
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    39
  });
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    40
  
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    41
  test("test click on a random segment", function() {
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    42
    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
    43
    widget.draw();
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    44
    
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    45
    var spy_callback = this.spy();
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    46
    var spy_handler = sinon.spy(widget, "clickHandler");
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    47
    this.Popcorn.listen("timeupdate", spy_callback);    
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    48
    
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    49
    var selector = IriSP.jQuery("#Ldt-Annotations :not(first-child)");
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    50
    var random = Math.round(Math.random() * selector.length);
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    51
    selector.eq(random).click();
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    52
        
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    53
    ok(spy_callback.called, "the currenttime was changed");         
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    54
    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
    55
  });
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    56
};