]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
Additional mustache unit tests.
authorDavid Humphrey <david.humphrey@senecac.on.ca>
Sun, 13 Feb 2011 02:08:51 +0000 (21:08 -0500)
committerDavid Humphrey <david.humphrey@senecac.on.ca>
Sun, 13 Feb 2011 02:08:51 +0000 (21:08 -0500)
plugins/mustache/popcorn.mustache.unit.js

index 2696bff19ddee76c0fea11fd3affdc0881fa0bab..aae2a207d7df3c763de23ce50650b80864558438 100644 (file)
@@ -1,9 +1,8 @@
 test("Popcorn Mustache Plugin", function () {
 
   var popped = Popcorn("#video"),
-      expects = 3,
+      expects = 5,
       count = 0,
-      interval,
       mustacheDiv = document.getElementById('mustache-div');
 
   expect( expects );
@@ -22,6 +21,7 @@ test("Popcorn Mustache Plugin", function () {
   equals ( mustacheDiv.innerHTML, "", "initially, there is nothing inside the mustache-div" );
   plus();
 
+  // Static strings
   popped.mustache({
     start: 1, // seconds
     end: 3, // seconds
@@ -31,13 +31,59 @@ test("Popcorn Mustache Plugin", function () {
     static: true
   } );
 
-  interval = setInterval( function() {
-    if( popped.currentTime() > 1 && popped.currentTime() < 3 ) {
+  // Dynamic functions
+  popped.mustache({
+    start: 5, // seconds
+    end: 7, // seconds
+    template: function(plugin, options) {
+      return "<h1>{{heading}}</h1>";
+    },
+    data: function(plugin, options) {
+      return JSON.parse('{"heading": "mustache"}');
+    },
+    target: 'mustache-div',
+  } );
+
+  // Template + Object literal
+  popped.mustache({
+    start: 9, // seconds
+    end: 11, // seconds
+    template: function(plugin, options) {
+      return "<h1>{{heading}}</h1>";
+    },
+    data: { heading: "mustache" },
+    target: 'mustache-div',
+    static: true
+  } );
+
+  var video = document.getElementById('video');
+  var two = six = ten = false;
+
+  video.addEventListener('timeupdate', function() {
+
+    function pass() {
       ok( /<h1>mustache<\/h1>/.test( mustacheDiv.innerHTML ), "Mustache template rendered" );
       plus();
-      clearInterval( interval );
     }
-  }, 500);
+
+    var t = Math.floor(video.currentTime);
+
+    if (t === 2 && !two) {
+      pass();
+      two = true;
+    } else if (t === 6 && !six) {
+      pass();
+      six = true;
+    } else if (t === 10 && !ten) {
+      pass();
+      ten = true;
+    }
+
+    if (t === 11) {
+      video.pause();
+    }
+
+  }, false);
 
   popped.volume(0);
   popped.play();