| 1 |
define( [ |
| 2 |
"qunit", |
| 3 |
"jquery", |
| 4 |
"lib/helper", |
| 5 |
"ui/widgets/dialog" |
| 6 |
], function( QUnit, $, helper ) { |
| 7 |
"use strict"; |
| 8 |
|
| 9 |
return $.extend( helper, { |
| 10 |
drag: function( element, handle, dx, dy ) { |
| 11 |
var d = element.dialog( "widget" ); |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
$( handle, d ).simulate( "mouseover" ).simulate( "drag", { |
| 16 |
dx: dx, |
| 17 |
dy: dy |
| 18 |
} ); |
| 19 |
}, |
| 20 |
testDrag: function( assert, element, dx, dy, expectedDX, expectedDY, msg ) { |
| 21 |
var actualDX, actualDY, offsetAfter, |
| 22 |
d = element.dialog( "widget" ), |
| 23 |
handle = $( ".ui-dialog-titlebar", d ), |
| 24 |
offsetBefore = d.offset(); |
| 25 |
|
| 26 |
this.drag( element, handle, dx, dy ); |
| 27 |
|
| 28 |
offsetAfter = d.offset(); |
| 29 |
|
| 30 |
msg = msg ? msg + "." : ""; |
| 31 |
|
| 32 |
actualDX = offsetAfter.left - offsetBefore.left; |
| 33 |
actualDY = offsetAfter.top - offsetBefore.top; |
| 34 |
assert.ok( expectedDX - actualDX <= 1 && expectedDY - actualDY <= 1, "dragged[" + expectedDX + ", " + expectedDY + "] " + msg ); |
| 35 |
}, |
| 36 |
|
| 37 |
shouldResize: function( assert, element, dw, dh, msg ) { |
| 38 |
var actualDH, actualDW, heightAfter, widthAfter, |
| 39 |
d = element.dialog( "widget" ), |
| 40 |
handle = $( ".ui-resizable-se", d ), |
| 41 |
heightBefore = element.height(), |
| 42 |
widthBefore = element.width(); |
| 43 |
|
| 44 |
this.drag( element, handle, 50, 50 ); |
| 45 |
|
| 46 |
heightAfter = element.height(); |
| 47 |
widthAfter = element.width(); |
| 48 |
|
| 49 |
msg = msg ? msg + "." : ""; |
| 50 |
|
| 51 |
actualDH = heightAfter - heightBefore; |
| 52 |
actualDW = widthAfter - widthBefore; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
assert.ok( Math.abs( actualDH - dh ) <= 1 && Math.abs( actualDW - dw ) <= 1, "resized[50, 50] " + msg ); |
| 57 |
} |
| 58 |
} ); |
| 59 |
|
| 60 |
} ); |