Position: Shift to use no globals

This commit is contained in:
Amanpreet Singh 2016-04-06 18:35:47 +05:30
parent 8127030ed4
commit 059b5b17a1

View File

@ -1,8 +1,9 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"lib/common", "lib/common",
"ui/position" "ui/position"
], function( $, common ) { ], function( QUnit, $, common ) {
var win = $( window ), var win = $( window ),
scrollTopSupport = function() { scrollTopSupport = function() {
@ -14,16 +15,16 @@ var win = $( window ),
return support; return support;
}; };
module( "position", { QUnit.module( "position", {
setup: function() { beforeEach: function() {
win.scrollTop( 0 ).scrollLeft( 0 ); win.scrollTop( 0 ).scrollLeft( 0 );
} }
} ); } );
common.testJshint( "position" ); common.testJshint( "position" );
test( "my, at, of", function() { QUnit.test( "my, at, of", function( assert ) {
expect( 4 ); assert.expect( 4 );
$( "#elx" ).position( { $( "#elx" ).position( {
my: "left top", my: "left top",
@ -31,7 +32,7 @@ test( "my, at, of", function() {
of: "#parentx", of: "#parentx",
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { top: 40, left: 40 }, "left top, left top" ); assert.deepEqual( $( "#elx" ).offset(), { top: 40, left: 40 }, "left top, left top" );
$( "#elx" ).position( { $( "#elx" ).position( {
my: "left top", my: "left top",
@ -39,7 +40,7 @@ test( "my, at, of", function() {
of: "#parentx", of: "#parentx",
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { top: 60, left: 40 }, "left top, left bottom" ); assert.deepEqual( $( "#elx" ).offset(), { top: 60, left: 40 }, "left top, left bottom" );
$( "#elx" ).position( { $( "#elx" ).position( {
my: "left", my: "left",
@ -47,7 +48,7 @@ test( "my, at, of", function() {
of: "#parentx", of: "#parentx",
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { top: 55, left: 50 }, "left, bottom" ); assert.deepEqual( $( "#elx" ).offset(), { top: 55, left: 50 }, "left, bottom" );
$( "#elx" ).position( { $( "#elx" ).position( {
my: "left foo", my: "left foo",
@ -55,11 +56,11 @@ test( "my, at, of", function() {
of: "#parentx", of: "#parentx",
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { top: 45, left: 50 }, "left foo, bar baz" ); assert.deepEqual( $( "#elx" ).offset(), { top: 45, left: 50 }, "left foo, bar baz" );
} ); } );
test( "multiple elements", function() { QUnit.test( "multiple elements", function( assert ) {
expect( 3 ); assert.expect( 3 );
var elements = $( "#el1, #el2" ), var elements = $( "#el1, #el2" ),
result = elements.position( { result = elements.position( {
@ -70,14 +71,14 @@ test( "multiple elements", function() {
} ), } ),
expected = { top: 10, left: 4 }; expected = { top: 10, left: 4 };
deepEqual( result, elements ); assert.deepEqual( result, elements );
elements.each( function() { elements.each( function() {
deepEqual( $( this ).offset(), expected ); assert.deepEqual( $( this ).offset(), expected );
} ); } );
} ); } );
test( "positions", function() { QUnit.test( "positions", function( assert ) {
expect( 18 ); assert.expect( 18 );
var offsets = { var offsets = {
left: 0, left: 0,
@ -100,7 +101,7 @@ test( "positions", function() {
of: "#parent", of: "#parent",
collision: "none" collision: "none"
} ); } );
deepEqual( el.offset(), { assert.deepEqual( el.offset(), {
top: start.top + offsets[ vertical ] * ( my ? -1 : 1 ), top: start.top + offsets[ vertical ] * ( my ? -1 : 1 ),
left: start.left + offsets[ horizontal ] * ( my ? -1 : 1 ) left: start.left + offsets[ horizontal ] * ( my ? -1 : 1 )
}, "Position via " + QUnit.jsDump.parse( { my: _my, at: _at } ) ); }, "Position via " + QUnit.jsDump.parse( { my: _my, at: _at } ) );
@ -109,8 +110,8 @@ test( "positions", function() {
} ); } );
} ); } );
test( "of", function() { QUnit.test( "of", function( assert ) {
expect( 9 + ( scrollTopSupport() ? 1 : 0 ) ); assert.expect( 9 + ( scrollTopSupport() ? 1 : 0 ) );
var event; var event;
@ -120,7 +121,7 @@ test( "of", function() {
of: "#parentx", of: "#parentx",
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { top: 40, left: 40 }, "selector" ); assert.deepEqual( $( "#elx" ).offset(), { top: 40, left: 40 }, "selector" );
$( "#elx" ).position( { $( "#elx" ).position( {
my: "left top", my: "left top",
@ -128,7 +129,7 @@ test( "of", function() {
of: $( "#parentx" ), of: $( "#parentx" ),
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { top: 60, left: 40 }, "jQuery object" ); assert.deepEqual( $( "#elx" ).offset(), { top: 60, left: 40 }, "jQuery object" );
$( "#elx" ).position( { $( "#elx" ).position( {
my: "left top", my: "left top",
@ -136,7 +137,7 @@ test( "of", function() {
of: $( "#parentx" )[ 0 ], of: $( "#parentx" )[ 0 ],
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { top: 40, left: 40 }, "DOM element" ); assert.deepEqual( $( "#elx" ).offset(), { top: 40, left: 40 }, "DOM element" );
$( "#elx" ).position( { $( "#elx" ).position( {
my: "right bottom", my: "right bottom",
@ -144,7 +145,7 @@ test( "of", function() {
of: document, of: document,
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { assert.deepEqual( $( "#elx" ).offset(), {
top: $( document ).height() - 10, top: $( document ).height() - 10,
left: $( document ).width() - 10 left: $( document ).width() - 10
}, "document" ); }, "document" );
@ -155,7 +156,7 @@ test( "of", function() {
of: $( document ), of: $( document ),
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { assert.deepEqual( $( "#elx" ).offset(), {
top: $( document ).height() - 10, top: $( document ).height() - 10,
left: $( document ).width() - 10 left: $( document ).width() - 10
}, "document as jQuery object" ); }, "document as jQuery object" );
@ -168,7 +169,7 @@ test( "of", function() {
of: window, of: window,
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { assert.deepEqual( $( "#elx" ).offset(), {
top: win.height() - 10, top: win.height() - 10,
left: win.width() - 10 left: win.width() - 10
}, "window" ); }, "window" );
@ -179,7 +180,7 @@ test( "of", function() {
of: win, of: win,
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { assert.deepEqual( $( "#elx" ).offset(), {
top: win.height() - 10, top: win.height() - 10,
left: win.width() - 10 left: win.width() - 10
}, "window as jQuery object" ); }, "window as jQuery object" );
@ -192,7 +193,7 @@ test( "of", function() {
of: window, of: window,
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { assert.deepEqual( $( "#elx" ).offset(), {
top: win.height() + 500 - 10, top: win.height() + 500 - 10,
left: win.width() + 200 - 10 left: win.width() + 200 - 10
}, "window, scrolled" ); }, "window, scrolled" );
@ -206,7 +207,7 @@ test( "of", function() {
of: event, of: event,
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { assert.deepEqual( $( "#elx" ).offset(), {
top: 300, top: 300,
left: 200 left: 200
}, "event - left top, left top" ); }, "event - left top, left top" );
@ -218,14 +219,14 @@ test( "of", function() {
of: event, of: event,
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { assert.deepEqual( $( "#elx" ).offset(), {
top: 600, top: 600,
left: 400 left: 400
}, "event - left top, right bottom" ); }, "event - left top, right bottom" );
} ); } );
test( "offsets", function() { QUnit.test( "offsets", function( assert ) {
expect( 9 ); assert.expect( 9 );
var offset; var offset;
@ -235,7 +236,7 @@ test( "offsets", function() {
of: "#parentx", of: "#parentx",
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { top: 70, left: 50 }, "offsets in at" ); assert.deepEqual( $( "#elx" ).offset(), { top: 70, left: 50 }, "offsets in at" );
$( "#elx" ).position( { $( "#elx" ).position( {
my: "left+10 top-10", my: "left+10 top-10",
@ -243,7 +244,7 @@ test( "offsets", function() {
of: "#parentx", of: "#parentx",
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { top: 50, left: 50 }, "offsets in my" ); assert.deepEqual( $( "#elx" ).offset(), { top: 50, left: 50 }, "offsets in my" );
$( "#elx" ).position( { $( "#elx" ).position( {
my: "left top", my: "left top",
@ -251,7 +252,7 @@ test( "offsets", function() {
of: "#parentx", of: "#parentx",
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { top: 58, left: 50 }, "percentage offsets in at" ); assert.deepEqual( $( "#elx" ).offset(), { top: 58, left: 50 }, "percentage offsets in at" );
$( "#elx" ).position( { $( "#elx" ).position( {
my: "left-30% top+50%", my: "left-30% top+50%",
@ -259,7 +260,7 @@ test( "offsets", function() {
of: "#parentx", of: "#parentx",
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { top: 65, left: 37 }, "percentage offsets in my" ); assert.deepEqual( $( "#elx" ).offset(), { top: 65, left: 37 }, "percentage offsets in my" );
$( "#elx" ).position( { $( "#elx" ).position( {
my: "left-30.001% top+50.0%", my: "left-30.001% top+50.0%",
@ -268,8 +269,8 @@ test( "offsets", function() {
collision: "none" collision: "none"
} ); } );
offset = $( "#elx" ).offset(); offset = $( "#elx" ).offset();
equal( Math.round( offset.top ), 65, "decimal percentage offsets in my" ); assert.equal( Math.round( offset.top ), 65, "decimal percentage offsets in my" );
equal( Math.round( offset.left ), 37, "decimal percentage offsets in my" ); assert.equal( Math.round( offset.left ), 37, "decimal percentage offsets in my" );
$( "#elx" ).position( { $( "#elx" ).position( {
my: "left+10.4 top-10.6", my: "left+10.4 top-10.6",
@ -278,8 +279,8 @@ test( "offsets", function() {
collision: "none" collision: "none"
} ); } );
offset = $( "#elx" ).offset(); offset = $( "#elx" ).offset();
equal( Math.round( offset.top ), 49, "decimal offsets in my" ); assert.equal( Math.round( offset.top ), 49, "decimal offsets in my" );
equal( Math.round( offset.left ), 50, "decimal offsets in my" ); assert.equal( Math.round( offset.left ), 50, "decimal offsets in my" );
$( "#elx" ).position( { $( "#elx" ).position( {
my: "left+right top-left", my: "left+right top-left",
@ -287,11 +288,11 @@ test( "offsets", function() {
of: "#parentx", of: "#parentx",
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#elx" ).offset(), { top: 60, left: 40 }, "invalid offsets" ); assert.deepEqual( $( "#elx" ).offset(), { top: 60, left: 40 }, "invalid offsets" );
} ); } );
test( "using", function() { QUnit.test( "using", function( assert ) {
expect( 10 ); assert.expect( 10 );
var count = 0, var count = 0,
elems = $( "#el1, #el2" ), elems = $( "#el1, #el2" ),
@ -327,47 +328,47 @@ test( "using", function() {
at: "center+10 bottom", at: "center+10 bottom",
of: "#parentx", of: "#parentx",
using: function( position, feedback ) { using: function( position, feedback ) {
deepEqual( this, elems[ count ], "correct context for call #" + count ); assert.deepEqual( this, elems[ count ], "correct context for call #" + count );
deepEqual( position, expectedPosition, "correct position for call #" + count ); assert.deepEqual( position, expectedPosition, "correct position for call #" + count );
deepEqual( feedback.element.element[ 0 ], elems[ count ] ); assert.deepEqual( feedback.element.element[ 0 ], elems[ count ] );
delete feedback.element.element; delete feedback.element.element;
deepEqual( feedback, expectedFeedback ); assert.deepEqual( feedback, expectedFeedback );
count++; count++;
} }
} ); } );
elems.each( function() { elems.each( function() {
deepEqual( $( this ).offset(), originalPosition, "elements not moved" ); assert.deepEqual( $( this ).offset(), originalPosition, "elements not moved" );
} ); } );
} ); } );
function collisionTest( config, result, msg ) { function collisionTest( assert, config, result, msg ) {
var elem = $( "#elx" ).position( $.extend( { var elem = $( "#elx" ).position( $.extend( {
my: "left top", my: "left top",
at: "right bottom", at: "right bottom",
of: "#parent" of: "#parent"
}, config ) ); }, config ) );
deepEqual( elem.offset(), result, msg ); assert.deepEqual( elem.offset(), result, msg );
} }
function collisionTest2( config, result, msg ) { function collisionTest2( assert, config, result, msg ) {
collisionTest( $.extend( { collisionTest( assert, $.extend( {
my: "right bottom", my: "right bottom",
at: "left top" at: "left top"
}, config ), result, msg ); }, config ), result, msg );
} }
test( "collision: fit, no collision", function() { QUnit.test( "collision: fit, no collision", function( assert ) {
expect( 2 ); assert.expect( 2 );
collisionTest( { collisionTest( assert, {
collision: "fit" collision: "fit"
}, { }, {
top: 10, top: 10,
left: 10 left: 10
}, "no offset" ); }, "no offset" );
collisionTest( { collisionTest( assert, {
collision: "fit", collision: "fit",
at: "right+2 bottom+3" at: "right+2 bottom+3"
}, { }, {
@ -378,17 +379,17 @@ test( "collision: fit, no collision", function() {
// Currently failing in IE8 due to the iframe used by TestSwarm // Currently failing in IE8 due to the iframe used by TestSwarm
if ( !/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() ) ) { if ( !/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() ) ) {
test( "collision: fit, collision", function() { QUnit.test( "collision: fit, collision", function( assert ) {
expect( 2 + ( scrollTopSupport() ? 1 : 0 ) ); assert.expect( 2 + ( scrollTopSupport() ? 1 : 0 ) );
collisionTest2( { collisionTest2( assert, {
collision: "fit" collision: "fit"
}, { }, {
top: 0, top: 0,
left: 0 left: 0
}, "no offset" ); }, "no offset" );
collisionTest2( { collisionTest2( assert, {
collision: "fit", collision: "fit",
at: "left+2 top+3" at: "left+2 top+3"
}, { }, {
@ -398,7 +399,7 @@ test( "collision: fit, collision", function() {
if ( scrollTopSupport() ) { if ( scrollTopSupport() ) {
win.scrollTop( 300 ).scrollLeft( 200 ); win.scrollTop( 300 ).scrollLeft( 200 );
collisionTest( { collisionTest( assert, {
collision: "fit" collision: "fit"
}, { }, {
top: 300, top: 300,
@ -410,17 +411,17 @@ test( "collision: fit, collision", function() {
} ); } );
} }
test( "collision: flip, no collision", function() { QUnit.test( "collision: flip, no collision", function( assert ) {
expect( 2 ); assert.expect( 2 );
collisionTest( { collisionTest( assert, {
collision: "flip" collision: "flip"
}, { }, {
top: 10, top: 10,
left: 10 left: 10
}, "no offset" ); }, "no offset" );
collisionTest( { collisionTest( assert, {
collision: "flip", collision: "flip",
at: "right+2 bottom+3" at: "right+2 bottom+3"
}, { }, {
@ -429,17 +430,17 @@ test( "collision: flip, no collision", function() {
}, "with offset" ); }, "with offset" );
} ); } );
test( "collision: flip, collision", function() { QUnit.test( "collision: flip, collision", function( assert ) {
expect( 2 ); assert.expect( 2 );
collisionTest2( { collisionTest2( assert, {
collision: "flip" collision: "flip"
}, { }, {
top: 10, top: 10,
left: 10 left: 10
}, "no offset" ); }, "no offset" );
collisionTest2( { collisionTest2( assert, {
collision: "flip", collision: "flip",
at: "left+2 top+3" at: "left+2 top+3"
}, { }, {
@ -448,17 +449,17 @@ test( "collision: flip, collision", function() {
}, "with offset" ); }, "with offset" );
} ); } );
test( "collision: flipfit, no collision", function() { QUnit.test( "collision: flipfit, no collision", function( assert ) {
expect( 2 ); assert.expect( 2 );
collisionTest( { collisionTest( assert, {
collision: "flipfit" collision: "flipfit"
}, { }, {
top: 10, top: 10,
left: 10 left: 10
}, "no offset" ); }, "no offset" );
collisionTest( { collisionTest( assert, {
collision: "flipfit", collision: "flipfit",
at: "right+2 bottom+3" at: "right+2 bottom+3"
}, { }, {
@ -467,17 +468,17 @@ test( "collision: flipfit, no collision", function() {
}, "with offset" ); }, "with offset" );
} ); } );
test( "collision: flipfit, collision", function() { QUnit.test( "collision: flipfit, collision", function( assert ) {
expect( 2 ); assert.expect( 2 );
collisionTest2( { collisionTest2( assert, {
collision: "flipfit" collision: "flipfit"
}, { }, {
top: 10, top: 10,
left: 10 left: 10
}, "no offset" ); }, "no offset" );
collisionTest2( { collisionTest2( assert, {
collision: "flipfit", collision: "flipfit",
at: "left+2 top+3" at: "left+2 top+3"
}, { }, {
@ -486,17 +487,17 @@ test( "collision: flipfit, collision", function() {
}, "with offset" ); }, "with offset" );
} ); } );
test( "collision: none, no collision", function() { QUnit.test( "collision: none, no collision", function( assert ) {
expect( 2 ); assert.expect( 2 );
collisionTest( { collisionTest( assert, {
collision: "none" collision: "none"
}, { }, {
top: 10, top: 10,
left: 10 left: 10
}, "no offset" ); }, "no offset" );
collisionTest( { collisionTest( assert, {
collision: "none", collision: "none",
at: "right+2 bottom+3" at: "right+2 bottom+3"
}, { }, {
@ -505,17 +506,17 @@ test( "collision: none, no collision", function() {
}, "with offset" ); }, "with offset" );
} ); } );
test( "collision: none, collision", function() { QUnit.test( "collision: none, collision", function( assert ) {
expect( 2 ); assert.expect( 2 );
collisionTest2( { collisionTest2( assert, {
collision: "none" collision: "none"
}, { }, {
top: -6, top: -6,
left: -6 left: -6
}, "no offset" ); }, "no offset" );
collisionTest2( { collisionTest2( assert, {
collision: "none", collision: "none",
at: "left+2 top+3" at: "left+2 top+3"
}, { }, {
@ -524,22 +525,22 @@ test( "collision: none, collision", function() {
}, "with offset" ); }, "with offset" );
} ); } );
test( "collision: fit, with margin", function() { QUnit.test( "collision: fit, with margin", function( assert ) {
expect( 2 ); assert.expect( 2 );
$( "#elx" ).css( { $( "#elx" ).css( {
marginTop: 6, marginTop: 6,
marginLeft: 4 marginLeft: 4
} ); } );
collisionTest( { collisionTest( assert, {
collision: "fit" collision: "fit"
}, { }, {
top: 10, top: 10,
left: 10 left: 10
}, "right bottom" ); }, "right bottom" );
collisionTest2( { collisionTest2( assert, {
collision: "fit" collision: "fit"
}, { }, {
top: 6, top: 6,
@ -547,29 +548,29 @@ test( "collision: fit, with margin", function() {
}, "left top" ); }, "left top" );
} ); } );
test( "collision: flip, with margin", function() { QUnit.test( "collision: flip, with margin", function( assert ) {
expect( 3 ); assert.expect( 3 );
$( "#elx" ).css( { $( "#elx" ).css( {
marginTop: 6, marginTop: 6,
marginLeft: 4 marginLeft: 4
} ); } );
collisionTest( { collisionTest( assert, {
collision: "flip" collision: "flip"
}, { }, {
top: 10, top: 10,
left: 10 left: 10
}, "left top" ); }, "left top" );
collisionTest2( { collisionTest2( assert, {
collision: "flip" collision: "flip"
}, { }, {
top: 10, top: 10,
left: 10 left: 10
}, "right bottom" ); }, "right bottom" );
collisionTest2( { collisionTest2( assert, {
collision: "flip", collision: "flip",
my: "left top" my: "left top"
}, { }, {
@ -578,17 +579,17 @@ test( "collision: flip, with margin", function() {
}, "right bottom" ); }, "right bottom" );
} ); } );
test( "within", function() { QUnit.test( "within", function( assert ) {
expect( 7 ); assert.expect( 7 );
collisionTest( { collisionTest( assert, {
within: document within: document
}, { }, {
top: 10, top: 10,
left: 10 left: 10
}, "within document" ); }, "within document" );
collisionTest( { collisionTest( assert, {
within: "#within", within: "#within",
collision: "fit" collision: "fit"
}, { }, {
@ -596,7 +597,7 @@ test( "within", function() {
left: 2 left: 2
}, "fit - right bottom" ); }, "fit - right bottom" );
collisionTest2( { collisionTest2( assert, {
within: "#within", within: "#within",
collision: "fit" collision: "fit"
}, { }, {
@ -604,7 +605,7 @@ test( "within", function() {
left: 0 left: 0
}, "fit - left top" ); }, "fit - left top" );
collisionTest( { collisionTest( assert, {
within: "#within", within: "#within",
collision: "flip" collision: "flip"
}, { }, {
@ -612,7 +613,7 @@ test( "within", function() {
left: -6 left: -6
}, "flip - right bottom" ); }, "flip - right bottom" );
collisionTest2( { collisionTest2( assert, {
within: "#within", within: "#within",
collision: "flip" collision: "flip"
}, { }, {
@ -620,7 +621,7 @@ test( "within", function() {
left: -6 left: -6
}, "flip - left top" ); }, "flip - left top" );
collisionTest( { collisionTest( assert, {
within: "#within", within: "#within",
collision: "flipfit" collision: "flipfit"
}, { }, {
@ -628,7 +629,7 @@ test( "within", function() {
left: 0 left: 0
}, "flipfit - right bottom" ); }, "flipfit - right bottom" );
collisionTest2( { collisionTest2( assert, {
within: "#within", within: "#within",
collision: "flipfit" collision: "flipfit"
}, { }, {
@ -637,8 +638,8 @@ test( "within", function() {
}, "flipfit - left top" ); }, "flipfit - left top" );
} ); } );
test( "with scrollbars", function() { QUnit.test( "with scrollbars", function( assert ) {
expect( 4 ); assert.expect( 4 );
$( "#scrollx" ).css( { $( "#scrollx" ).css( {
width: 100, width: 100,
@ -647,7 +648,7 @@ test( "with scrollbars", function() {
top: 0 top: 0
} ); } );
collisionTest( { collisionTest( assert, {
of: "#scrollx", of: "#scrollx",
collision: "fit", collision: "fit",
within: "#scrollx" within: "#scrollx"
@ -662,7 +663,7 @@ test( "with scrollbars", function() {
var scrollbarInfo = $.position.getScrollInfo( $.position.getWithinInfo( $( "#scrollx" ) ) ); var scrollbarInfo = $.position.getScrollInfo( $.position.getWithinInfo( $( "#scrollx" ) ) );
collisionTest( { collisionTest( assert, {
of: "#scrollx", of: "#scrollx",
collision: "fit", collision: "fit",
within: "#scrollx" within: "#scrollx"
@ -675,7 +676,7 @@ test( "with scrollbars", function() {
overflow: "auto" overflow: "auto"
} ); } );
collisionTest( { collisionTest( assert, {
of: "#scrollx", of: "#scrollx",
collision: "fit", collision: "fit",
within: "#scrollx" within: "#scrollx"
@ -688,7 +689,7 @@ test( "with scrollbars", function() {
overflow: "auto" overflow: "auto"
} ).append( $( "<div>" ).height( 300 ).width( 300 ) ); } ).append( $( "<div>" ).height( 300 ).width( 300 ) );
collisionTest( { collisionTest( assert, {
of: "#scrollx", of: "#scrollx",
collision: "fit", collision: "fit",
within: "#scrollx" within: "#scrollx"
@ -698,8 +699,8 @@ test( "with scrollbars", function() {
}, "auto, with scroll" ); }, "auto, with scroll" );
} ); } );
test( "fractions", function() { QUnit.test( "fractions", function( assert ) {
expect( 1 ); assert.expect( 1 );
$( "#fractions-element" ).position( { $( "#fractions-element" ).position( {
my: "left top", my: "left top",
@ -707,11 +708,11 @@ test( "fractions", function() {
of: "#fractions-parent", of: "#fractions-parent",
collision: "none" collision: "none"
} ); } );
deepEqual( $( "#fractions-element" ).offset(), $( "#fractions-parent" ).offset(), "left top, left top" ); assert.deepEqual( $( "#fractions-element" ).offset(), $( "#fractions-parent" ).offset(), "left top, left top" );
} ); } );
test( "bug #5280: consistent results (avoid fractional values)", function() { QUnit.test( "bug #5280: consistent results (avoid fractional values)", function( assert ) {
expect( 1 ); assert.expect( 1 );
var wrapper = $( "#bug-5280" ), var wrapper = $( "#bug-5280" ),
elem = wrapper.children(), elem = wrapper.children(),
@ -727,14 +728,14 @@ test( "bug #5280: consistent results (avoid fractional values)", function() {
of: wrapper, of: wrapper,
collision: "none" collision: "none"
} ).offset(); } ).offset();
deepEqual( offset1, offset2 ); assert.deepEqual( offset1, offset2 );
} ); } );
test( "bug #8710: flip if flipped position fits more", function() { QUnit.test( "bug #8710: flip if flipped position fits more", function( assert ) {
expect( 3 ); assert.expect( 3 );
// Positions a 10px tall element within 99px height at top 90px. // Positions a 10px tall element within 99px height at top 90px.
collisionTest( { collisionTest( assert, {
within: "#bug-8710-within-smaller", within: "#bug-8710-within-smaller",
of: "#parentx", of: "#parentx",
collision: "flip", collision: "flip",
@ -745,7 +746,7 @@ test( "bug #8710: flip if flipped position fits more", function() {
}, "flip - top fits all" ); }, "flip - top fits all" );
// Positions a 10px tall element within 99px height at top 92px. // Positions a 10px tall element within 99px height at top 92px.
collisionTest( { collisionTest( assert, {
within: "#bug-8710-within-smaller", within: "#bug-8710-within-smaller",
of: "#parentx", of: "#parentx",
collision: "flip", collision: "flip",
@ -756,7 +757,7 @@ test( "bug #8710: flip if flipped position fits more", function() {
}, "flip - top fits more" ); }, "flip - top fits more" );
// Positions a 10px tall element within 101px height at top 92px. // Positions a 10px tall element within 101px height at top 92px.
collisionTest( { collisionTest( assert, {
within: "#bug-8710-within-bigger", within: "#bug-8710-within-bigger",
of: "#parentx", of: "#parentx",
collision: "flip", collision: "flip",