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