From 7b5d0a51abf496655fc2235608d5e1aad05c2dd6 Mon Sep 17 00:00:00 2001 From: dseif Date: Mon, 7 Mar 2011 14:00:31 -0800 Subject: [PATCH] Adding unit tests, and some error checking and such --- plugins/googlefeed/popcorn.googlefeed.js | 9 ++- .../googlefeed/popcorn.googlefeed.unit.html | 44 ++++++++++++ plugins/googlefeed/popcorn.googlefeed.unit.js | 68 +++++++++++++++++++ 3 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 plugins/googlefeed/popcorn.googlefeed.unit.html create mode 100644 plugins/googlefeed/popcorn.googlefeed.unit.js diff --git a/plugins/googlefeed/popcorn.googlefeed.js b/plugins/googlefeed/popcorn.googlefeed.js index 084259a..2ef2da3 100644 --- a/plugins/googlefeed/popcorn.googlefeed.js +++ b/plugins/googlefeed/popcorn.googlefeed.js @@ -26,7 +26,8 @@ */ var _feedFired = false, - _feedLoaded = false; + _feedLoaded = false, + i = 1; // insert google api and dynamic feed control script once, as well as the dynamic feed css file if ( !_feedFired ) { @@ -50,6 +51,10 @@ // that already exists in the parent div gets overwritten var newdiv = document.createElement( "div" ); newdiv.style.display = "none"; + newdiv.id = "_feed"+i; + newdiv.style.width = "100%"; + newdiv.style.height = "100%"; + i++; if ( document.getElementById( options.target ) ) { document.getElementById( options.target ).appendChild( newdiv ); } @@ -81,7 +86,6 @@ */ start: function( event, options ){ newdiv.setAttribute( "style", "display:inline" ); - // Default to vertical orientation if empty or incorrect input if( !options.orientation || ( options.orientation.toLowerCase() != "vertical" && options.orientation.toLowerCase() != "horizontal" ) ) { @@ -115,4 +119,5 @@ orientation : { elem:"input", type:"text", label:"orientation" } } }); + })( Popcorn ); diff --git a/plugins/googlefeed/popcorn.googlefeed.unit.html b/plugins/googlefeed/popcorn.googlefeed.unit.html new file mode 100644 index 0000000..15ad19a --- /dev/null +++ b/plugins/googlefeed/popcorn.googlefeed.unit.html @@ -0,0 +1,44 @@ + + + + Popcorn API + + + + + + + + + + +

Popcorn Google Feed Plugin

+

+
+

+
    +
    + + +
    +
    + + diff --git a/plugins/googlefeed/popcorn.googlefeed.unit.js b/plugins/googlefeed/popcorn.googlefeed.unit.js new file mode 100644 index 0000000..108f332 --- /dev/null +++ b/plugins/googlefeed/popcorn.googlefeed.unit.js @@ -0,0 +1,68 @@ +test("Popcorn Google Feed Plugin", function () { + + var popped = Popcorn("#video"), + expects = 10, + count = 0; + + console.log(expects); + + expect(expects); + + function plus() { + if ( ++count===expects) { + start(); + } + } + + stop(); + + ok ('googlefeed' in popped, "googlefeed is a method of the popped instance"); + plus(); + ok ( document.getElementById('feed').innerHTML === "", "initially, there is nothing inside the feed" ); + plus(); + ok ( document.getElementById('feed1').innerHTML === "", "initially, there is nothing inside the feed1" ); + plus(); + + popped.googlefeed({ + start: 0, // seconds + end: 5, // seconds + target: "feed", + url: "http://zenit.senecac.on.ca/~chris.tyler/planet/rss20.xml", + title: "Planet Feed", + orientation: "Vertical" + } ) + .googlefeed({ + start: 0, // seconds + end: 5, // seconds + target: "feed1", + url: "http://blog.pikimal.com/geek/feed/", + title: "pikiGeek", + orientation: "Horizontal" + } ) + .volume(0); + + popped.exec( 1, function() { + ok(google.load, "Google Feed is available"); + plus(); + ok(GFdynamicFeedControl, "Dynamic Feed Control Available"); + plus(); + ok (document.getElementById('_feed1'), "First feed is on the page" ); + plus(); + equals (document.getElementById('_feed1').offsetParent.id, "feed", "First feed is inside the 'feed' div" ); + plus(); + }); + popped.exec( 2, function() { + ok (document.getElementById('_feed2'), "Second feed is on the page" ); + plus(); + equals (document.getElementById('_feed2').offsetParent.id, "feed1", "Second feed is inside the 'feed2' div" ); + plus(); + }); + popped.exec( 6, function() { + ok (document.getElementById('_feed2').style.display === "none" && + document.getElementById('_feed1').style.display === "none", "Both feeds are no lnger visible" ); + plus(); + }); + + popped.play(); + +}); -- 2.43.0