2015-04-06 16:42:49 +00:00
|
|
|
define( [
|
|
|
|
"jquery",
|
|
|
|
"./draggable_test_helpers",
|
|
|
|
"ui/draggable"
|
|
|
|
], function( $, draggableTestHelpers ) {
|
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
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
module( "draggable: methods", {
|
|
|
|
setup: function() {
|
|
|
|
element = $("<div style='background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;'><span>Absolute</span></div>").appendTo("#qunit-fixture");
|
|
|
|
},
|
|
|
|
teardown: function() {
|
|
|
|
element.remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test( "init", function() {
|
|
|
|
expect( 5 );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable();
|
|
|
|
ok( true, ".draggable() called on element" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
|
|
|
$([]).draggable();
|
2013-01-12 05:33:45 +00:00
|
|
|
ok( true, ".draggable() called on empty collection" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
|
|
|
$("<div></div>").draggable();
|
2013-01-12 05:33:45 +00:00
|
|
|
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" );
|
|
|
|
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" );
|
|
|
|
ok( true, "arbitrary option setter after init" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "destroy", function() {
|
|
|
|
expect( 4 );
|
|
|
|
|
|
|
|
element.draggable().draggable("destroy");
|
|
|
|
ok( true, ".draggable('destroy') called on element" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
|
|
|
$([]).draggable().draggable("destroy");
|
2013-01-12 05:33:45 +00:00
|
|
|
ok( true, ".draggable('destroy') called on empty collection" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable().draggable("destroy");
|
|
|
|
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(),
|
2012-12-26 13:08:48 +00:00
|
|
|
actual = expected.draggable("destroy");
|
2013-01-12 05:33:45 +00:00
|
|
|
equal( actual, expected, "destroy is chainable" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "enable", function() {
|
2014-08-22 15:51:15 +00:00
|
|
|
expect( 11 );
|
2012-11-03 20:17:16 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable({ disabled: true });
|
2015-04-06 16:42:49 +00:00
|
|
|
draggableTestHelpers.shouldNotDrag( element, ".draggable({ disabled: true })" );
|
2012-11-03 20:17:16 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable("enable");
|
2015-04-06 16:42:49 +00:00
|
|
|
draggableTestHelpers.shouldMove( element, ".draggable('enable')" );
|
2013-01-12 05:33:45 +00:00
|
|
|
equal( element.draggable( "option", "disabled" ), false, "disabled option getter" );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable("destroy");
|
|
|
|
element.draggable({ disabled: true });
|
2015-04-06 16:42:49 +00:00
|
|
|
draggableTestHelpers.shouldNotDrag( 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 );
|
|
|
|
equal(element.draggable( "option", "disabled" ), false, "disabled option setter" );
|
2015-04-06 16:42:49 +00:00
|
|
|
draggableTestHelpers.shouldMove( 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(),
|
|
|
|
actual = expected.draggable("enable");
|
|
|
|
equal( actual, expected, "enable is chainable" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2015-01-30 14:57:30 +00:00
|
|
|
test( "disable", function( assert ) {
|
2014-08-22 15:51:15 +00:00
|
|
|
expect( 14 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-03-14 23:08:21 +00:00
|
|
|
element = $( "#draggable2" ).draggable({ disabled: false });
|
2015-04-06 16:42:49 +00:00
|
|
|
draggableTestHelpers.shouldMove( element, ".draggable({ disabled: false })" );
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-03-14 23:08:21 +00:00
|
|
|
element.draggable( "disable" );
|
2015-04-06 16:42:49 +00:00
|
|
|
draggableTestHelpers.shouldNotDrag( element, ".draggable('disable')" );
|
2013-01-12 05:33:45 +00:00
|
|
|
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" );
|
2013-01-12 05:33:45 +00:00
|
|
|
element.draggable({ disabled: false });
|
2015-04-06 16:42:49 +00:00
|
|
|
draggableTestHelpers.shouldMove( 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 );
|
|
|
|
equal( element.draggable( "option", "disabled" ), true, "disabled option setter" );
|
2015-04-06 16:42:49 +00:00
|
|
|
draggableTestHelpers.shouldNotDrag( 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" );
|
2013-03-14 23:08:21 +00:00
|
|
|
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" );
|
2013-01-12 05:33:45 +00:00
|
|
|
equal( actual, expected, "disable is chainable" );
|
2009-02-01 00:25:58 +00:00
|
|
|
});
|
|
|
|
|
2015-04-06 16:42:49 +00:00
|
|
|
} );
|