2015-04-06 16:42:49 +00:00
|
|
|
define( [
|
2016-04-03 16:21:57 +00:00
|
|
|
"qunit",
|
2015-04-06 16:42:49 +00:00
|
|
|
"jquery",
|
2020-05-16 07:16:24 +00:00
|
|
|
"lib/helper",
|
2015-04-07 14:55:52 +00:00
|
|
|
"./helper",
|
2015-07-15 01:59:40 +00:00
|
|
|
"ui/widgets/draggable"
|
2020-05-16 07:16:24 +00:00
|
|
|
], function( QUnit, $, helper, testHelper ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
var element;
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.module( "draggable: methods", {
|
|
|
|
beforeEach: function() {
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "<div style='background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;'><span>Absolute</span></div>" ).appendTo( "#qunit-fixture" );
|
2013-01-12 05:33:45 +00:00
|
|
|
},
|
2016-04-03 16:21:57 +00:00
|
|
|
afterEach: function() {
|
2013-01-12 05:33:45 +00:00
|
|
|
element.remove();
|
2020-05-16 07:16:24 +00:00
|
|
|
return helper.moduleAfterEach.apply( this, arguments );
|
2013-01-12 05:33:45 +00:00
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "init", function( assert ) {
|
|
|
|
assert.expect( 5 );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable();
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( true, ".draggable() called on element" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
$( [] ).draggable();
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( true, ".draggable() called on empty collection" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
$( "<div></div>" ).draggable();
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( true, ".draggable() called on disconnected DOMElement" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable( "option", "foo" );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( true, "arbitrary option getter after init" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable( "option", "foo", "bar" );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( true, "arbitrary option setter after init" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "destroy", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.draggable().draggable( "destroy" );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( true, ".draggable('destroy') called on element" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
$( [] ).draggable().draggable( "destroy" );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( true, ".draggable('destroy') called on empty collection" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.draggable().draggable( "destroy" );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( true, ".draggable('destroy') called on disconnected DOMElement" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
var expected = element.draggable(),
|
2015-08-24 12:59:44 +00:00
|
|
|
actual = expected.draggable( "destroy" );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( actual, expected, "destroy is chainable" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "enable", function( assert ) {
|
|
|
|
assert.expect( 11 );
|
2012-11-03 20:17:16 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.draggable( { disabled: true } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldNotDrag( assert, element, ".draggable({ disabled: true })" );
|
2012-11-03 20:17:16 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.draggable( "enable" );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, ".draggable('enable')" );
|
|
|
|
assert.equal( element.draggable( "option", "disabled" ), false, "disabled option getter" );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element.draggable( "destroy" );
|
|
|
|
element.draggable( { disabled: true } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldNotDrag( assert, element, ".draggable({ disabled: true })" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable( "option", "disabled", false );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( element.draggable( "option", "disabled" ), false, "disabled option setter" );
|
|
|
|
testHelper.shouldMove( assert, element, ".draggable('option', 'disabled', false)" );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
var expected = element.draggable(),
|
2015-08-24 12:59:44 +00:00
|
|
|
actual = expected.draggable( "enable" );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( actual, expected, "enable is chainable" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "disable", function( assert ) {
|
|
|
|
assert.expect( 14 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#draggable2" ).draggable( { disabled: false } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, ".draggable({ disabled: false })" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-14 23:08:21 +00:00
|
|
|
element.draggable( "disable" );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldNotDrag( assert, element, ".draggable('disable')" );
|
|
|
|
assert.equal( element.draggable( "option", "disabled" ), true, "disabled option getter" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-14 23:08:21 +00:00
|
|
|
element.draggable( "destroy" );
|
2015-08-24 12:59:44 +00:00
|
|
|
element.draggable( { disabled: false } );
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, ".draggable({ disabled: false })" );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable( "option", "disabled", true );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( element.draggable( "option", "disabled" ), true, "disabled option setter" );
|
|
|
|
testHelper.shouldNotDrag( assert, element, ".draggable('option', 'disabled', true)" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2015-01-30 14:57:30 +00:00
|
|
|
assert.lacksClasses( element.draggable( "widget" ), "ui-state-disabled" );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( !element.draggable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" );
|
2015-01-30 14:57:30 +00:00
|
|
|
assert.hasClasses( element.draggable( "widget" ), "ui-draggable-disabled" );
|
2013-03-14 23:08:21 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
var expected = element.draggable(),
|
2013-03-14 23:08:21 +00:00
|
|
|
actual = expected.draggable( "disable" );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( actual, expected, "disable is chainable" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2015-04-06 16:42:49 +00:00
|
|
|
} );
|