unittests/tests/widgets/sliderWidget.js
author hamidouk
Thu, 24 Nov 2011 11:42:54 +0100
branchpopcorn-port
changeset 318 463382f92211
parent 259 7d748154f0b5
child 427 440ffc18f827
permissions -rw-r--r--
fixed unit tests to follow name changes in css classes. also fixed line endings, which where botched, courtesy of np++.
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
}