jquery-ui/tests/unit/dialog/helper.js

59 lines
1.8 KiB
JavaScript
Raw Normal View History

define( [
2016-04-03 16:10:09 +00:00
"qunit",
"jquery",
"lib/helper",
"ui/widgets/dialog"
2016-04-03 16:10:09 +00:00
], function( QUnit, $, helper ) {
return $.extend( helper, {
2015-08-24 12:59:54 +00:00
drag: function( element, handle, dx, dy ) {
var d = element.dialog( "widget" );
2016-04-03 16:10:09 +00:00
//This mouseover is to work around a limitation in resizable
//TODO: fix resizable so handle doesn't require mouseover in order to be used
2015-08-24 12:59:54 +00:00
$( handle, d ).simulate( "mouseover" ).simulate( "drag", {
dx: dx,
dy: dy
2015-08-24 12:59:54 +00:00
} );
},
2016-04-03 16:10:09 +00:00
testDrag: function( assert, element, dx, dy, expectedDX, expectedDY, msg ) {
var actualDX, actualDY, offsetAfter,
2015-08-24 12:59:54 +00:00
d = element.dialog( "widget" ),
handle = $( ".ui-dialog-titlebar", d ),
offsetBefore = d.offset();
2015-08-24 12:59:54 +00:00
this.drag( element, handle, dx, dy );
offsetAfter = d.offset();
msg = msg ? msg + "." : "";
actualDX = offsetAfter.left - offsetBefore.left;
actualDY = offsetAfter.top - offsetBefore.top;
2016-04-03 16:10:09 +00:00
assert.ok( expectedDX - actualDX <= 1 && expectedDY - actualDY <= 1, "dragged[" + expectedDX + ", " + expectedDY + "] " + msg );
},
2015-08-24 12:59:54 +00:00
// TODO switch back to checking the size of the .ui-dialog element (var d)
// once we switch to using box-sizing: border-box (#9845) that should work fine
// using the element's dimensions to avoid subpixel errors
2016-04-03 16:10:09 +00:00
shouldResize: function( assert, element, dw, dh, msg ) {
var heightAfter, widthAfter, actual, expected,
2015-08-24 12:59:54 +00:00
d = element.dialog( "widget" ),
handle = $( ".ui-resizable-se", d ),
heightBefore = element.height(),
widthBefore = element.width();
2015-08-24 12:59:54 +00:00
this.drag( element, handle, 50, 50 );
heightAfter = element.height();
widthAfter = element.width();
msg = msg ? msg + "." : "";
actual = { width: widthAfter, height: heightAfter },
expected = { width: widthBefore + dw, height: heightBefore + dh };
2016-04-03 16:10:09 +00:00
assert.deepEqual( actual, expected, "resized[" + 50 + ", " + 50 + "] " + msg );
}
} );
} );