unittests/tests/widgets/tweetsWidget.js
author hamidouk
Mon, 19 Dec 2011 15:25:22 +0100
branchpopcorn-port
changeset 481 a46cfeee6d77
parent 427 440ffc18f827
permissions -rw-r--r--
using jquery ui draggable changes the state of an element from absolute to relative positioning, which breaks the way our seek button expands itself, so we need to force absolute positioning, quite uglily, using jquery.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
267
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
     1
/* tweetsWidget.js */
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
     2
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
     3
function test_tweets_widget() {
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
     4
  module("tweet widget testing", 
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
     5
  {setup : function() {    
427
440ffc18f827 changed the unit tests to reference a local video instead of youtube.
hamidouk
parents: 378
diff changeset
     6
    this.Popcorn = Popcorn("#popcorn-div");
267
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
     7
    
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
     8
    this.dt = new IriSP.DataLoader();
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
     9
    this.ser = new IriSP.MockTweetSerializer(this.dt, "/url"); /* dummy serializer */
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    10
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    11
    this.config = {
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    12
							width:650,
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    13
							height:1,
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    14
							mode:'radio',
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    15
							container:'widget-div',
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    16
							debug:true,
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    17
							css:'../src/css/LdtPlayer.css'};
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    18
    },
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    19
  teardown: function() {
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    20
    /* free the popcorn object because it has signal handlers attached to it */
427
440ffc18f827 changed the unit tests to reference a local video instead of youtube.
hamidouk
parents: 378
diff changeset
    21
    this.Popcorn = Popcorn("#popcorn-div");
267
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    22
  }
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    23
  });
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    24
  
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    25
  test("test widget initialization", function() {  
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    26
    var widget = new IriSP.TweetsWidget(this.Popcorn, this.config, this.ser);    
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    27
    widget.draw();
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    28
283
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    29
    equal(widget.selector.find(".Ldt-tweetAvatar").length, 1, "test if the div has been added correctly");
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    30
    equal(widget.selector.find(".Ldt-tweetContents").length, 1, "test if sub-div has been added correctly");
267
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    31
  });
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    32
  
283
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    33
  test("test tweet display function", function() {    
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    34
    // tweak the display period so that our tests don't timeout
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    35
    IriSP.widgetsDefaults.TweetsWidget.tweet_display_period = 10;
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    36
    
267
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    37
    var widget = new IriSP.TweetsWidget(this.Popcorn, this.config, this.ser);    
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    38
    widget.draw();
298
eccdc619ede3 fixes a display bug because mustache escapes html by default.
hamidouk
parents: 283
diff changeset
    39
    var annotation = {content: 
eccdc619ede3 fixes a display bug because mustache escapes html by default.
hamidouk
parents: 283
diff changeset
    40
                        {"title": "title", "description": "description", "keywords": "keywords", "img": {"src" : "http://yop.com"}},
eccdc619ede3 fixes a display bug because mustache escapes html by default.
hamidouk
parents: 283
diff changeset
    41
                      meta: {"dc:source" : {}}
eccdc619ede3 fixes a display bug because mustache escapes html by default.
hamidouk
parents: 283
diff changeset
    42
                     };
267
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    43
    widget.displayTweet(annotation);
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    44
    
283
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    45
    equal(widget.selector.find(".Ldt-tweetContents").text(), "title", "title set correctly");    
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    46
    equal(widget.selector.find(".Ldt-tweetAvatar").children().attr("src"), "http://yop.com", "user avatar set correctly");
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    47
    
298
eccdc619ede3 fixes a display bug because mustache escapes html by default.
hamidouk
parents: 283
diff changeset
    48
    var annotation2 = {content: {"title": "title", "description": "description", "keywords": "keywords", "img" : {}}, meta: {"dc:source" : {}}};
283
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    49
    widget.displayTweet(annotation2);
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    50
    equal(widget.selector.find(".Ldt-tweetAvatar").children().attr("src"), 
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    51
                               IriSP.widgetsDefaults.TweetsWidget.default_profile_picture, "default avatar set correctly");
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    52
    
378
110311d59b2f implemented a second button to keep the tweetWidget open.
hamidouk
parents: 298
diff changeset
    53
    widget.selector.find(".Ldt-tweetWidgetKeepOpen").click();
110311d59b2f implemented a second button to keep the tweetWidget open.
hamidouk
parents: 298
diff changeset
    54
    ok(widget._timeoutId === null, "the timeout is cancelled");
283
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    55
    widget.selector.find(".Ldt-tweetWidgetMinimize").click();
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    56
    
378
110311d59b2f implemented a second button to keep the tweetWidget open.
hamidouk
parents: 298
diff changeset
    57
    widget.displayTweet(annotation2);
110311d59b2f implemented a second button to keep the tweetWidget open.
hamidouk
parents: 298
diff changeset
    58
    
283
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    59
    ok(!widget.selector.is(":visible"), "the widget is hidden after a click");    
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    60
  });
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    61
  
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    62
  test("test async clear", function() {
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    63
  /*
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    64
    expect(1);
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    65
    
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    66
    // tweak the display period so that our tests don't timeout
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    67
    IriSP.widgetsDefaults.TweetsWidget.tweet_display_period = 10;
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    68
    stop();
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    69
    
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    70
    var widget = new IriSP.TweetsWidget(this.Popcorn, this.config, this.ser);    
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    71
    widget.draw();
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    72
    var annotation = {content: {"title": "title", "description": "description", "keywords": "keywords", "img": {"src" : "http://yop.com"}}};
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    73
    widget.displayTweet(annotation);
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    74
  
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    75
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    76
    window.setTimeout(function() { console.log("called!"); 
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    77
      ok(!widget.selector.is(":visible"), "the widget is hidden after the timeout has passed."); 
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    78
      start(); 
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    79
      }, 100);
39e6707ca72b more tests.
hamidouk
parents: 267
diff changeset
    80
  */
267
f84013fb19dc added a new widget, to display the contents of tweets in a separate pane.
hamidouk
parents:
diff changeset
    81
  });
378
110311d59b2f implemented a second button to keep the tweetWidget open.
hamidouk
parents: 298
diff changeset
    82
};