unittests/tests/widgets/sliderWidget.js
author hamidouk
Wed, 16 Nov 2011 17:04:35 +0100
branchpopcorn-port
changeset 259 7d748154f0b5
parent 234 43b198dc932d
child 318 463382f92211
permissions -rw-r--r--
working implementation and tests of the slider.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
234
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
     1
function test_slider_widget() {
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
     2
 module("slider widget testing", 
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
     3
  {setup : function() {    
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
     4
    this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4");
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
     5
    
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
     6
    this.dt = new IriSP.DataLoader();
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
     7
    this.ser = new IriSP.MockSerializer(this.dt, "/url"); /* dummy serializer */
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
     8
            
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
     9
    this.config = {
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    10
						metadata:{
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    11
							format:'cinelab',
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    12
							src:'test.json',
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    13
							load:'json'},
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    14
							width:650,
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    15
							height:1,
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    16
							mode:'radio',
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    17
							container:'widget-div',
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    18
							debug:true,
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    19
							css:'../src/css/LdtPlayer.css'}
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    20
    },  
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    21
  teardown: function() {
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    22
    /* free the popcorn object because it has signal handlers attached to it */
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    23
    this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4");
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    24
  }});
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    25
  
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    26
  test("test widget initialization", function() {  
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    27
    var widget = new IriSP.SliderWidget(this.Popcorn, this.config, this.ser);    
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    28
    widget.draw();
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    29
    
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    30
    ok(IriSP.jQuery("#widget-div").children().hasClass("sliderBackground"), "test if the div has been set-up");
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    31
    ok(IriSP.jQuery("#widget-div").children().hasClass("sliderForeground"), "test if the div has been set-up");
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    32
  
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    33
  });
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    34
  
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    35
  test("test slider seeking", function() {    
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    36
    var widget = new IriSP.SliderWidget(this.Popcorn, this.config, this.ser);    
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    37
    widget.draw();
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    38
    
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    39
    var spy_callback = this.spy();
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    40
    widget._Popcorn.listen("timeupdate", spy_callback);       
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    41
    IriSP.jQuery("#widget-div").children().click();
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    42
    ok(spy_callback.called, "handling function has been called");
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    43
  });
259
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    44
  
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    45
    test("test slider dragging", function() {
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    46
    
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    47
    /* comes from the jquery unit tests */
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    48
    var drag = function(handle, dx, dy) {
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    49
      var element = el.data("draggable").element;
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    50
      $(handle).simulate("drag", {
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    51
        dx: dx || 0,
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    52
        dy: dy || 0
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    53
      });
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    54
      dragged = { dx: dx, dy: dy };
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    55
    }    
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    56
    
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    57
    var widget = new IriSP.SliderWidget(this.Popcorn, this.config, this.ser);    
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    58
    widget.draw();
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    59
    
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    60
    var spy_callback = this.spy();
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    61
    widget._Popcorn.listen("timeupdate", spy_callback);
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    62
    
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    63
    IriSP.jQuery("#widget-div").children(".positionMarker").simulate("drag", 70, 50);
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    64
    ok(spy_callback.called, "handling function has been called");
7d748154f0b5 working implementation and tests of the slider.
hamidouk
parents: 234
diff changeset
    65
  });
234
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    66
}