| 1 |
define( [ |
| 2 |
"qunit", |
| 3 |
"jquery", |
| 4 |
"lib/helper", |
| 5 |
"./helper", |
| 6 |
"ui/widgets/sortable" |
| 7 |
], function( QUnit, $, helper, testHelper ) { |
| 8 |
"use strict"; |
| 9 |
|
| 10 |
QUnit.module( "sortable: core", { afterEach: helper.moduleAfterEach } ); |
| 11 |
|
| 12 |
QUnit.test( "#9314: Sortable: Items cannot be dragged directly into bottom position", function( assert ) { |
| 13 |
assert.expect( 1 ); |
| 14 |
|
| 15 |
var el = $( ".connectWith" ).sortable( { |
| 16 |
connectWith: ".connectWith" |
| 17 |
} ); |
| 18 |
|
| 19 |
testHelper.sort( assert, $( "li", el[ 1 ] )[ 0 ], 0, -12, 5, "Dragging the sortable into connected sortable" ); |
| 20 |
} ); |
| 21 |
|
| 22 |
QUnit.test( "ui-sortable-handle applied to appropriate element", function( assert ) { |
| 23 |
assert.expect( 8 ); |
| 24 |
var item = "<li><p></p></li>", |
| 25 |
el = $( "<ul>" + item + item + "</ul>" ) |
| 26 |
.sortable() |
| 27 |
.appendTo( "#qunit-fixture" ); |
| 28 |
|
| 29 |
assert.hasClasses( el.find( "li" ).first(), "ui-sortable-handle" ); |
| 30 |
assert.hasClasses( el.find( "li" ).last(), "ui-sortable-handle" ); |
| 31 |
|
| 32 |
el.sortable( "option", "handle", "p" ); |
| 33 |
assert.lacksClasses( el.find( "li" )[ 0 ], "ui-sortable-handle" ); |
| 34 |
assert.lacksClasses( el.find( "li" )[ 1 ], "ui-sortable-handle" ); |
| 35 |
assert.hasClasses( el.find( "p" )[ 0 ], "ui-sortable-handle" ); |
| 36 |
assert.hasClasses( el.find( "p" )[ 1 ], "ui-sortable-handle" ); |
| 37 |
|
| 38 |
el.append( item ).sortable( "refresh" ); |
| 39 |
assert.hasClasses( el.find( "p" ).last(), "ui-sortable-handle" ); |
| 40 |
|
| 41 |
el.sortable( "destroy" ); |
| 42 |
assert.equal( el.find( ".ui-sortable-handle" ).length, 0, "class name removed on destroy" ); |
| 43 |
} ); |
| 44 |
|
| 45 |
|
| 46 |
QUnit.test( "drag & drop works with a zero-height container", function( assert ) { |
| 47 |
var ready = assert.async(); |
| 48 |
assert.expect( 3 ); |
| 49 |
|
| 50 |
var el = $( "<ul class='list-gh-1998'>\n" + |
| 51 |
" <style>" + |
| 52 |
" .list-gh-1998 {\n" + |
| 53 |
" margin: 0;\n" + |
| 54 |
" padding: 0;\n" + |
| 55 |
" }\n" + |
| 56 |
" .list-item-gh-1998 {\n" + |
| 57 |
" float: left;\n" + |
| 58 |
" display: block;\n" + |
| 59 |
" width: 100px;\n" + |
| 60 |
" height: 100px;\n" + |
| 61 |
" }\n" + |
| 62 |
" </style>\n" + |
| 63 |
" <li class='list-item-gh-1998'>Item 1</li>\n" + |
| 64 |
" <li class='list-item-gh-1998'>Item 2</li>\n" + |
| 65 |
" <li class='list-item-gh-1998'>Item 3</li>\n" + |
| 66 |
"</ul>" ) |
| 67 |
.sortable() |
| 68 |
.appendTo( "#qunit-fixture" ); |
| 69 |
|
| 70 |
function step1() { |
| 71 |
el.find( "li" ).eq( 0 ).simulate( "drag", { |
| 72 |
dx: 100, |
| 73 |
dy: 3, |
| 74 |
moves: 3 |
| 75 |
} ); |
| 76 |
setTimeout( step2 ); |
| 77 |
} |
| 78 |
|
| 79 |
function step2() { |
| 80 |
el.find( "li" ).eq( 2 ).simulate( "drag", { |
| 81 |
dx: -200, |
| 82 |
dy: -3, |
| 83 |
moves: 3 |
| 84 |
} ); |
| 85 |
setTimeout( step3 ); |
| 86 |
} |
| 87 |
|
| 88 |
function step3() { |
| 89 |
assert.equal( el.find( "li" ).eq( 0 ).text(), "Item 3" ); |
| 90 |
assert.equal( el.find( "li" ).eq( 1 ).text(), "Item 2" ); |
| 91 |
assert.equal( el.find( "li" ).eq( 2 ).text(), "Item 1" ); |
| 92 |
ready(); |
| 93 |
} |
| 94 |
|
| 95 |
step1(); |
| 96 |
} ); |
| 97 |
|
| 98 |
} ); |