From: ScottDowne Date: Mon, 16 May 2011 22:33:47 +0000 (-0400) Subject: [#t479] unit tests and teardown X-Git-Tag: v0.6~14^2~2^2~2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=2886ad2ae67ea913cba617974e6b6685c40b32f2;p=popcorn-js.git [#t479] unit tests and teardown --- diff --git a/plugins/wordriver/popcorn.wordriver.html b/plugins/wordriver/popcorn.wordriver.html index a53fbce..d5b5f89 100644 --- a/plugins/wordriver/popcorn.wordriver.html +++ b/plugins/wordriver/popcorn.wordriver.html @@ -10,7 +10,7 @@ document.addEventListener('DOMContentLoaded', function () { var p = Popcorn('#video') .volume(0) - .play() + .play() .wordriver({ start: 1, // seconds end: 3, // seconds @@ -25,6 +25,20 @@ target: "wordriverdiv", color: "blue" }) + .wordriver({ + start: 1, // seconds + end: 4, // seconds + text: "hello", + target: "wordriverdiv2", + color: "red" + }) + .wordriver({ + start: 2, // seconds + end: 4, // seconds + text: "world", + target: "wordriverdiv2", + color: "blue" + }); }, false); @@ -52,6 +66,7 @@
+
diff --git a/plugins/wordriver/popcorn.wordriver.js b/plugins/wordriver/popcorn.wordriver.js index dc601e6..939cc81 100644 --- a/plugins/wordriver/popcorn.wordriver.js +++ b/plugins/wordriver/popcorn.wordriver.js @@ -4,13 +4,10 @@ var container = {}, spanLocation = 0, - knownSpeaker = false, - knownIndex = 0, - unknownIndex = 0, setupContainer = function( target ) { container[ target ] = document.createElement( "div" ); - document.getElementById( target ).appendChild( container[ target ] ); + document.getElementById( target ) && document.getElementById( target ).appendChild( container[ target ] ); container[ target ].style.height = "100%"; container[ target ].style.position = "relative"; @@ -69,7 +66,8 @@ options.word.style.MozTransform = options.word.style.webkitTransform = options.word.style.OTransform = - options.word.style.transform = "translateY(" + ( document.getElementById( options.target ).offsetHeight - options.word.offsetHeight ) + "px)"; + options.word.style.transform = "translateY(" + + ( document.getElementById( options.target ).offsetHeight - options.word.offsetHeight ) + "px)"; options.word.style.opacity = 1; @@ -85,6 +83,17 @@ // manually clears the word based on user interaction options.word.style.opacity = 0; + }, + _teardown: function( options ) { + + // removes word span from generated container + options._container.removeChild( options.word ); + + // if no more word spans exist in container, remove container + container[ options.target ] && + !container[ options.target ].childElementCount && + document.getElementById( options.target ).removeChild( container[ options.target ] ) && + delete container[ options.target ]; } }); diff --git a/plugins/wordriver/popcorn.wordriver.unit.html b/plugins/wordriver/popcorn.wordriver.unit.html new file mode 100644 index 0000000..532f3de --- /dev/null +++ b/plugins/wordriver/popcorn.wordriver.unit.html @@ -0,0 +1,43 @@ + + + + Popcorn Word River Plugin + + + + + + + + + + +

Popcorn Word River Plugin

+

+
+

+
    +
    + + +
    + + diff --git a/plugins/wordriver/popcorn.wordriver.unit.js b/plugins/wordriver/popcorn.wordriver.unit.js new file mode 100644 index 0000000..6dcc4b2 --- /dev/null +++ b/plugins/wordriver/popcorn.wordriver.unit.js @@ -0,0 +1,91 @@ +test( "Popcorn wordriver Plugin", function () { + + var popped = Popcorn( "#video" ), + expects = 16, + count = 0, + firstTrack, + secondTrack, + wordriverdiv = document.getElementById( "wordriverdiv" ); + + expect(expects); + + function plus() { + if ( ++count === expects) { + start(); + } + } + + stop(); + + ok ( "wordriver" in popped, "wordriver is a method of the popped instance" ); + plus(); + + equals ( wordriverdiv.childElementCount, 0, "initially, there is nothing inside the wordriverdiv" ); + plus(); + + + popped.wordriver({ + start: 0, // seconds + end: 2, // seconds + text: "hello", + target: "wordriverdiv", + color: "red" + }); + + firstTrack = popped.getLastTrackEventId(); + + popped.wordriver({ + start: 2, // seconds + end: 4, // seconds + text: "world", + target: "wordriverdiv", + color: "blue" + }) + .volume(0); + + secondTrack = popped.getLastTrackEventId(); + + popped.exec( 0, function() { + equals( wordriverdiv.children[0].childElementCount, 1, "wordriverdiv now has one inner element" ); + plus(); + equals( wordriverdiv.children[0].children[0].style.opacity, 1, "first word is visible on the page" ); + plus(); + equals( wordriverdiv.children[0].children[0].innerHTML, "hello", "first word content is correct" ); + plus(); + ok( !wordriverdiv.children[0].children[1], "second word does not exist yet" ); + plus(); + }); + + popped.exec( 2, function() { + equals( wordriverdiv.children[0].childElementCount, 2, "wordriverdiv now has two inner elements" ); + plus(); + equals( wordriverdiv.children[0].children[0].style.opacity, 0, "first word is not visible on the page" ); + plus(); + equals( wordriverdiv.children[0].children[0].innerHTML, "hello", "first word content is correct" ); + plus(); + equals( wordriverdiv.children[0].children[1].style.opacity, 1, "second word is visible on the page" ); + plus(); + equals( wordriverdiv.children[0].children[1].innerHTML, "world", "second word content is correct" ); + plus(); + }); + + popped.exec( 4, function() { + equals( wordriverdiv.children[0].children[0].style.opacity, 0, "first word is not visible on the page" ); + plus(); + equals( wordriverdiv.children[0].children[1].style.opacity, 0, "second word is not visible on the page" ); + plus(); + + popped.pause().removeTrackEvent( firstTrack ); + equals( wordriverdiv.children[0].childElementCount, 1, "wordriverdiv now has one inner element" ); + plus(); + equals( wordriverdiv.children[0].children[0].innerHTML, "world", "first word content is changed" ); + plus(); + + popped.pause().removeTrackEvent( secondTrack ); + equals( wordriverdiv.childElementCount, 0, "wordriverdiv now has no inner element" ); + plus(); + }); + + popped.play(); + +});