]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#159] added unit tests for twitter plugin
authorScottDowne <sdowne@learn.senecac.on.ca>
Tue, 21 Dec 2010 17:52:25 +0000 (12:52 -0500)
committerScottDowne <sdowne@learn.senecac.on.ca>
Tue, 21 Dec 2010 17:52:25 +0000 (12:52 -0500)
plugins/twitter/popcorn.twitter.unit.html [new file with mode: 0644]
plugins/twitter/popcorn.twitter.unit.js [new file with mode: 0644]

diff --git a/plugins/twitter/popcorn.twitter.unit.html b/plugins/twitter/popcorn.twitter.unit.html
new file mode 100644 (file)
index 0000000..e03f454
--- /dev/null
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Popcorn API</title>
+  <link rel="stylesheet" href="../../test/qunit/qunit.css" type="text/css" media="screen">
+  <script src="../../test/qunit/qunit.js"></script>
+  <!-- 
+    do not move - this must be called immediately prior to 
+    popcorn-api-draft.js
+  -->
+  
+  <script src="../../popcorn.js"></script>
+  <script src="http://widgets.twimg.com/j/2/widget.js"></script>
+  <script src="popcorn.twitter.js"></script>
+
+  <script src="popcorn.twitter.unit.js"></script>
+</head>
+<body>
+
+  <h1 id="qunit-header">Popcorn Twitter Plugin</h1>
+  <h2 id="qunit-banner"></h2>
+  <div id="qunit-testrunner-toolbar"></div>
+  <h2 id="qunit-userAgent"></h2>
+  <ol id="qunit-tests"></ol>
+  <div id="qunit-fixture">  </div>
+  
+  <video id='video' 
+    controls 
+    width= '250px'
+    poster="../../test/poster.png"> 
+
+    <source id='mp4'
+      src="../../test/trailer.mp4"
+      type='video/mp4; codecs="avc1, mp4a"'> 
+
+    <source id='ogv'
+      src="../../test/trailer.ogv"
+      type='video/ogg; codecs="theora, vorbis"'> 
+
+    <p>Your user agent does not support the HTML5 Video element.</p> 
+
+  </video> 
+  <div id="twitterdiv"></div>  
+</body>
+</html>
diff --git a/plugins/twitter/popcorn.twitter.unit.js b/plugins/twitter/popcorn.twitter.unit.js
new file mode 100644 (file)
index 0000000..b3eed37
--- /dev/null
@@ -0,0 +1,61 @@
+test("Popcorn Twitter Plugin", function () {
+  
+  var popped = Popcorn("#video"),
+      expects = 6, 
+      count = 0,
+      interval,
+      interval2,
+      twitterdiv = document.getElementById('twitterdiv');
+  
+  expect( expects );
+  
+  function plus() {
+    if ( ++count === expects) {
+      start();
+    }
+  }
+
+  stop();   
+ 
+  ok('twitter' in popped, "twitter is a method of the popped instance");
+  plus();
+
+  equals ( twitterdiv.innerHTML, "", "initially, there is nothing inside the twitterdiv" );
+  plus();
+  
+  try {
+    
+    ok( TWTR, "Twitter constructor exists");
+    plus();
+    
+  } catch (e) {};
+
+  popped.twitter({
+    start: 1, // seconds
+    end: 3, // seconds
+    title: 'Steve Song',
+    src: '@stevesong',
+    target: 'twitterdiv',
+  } );
+
+  interval = setInterval( function() {
+    if( popped.currentTime() > 1 && popped.currentTime() < 3 ) {
+      ok( /display: inline;/.test( twitterdiv.innerHTML ), "Div contents are displayed" );
+      plus();
+      ok( /twtr-widget/.test( twitterdiv.innerHTML ), "A Twitter widget exists" );
+      plus();
+      clearInterval( interval );
+    }
+  }, 500);
+  
+  interval2 = setInterval( function() {
+    if( popped.currentTime() > 3 ) {
+      ok( /display: none;/.test( twitterdiv.innerHTML ), "Div contents are hidden again" );
+      plus();
+      clearInterval( interval2 );
+    }
+  }, 500);
+  
+  popped.play();
+  
+});