unittests/tests/polemicWidget.js
author hamidouk
Fri, 04 Nov 2011 16:08:25 +0100
branchpopcorn-port
changeset 196 9fb4dcb0b878
parent 186 7a963ec3e09a
permissions -rw-r--r--
"fixed" a test and added a new array to contain references to the raphael nodes we create.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
186
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
     1
/* polemicWidget.js */
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
     2
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
     3
function test_polemic_widget() {
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
     4
  module("polemic widget testing", 
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
     5
  {setup : function() {    
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
     6
    this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4");
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
     7
    
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
     8
    this.dt = new IriSP.DataLoader();
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
     9
    this.ser = new IriSP.MockTweetSerializer(this.dt, "/url"); /* dummy serializer */
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    10
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    11
    IriSP.jQuery("#widget-div").append("<div id='TooltipDiv'></div>");
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    12
    IriSP.jQuery("#widget-div").append("<div id='PolemicDiv'></div>");
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    13
    this.config = {
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    14
						metadata:{
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    15
							format:'cinelab',
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    16
							src:'test.json',
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    17
							load:'json'},
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    18
							width:650,
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    19
							height:1,
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    20
							mode:'radio',
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    21
							container:'PolemicDiv',
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    22
							debug:true,
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    23
							css:'../src/css/LdtPlayer.css',
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    24
            requires: [{
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    25
							type: "TooltipWidget",
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    26
              container: "TooltipDiv",
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    27
							width: 180,
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    28
							heigh: 160,
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    29
							metadata : {
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    30
								format:'cinelab',
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    31
								type:'empty'
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    32
							}
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    33
						 }]
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    34
    }
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    35
    },  
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    36
  teardown: function() {
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    37
    /* free the popcorn object because it has signal handlers attached to it */
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    38
    this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4");
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    39
  }});
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    40
  
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    41
  test("test widget initialization", function() {
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    42
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    43
    var tooltip = new IriSP.TooltipWidget(this.Popcorn, this.config.requires[0], this.ser);
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    44
    var widget = new IriSP.PolemicWidget(this.Popcorn, this.config, this.ser);
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    45
    widget.TooltipWidget = tooltip;
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    46
    
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    47
    widget.draw();    
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    48
    equal(IriSP.jQuery("#widget-div").length, 1, "test if the div has been added correctly");        
196
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    49
    equal(IriSP.jQuery("#PolemicDiv svg").length, 1, "test if svg div has been added correctly");
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    50
    
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    51
    // select the second element of the svg. the second because the first is a rect which serves
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    52
    // as a background.
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    53
    var paperSlider = IriSP.jQuery("#PolemicDiv svg :nth-child(2)");
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    54
    // querying svg with jquery is quite the piece of cake.
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    55
    equal(paperSlider.attr("x").baseVal.value, 0, "test if the slider has been created correctly");            
186
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    56
  });
196
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    57
  
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    58
  test("test widget interactions", function() {
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    59
  
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    60
    /* We can't test interactions because of raphael */
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    61
    // var tooltip = new IriSP.TooltipWidget(this.Popcorn, this.config.requires[0], this.ser);
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    62
    // var widget = new IriSP.PolemicWidget(this.Popcorn, this.config, this.ser);
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    63
    
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    64
    // widget.TooltipWidget = tooltip;
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    65
    // widget.draw();
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    66
    
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    67
    // var spy_callback = this.spy();    
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    68
    // this.Popcorn.listen("timeupdate", spy_callback);
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    69
    
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    70
    // var random = Math.round(Math.random() * widget.svgElements.length) + 1;
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    71
    // var e = widget.svgElements[random].node;
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    72
    // IriSP.jQuery(e).click();
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    73
    
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    74
    // ok(spy_callback.called, "the currenttime was changed");  
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    75
    
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    76
  });
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    77
  
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 186
diff changeset
    78
  
186
7a963ec3e09a added tests for the polemicWidget.
hamidouk
parents:
diff changeset
    79
};