From: rwldrn Date: Fri, 1 Apr 2011 16:59:52 +0000 (-0400) Subject: [#415] Fixed missing comma; Complete unit test rewrite for: relative, absolute, fixed... X-Git-Tag: v0.5~13^2~3^2~1 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=b3e8b98898a64eeed04c88ce151b6f66d6c73eb8;p=popcorn-js.git [#415] Fixed missing comma; Complete unit test rewrite for: relative, absolute, fixed, static --- diff --git a/popcorn.js b/popcorn.js index 2220f0a..bb7dfb6 100644 --- a/popcorn.js +++ b/popcorn.js @@ -396,7 +396,8 @@ }); return this; - } + }, + // Popcorn Object Element Utils position: function() { var media = this.video, diff --git a/test/index.html b/test/index.html index c075015..dc69bc2 100644 --- a/test/index.html +++ b/test/index.html @@ -49,5 +49,58 @@ + + + + + +
+
+
+
+
+
+
+ +
+
+
+
+
+
+ + +
+
+ +
+
+ +
+ + diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 4d4aa96..593a798 100755 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -310,46 +310,66 @@ test("exec", function () { module("Popcorn Position"); test("position", function () { - var pops = [ Popcorn("#pos-1"), - Popcorn("#pos-2"), - Popcorn("#pos-3"), - Popcorn("#pos-4") - ], - expects = 22, - count = 0, - tests = [ - {"top":0,"height":150,"width":300,"bottom":150,"left":1123,"right":1423}, - {"top":100,"height":150,"width":300,"bottom":250,"left":1023,"right":1323}, - {"height":150,"width":300,"left":1366,"right":1666}, - {"top":0,"height":150,"width":300,"bottom":150,"left":1123,"right":1423} - ], - bounds, - against, - styles; - - expect( expects ); - - function plus(){ - if ( ++count == expects ) { - start(); - } - } - - stop( 10000 ); + expect(24); + + var $absolute = $(".absolute"), + $relative = $(".relative"), + $fixed = $(".fixed"), + $static = $(".static"), + tests; + + $("#position-tests").show(); +// console.log( $absolute ); +// console.log( $fixed ); +// console.log( $relative ); +// console.log( $static ); + + tests = [ + { id: "absolute-1", top: 0, left: 0 }, + { id: "absolute-1-1", top: 1, left: 1 }, + { id: "absolute-1-1-1", top: 2, left: 2 }, + { id: "absolute-2", top: 19, left: 19 } + ]; + + Popcorn.forEach( tests, function( test ) { + equals( Popcorn( "#vid-" + test.id ).position().top, test.top, "Popcorn('#vid-" + test.id + "').position().top" ); + equals( Popcorn( "#vid-" + test.id ).position().left, test.left, "Popcorn('#vid-" + test.id + "').position().left" ); + }); - pops.forEach(function( pop, idx ) { + tests = [ + { id: "relative-1", top: 0, left: 0 }, + { id: "relative-2", top: 120, left: 20 } + ]; + + Popcorn.forEach( tests, function( test ) { + equals( Popcorn( "#vid-" + test.id ).position().top, test.top, "Popcorn('#vid-" + test.id + "').position().top" ); + equals( Popcorn( "#vid-" + test.id ).position().left, test.left, "Popcorn('#vid-" + test.id + "').position().left" ); + }); + + tests = [ + { id: "fixed-1", top: 0, left: 0 }, + { id: "fixed-2", top: 20, left: 20 } + ]; + + Popcorn.forEach( tests, function( test ) { + equals( Popcorn( "#vid-" + test.id ).position().top, test.top, "Popcorn('#vid-" + test.id + "').position().top" ); + equals( Popcorn( "#vid-" + test.id ).position().left, test.left, "Popcorn('#vid-" + test.id + "').position().left" ); + }); + + tests = [ + { id: "static-1", top: 200, left: 0 }, + { id: "static-1-1", top: 0, left: 0 }, + { id: "static-1-1-1", top: 0, left: 0 }, + { id: "static-2", top: 300, left: 0 } + ]; + + Popcorn.forEach( tests, function( test ) { + equals( Popcorn( "#vid-" + test.id ).position().top, test.top, "Popcorn('#vid-" + test.id + "').position().top" ); + equals( Popcorn( "#vid-" + test.id ).position().left, test.left, "Popcorn('#vid-" + test.id + "').position().left" ); + }); - bounds = pop.position(); - against = tests[ idx ]; - styles = document.getElementById( pop.video.id ).style; - for ( var p in bounds ) { - if ( p in against ) { - equal( bounds[ p ], against[ p ], "video#" + pop.video.id + ": " + p ); - plus(); - } - } - }); + $("#position-tests").hide(); }); test("position called from plugin", function () {