| 1 |
define( [ |
| 2 |
"qunit", |
| 3 |
"jquery", |
| 4 |
"lib/helper", |
| 5 |
"ui/widgets/selectable" |
| 6 |
], function( QUnit, $, testHelpers ) { |
| 7 |
"use strict"; |
| 8 |
|
| 9 |
QUnit.module( "selectable: events", { afterEach: testHelpers.moduleAfterEach } ); |
| 10 |
|
| 11 |
QUnit.test( "start", function( assert ) { |
| 12 |
assert.expect( 2 ); |
| 13 |
var el = $( "#selectable1" ); |
| 14 |
el.selectable( { |
| 15 |
start: function() { |
| 16 |
assert.ok( true, "drag fired start callback" ); |
| 17 |
assert.equal( this, el[ 0 ], "context of callback" ); |
| 18 |
} |
| 19 |
} ); |
| 20 |
el.simulate( "drag", { |
| 21 |
dx: 20, |
| 22 |
dy: 20 |
| 23 |
} ); |
| 24 |
} ); |
| 25 |
|
| 26 |
QUnit.test( "stop", function( assert ) { |
| 27 |
assert.expect( 2 ); |
| 28 |
var el = $( "#selectable1" ); |
| 29 |
el.selectable( { |
| 30 |
start: function() { |
| 31 |
assert.ok( true, "drag fired stop callback" ); |
| 32 |
assert.equal( this, el[ 0 ], "context of callback" ); |
| 33 |
} |
| 34 |
} ); |
| 35 |
el.simulate( "drag", { |
| 36 |
dx: 20, |
| 37 |
dy: 20 |
| 38 |
} ); |
| 39 |
} ); |
| 40 |
|
| 41 |
QUnit.test( "mousedown: initial position of helper", function( assert ) { |
| 42 |
assert.expect( 2 ); |
| 43 |
|
| 44 |
var helperOffset, |
| 45 |
element = $( "#selectable1" ).selectable(), |
| 46 |
contentToForceScroll = testHelpers.forceScrollableWindow( "body" ); |
| 47 |
|
| 48 |
$( window ).scrollTop( 100 ).scrollLeft( 100 ); |
| 49 |
|
| 50 |
element.simulate( "mousedown", { |
| 51 |
clientX: 10, |
| 52 |
clientY: 10 |
| 53 |
} ); |
| 54 |
|
| 55 |
helperOffset = $( ".ui-selectable-helper" ).offset(); |
| 56 |
assert.ok( helperOffset.top, 110, "Scroll top should be accounted for." ); |
| 57 |
assert.ok( helperOffset.left, 110, "Scroll left should be accounted for." ); |
| 58 |
|
| 59 |
|
| 60 |
element.simulate( "mouseup" ); |
| 61 |
contentToForceScroll.remove(); |
| 62 |
$( window ).scrollTop( 0 ).scrollLeft( 0 ); |
| 63 |
} ); |
| 64 |
|
| 65 |
} ); |