From 34c070f442192866be6cf8bd7611eae9e7c55601 Mon Sep 17 00:00:00 2001 From: David Humphrey Date: Sat, 12 Feb 2011 21:08:51 -0500 Subject: [PATCH] Additional mustache unit tests. --- plugins/mustache/popcorn.mustache.unit.js | 58 ++++++++++++++++++++--- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/plugins/mustache/popcorn.mustache.unit.js b/plugins/mustache/popcorn.mustache.unit.js index 2696bff..aae2a20 100644 --- a/plugins/mustache/popcorn.mustache.unit.js +++ b/plugins/mustache/popcorn.mustache.unit.js @@ -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 "

{{heading}}

"; + }, + 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 "

{{heading}}

"; + }, + 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( /

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(); -- 2.43.0