1 /* tweetsWidget.js */ |
|
2 |
|
3 function test_tweets_widget() { |
|
4 module("tweet widget testing", |
|
5 {setup : function() { |
|
6 this.Popcorn = Popcorn("#popcorn-div"); |
|
7 |
|
8 this.dt = new IriSP.DataLoader(); |
|
9 this.ser = new IriSP.MockTweetSerializer(this.dt, "/url"); /* dummy serializer */ |
|
10 |
|
11 this.config = { |
|
12 width:650, |
|
13 height:1, |
|
14 mode:'radio', |
|
15 container:'widget-div', |
|
16 debug:true, |
|
17 css:'../src/css/LdtPlayer.css'}; |
|
18 }, |
|
19 teardown: function() { |
|
20 /* free the popcorn object because it has signal handlers attached to it */ |
|
21 this.Popcorn = Popcorn("#popcorn-div"); |
|
22 } |
|
23 }); |
|
24 |
|
25 test("test widget initialization", function() { |
|
26 var widget = new IriSP.TweetsWidget(this.Popcorn, this.config, this.ser); |
|
27 widget.draw(); |
|
28 |
|
29 equal(widget.selector.find(".Ldt-tweetAvatar").length, 1, "test if the div has been added correctly"); |
|
30 equal(widget.selector.find(".Ldt-tweetContents").length, 1, "test if sub-div has been added correctly"); |
|
31 }); |
|
32 |
|
33 test("test tweet display function", function() { |
|
34 // tweak the display period so that our tests don't timeout |
|
35 IriSP.widgetsDefaults.TweetsWidget.tweet_display_period = 10; |
|
36 |
|
37 var widget = new IriSP.TweetsWidget(this.Popcorn, this.config, this.ser); |
|
38 widget.draw(); |
|
39 var annotation = {content: |
|
40 {"title": "title", "description": "description", "keywords": "keywords", "img": {"src" : "http://yop.com"}}, |
|
41 meta: {"dc:source" : {}} |
|
42 }; |
|
43 widget.displayTweet(annotation); |
|
44 |
|
45 equal(widget.selector.find(".Ldt-tweetContents").text(), "title", "title set correctly"); |
|
46 equal(widget.selector.find(".Ldt-tweetAvatar").children().attr("src"), "http://yop.com", "user avatar set correctly"); |
|
47 |
|
48 var annotation2 = {content: {"title": "title", "description": "description", "keywords": "keywords", "img" : {}}, meta: {"dc:source" : {}}}; |
|
49 widget.displayTweet(annotation2); |
|
50 equal(widget.selector.find(".Ldt-tweetAvatar").children().attr("src"), |
|
51 IriSP.widgetsDefaults.TweetsWidget.default_profile_picture, "default avatar set correctly"); |
|
52 |
|
53 widget.selector.find(".Ldt-tweetWidgetKeepOpen").click(); |
|
54 ok(widget._timeoutId === null, "the timeout is cancelled"); |
|
55 widget.selector.find(".Ldt-tweetWidgetMinimize").click(); |
|
56 |
|
57 widget.displayTweet(annotation2); |
|
58 |
|
59 ok(!widget.selector.is(":visible"), "the widget is hidden after a click"); |
|
60 }); |
|
61 |
|
62 test("test async clear", function() { |
|
63 /* |
|
64 expect(1); |
|
65 |
|
66 // tweak the display period so that our tests don't timeout |
|
67 IriSP.widgetsDefaults.TweetsWidget.tweet_display_period = 10; |
|
68 stop(); |
|
69 |
|
70 var widget = new IriSP.TweetsWidget(this.Popcorn, this.config, this.ser); |
|
71 widget.draw(); |
|
72 var annotation = {content: {"title": "title", "description": "description", "keywords": "keywords", "img": {"src" : "http://yop.com"}}}; |
|
73 widget.displayTweet(annotation); |
|
74 |
|
75 |
|
76 window.setTimeout(function() { console.log("called!"); |
|
77 ok(!widget.selector.is(":visible"), "the widget is hidden after the timeout has passed."); |
|
78 start(); |
|
79 }, 100); |
|
80 */ |
|
81 }); |
|
82 }; |
|