From: Anna Sobiepanek Date: Sun, 19 Dec 2010 19:40:53 +0000 (-0500) Subject: starting tests X-Git-Tag: v0.2~24^2~5 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=3821b595bdd9ee5da9fa4aae18c96aa6852e46a6;p=popcorn-js.git starting tests --- diff --git a/plugins/wikipedia/popcorn.wikipedia.html b/plugins/wikipedia/popcorn.wikipedia.html index 6d45ed7..b85d4b5 100644 --- a/plugins/wikipedia/popcorn.wikipedia.html +++ b/plugins/wikipedia/popcorn.wikipedia.html @@ -11,10 +11,16 @@ .volume(0) .play() .wikipedia({ - start: 10, // seconds - end: 50, // seconds + start: 5, // seconds + end: 10, // seconds src: 'http://en.wikipedia.org/wiki/Cape_Town', target: 'wikidiv' + } ) + .wikipedia({ + start: 12, // seconds + end: 20, // seconds + src: 'http://en.wikipedia.org/wiki/S%C3%A3o_Paulo', + target: 'wikidiv2' } ); }, false); @@ -23,11 +29,11 @@

Popcorn WebPage Plug-in Demo

-

A Webpage displaying webmademovies.org will appear at 5 seconds and disappear at 15 seconds.

-

A Webpage displaying zenit Processing.js wiki will appear at 20 seconds and disappear at 45 seconds.

+

A Wiki article about Cape Town will appear at 5 seconds and disappear at 10 seconds.

+

A Wiki article about Sao Paolo will appear at 12 seconds and disappear at 20 seconds.

+ +
+
diff --git a/plugins/wikipedia/popcorn.wikipedia.js b/plugins/wikipedia/popcorn.wikipedia.js index 722c6f2..03510e0 100644 --- a/plugins/wikipedia/popcorn.wikipedia.js +++ b/plugins/wikipedia/popcorn.wikipedia.js @@ -1,12 +1,7 @@ // PLUGIN: WIKIPEDIA -// wikipedia callback functions executes when data is retrieved from the wiki -// stores the data in a global variable -var wikidatastring; -var wikiCallback = function (data) { - wikidatastring = data; -}; +var wikiCallback; (function (Popcorn) { @@ -61,28 +56,22 @@ var wikiCallback = function (data) { var getJson = function(url) { var head = document.getElementsByTagName("head")[0]; var script = document.createElement("script"); - // once you get the data store it - script.onload = function () { - if (wikidatastring) { - // create a link that the user can use to view the whole article - link = document.createElement('a'); - link.setAttribute('href', options.src); - link.setAttribute('target', '_blank'); - // create a paragraph that the title of the article can go into - p = document.createElement('p'); - p.innerHTML = wikidatastring.parse.displaytitle; - link.appendChild(p); - // get the first 140 characters of the wiki content - desc = document.createElement('p'); - text = wikidatastring.parse.text["*"].substr(wikidatastring.parse.text["*"].indexOf('

')); - text = text.replace(/((<(.|\n)+?>)|(\((.*?)\) )|(\[(.*?)\]))/g, ""); - desc.innerHTML = text.substr(0, length ) + " ..."; - } - }; script.src = url; head.insertBefore( script, head.firstChild ); }; - + wikiCallback = function (data) { + wikidatastring = data; + link = document.createElement('a'); + link.setAttribute('href', options.src); + link.setAttribute('target', '_blank'); + // add the title of the article to the link + link.innerHTML = wikidatastring.parse.displaytitle; + // get the content of the wiki article + desc = document.createElement('p'); + text = wikidatastring.parse.text["*"].substr(wikidatastring.parse.text["*"].indexOf('

')); + text = text.replace(/((<(.|\n)+?>)|(\((.*?)\) )|(\[(.*?)\]))/g, ""); + desc.innerHTML = text.substr(0, length ) + " ..."; + }; }, /** * @member wikipedia diff --git a/plugins/wikipedia/popcorn.wikipedia.unit.html b/plugins/wikipedia/popcorn.wikipedia.unit.html index 238ff9d..43cdc4b 100644 --- a/plugins/wikipedia/popcorn.wikipedia.unit.html +++ b/plugins/wikipedia/popcorn.wikipedia.unit.html @@ -10,12 +10,12 @@ --> - + - + -

Popcorn Webpage UI

+

Popcorn wikipedia UI

@@ -23,7 +23,7 @@
-
+
diff --git a/plugins/wikipedia/popcorn.wikipedia.unit.js b/plugins/wikipedia/popcorn.wikipedia.unit.js index a402670..d4e2606 100644 --- a/plugins/wikipedia/popcorn.wikipedia.unit.js +++ b/plugins/wikipedia/popcorn.wikipedia.unit.js @@ -1,13 +1,14 @@ -test("Popcorn Webpage Plugin", function () { +test("Popcorn wikipedia Plugin", function () { var popped = Popcorn("#video"), - expects = 11, + expects = 5, count = 0, - iframeInterval, - iframeInterval2, - iframeInterval3, - iframeInterval4; - theiFrame = document.getElementsByTagName('iframe'); + wikiInterval, + wikiInterval2, + wikiInterval3, + wikiInterval4; + theArticle = document.getElementById('wikidiv'); + expect(expects); function plus() { @@ -18,63 +19,57 @@ test("Popcorn Webpage Plugin", function () { stop(); - ok ('webpage' in popped, "webpages is a mehtod of the popped instance"); + ok ('wikipedia' in popped, "wikipedia is a mehtod of the popped instance"); plus(); - equals (theiFrame.length, 0, "initially, there is no iframes on the page" ); + equals (theArticle.innerHTML, "", "initially, there is nothing in the wikidiv" ); plus(); - popped.webpage({ - id: "webpages-a", + popped.wikipedia({ start: 5, // seconds - end: 25, // seconds - src: 'http://webmademovies.org', - target: 'webpagediv' - }) - .webpage({ - id: "webpages-b", - start: 35, // seconds - end: 50, // seconds - src: 'http://zenit.senecac.on.ca/wiki/index.php/Processing.js', - target: 'webpagediv' - }) + end: 10, // seconds + src: 'http://en.wikipedia.org/wiki/Cape_Town', + target: 'wikidiv' + } ) + .wikipedia({ + start: 12, // seconds + end: 20, // seconds + src: 'http://en.wikipedia.org/wiki/S%C3%A3o_Paulo', + target: 'wikidiv' + } ) .play(); - iframeInterval = setInterval( function() { - if( popped.currentTime() > 7 && popped.currentTime() <= 25 ) { - ok (!!theiFrame[0], "iframe was created" ); + wikiInterval = setInterval( function() { + if( popped.currentTime() > 7 && popped.currentTime() <= 10 ) { + ok (theArticle.innerHTML !== "", "wikidiv now contains information" ); plus(); - equals (theiFrame.length, 1, "there is only one iframe on the page" ); + equals (theArticle.childElementCount, 2, "wikidiv now contains two child elements" ); plus(); - equals (theiFrame[0].id, "webpages-a", "iframe has the id 'webpages-a'" ); - plus(); - equals (theiFrame[0].src, "http://webmademovies.org/", "iframe has the src 'http://webmademovies.org/'" ); - plus(); - clearInterval( iframeInterval ); + + clearInterval( wikiInterval ); } }, 5000); - iframeInterval2 = setInterval( function() { - if( popped.currentTime() > 27 && popped.currentTime() < 35 ) { - equals (theiFrame.length, 0, "the iframe has been removed" ); + wikiInterval2 = setInterval( function() { + if( popped.currentTime() > 10 && popped.currentTime() < 12 ) { + equals (theArticle.innerHTML, "", "wikidiv was cleared properly" ); plus(); - clearInterval( iframeInterval2 ); + clearInterval( wikiInterval2 ); } }, 5000); - iframeInterval3 = setInterval( function() { - if( popped.currentTime() > 37 && popped.currentTime() <= 50 ) { - ok (!!theiFrame[0], "iframe was created" ); - plus(); - equals (theiFrame.length, 1, "there is only one iframe on the page" ); + wikiInterval3 = setInterval( function() { + if( popped.currentTime() > 13 && popped.currentTime() <= 20 ) { + ok (theArticle.innerHTML !== "", "wikidiv now contains information" ); plus(); - equals (theiFrame[0].id, "webpages-b", "iframe has the id 'webpages-b'" ); + equals (theArticle.childElementCount, 2, "wikidiv now contains two child elements" ); plus(); - equals (theiFrame[0].src,"http://zenit.senecac.on.ca/wiki/index.php/Processing.js", "iframe has the src 'http://zenit.senecac.on.ca/wiki/index.php/Processing.js'" ); - plus(); - clearInterval( iframeInterval3 ); + + clearInterval( wikiInterval3 ); } }, 5000); + + });