jquery-ui/tests/unit/draggable/methods.js

105 lines
3.3 KiB
JavaScript
Raw Normal View History

define( [
"jquery",
2015-04-07 14:55:52 +00:00
"./helper",
"ui/widgets/draggable"
], function( $, testHelper ) {
var element;
module( "draggable: methods", {
setup: 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" );
},
teardown: function() {
element.remove();
}
2015-08-24 12:59:44 +00:00
} );
test( "init", function() {
expect( 5 );
element.draggable();
ok( true, ".draggable() called on element" );
2015-08-24 12:59:44 +00:00
$( [] ).draggable();
ok( true, ".draggable() called on empty collection" );
2015-08-24 12:59:44 +00:00
$( "<div></div>" ).draggable();
ok( true, ".draggable() called on disconnected DOMElement" );
element.draggable( "option", "foo" );
ok( true, "arbitrary option getter after init" );
element.draggable( "option", "foo", "bar" );
ok( true, "arbitrary option setter after init" );
2015-08-24 12:59:44 +00:00
} );
test( "destroy", function() {
expect( 4 );
2015-08-24 12:59:44 +00:00
element.draggable().draggable( "destroy" );
ok( true, ".draggable('destroy') called on element" );
2015-08-24 12:59:44 +00:00
$( [] ).draggable().draggable( "destroy" );
ok( true, ".draggable('destroy') called on empty collection" );
2015-08-24 12:59:44 +00:00
element.draggable().draggable( "destroy" );
ok( true, ".draggable('destroy') called on disconnected DOMElement" );
var expected = element.draggable(),
2015-08-24 12:59:44 +00:00
actual = expected.draggable( "destroy" );
equal( actual, expected, "destroy is chainable" );
2015-08-24 12:59:44 +00:00
} );
test( "enable", function() {
expect( 11 );
2015-08-24 12:59:44 +00:00
element.draggable( { disabled: true } );
testHelper.shouldNotDrag( element, ".draggable({ disabled: true })" );
2015-08-24 12:59:44 +00:00
element.draggable( "enable" );
testHelper.shouldMove( element, ".draggable('enable')" );
equal( element.draggable( "option", "disabled" ), false, "disabled option getter" );
2015-08-24 12:59:44 +00:00
element.draggable( "destroy" );
element.draggable( { disabled: true } );
testHelper.shouldNotDrag( element, ".draggable({ disabled: true })" );
element.draggable( "option", "disabled", false );
2015-08-24 12:59:44 +00:00
equal( element.draggable( "option", "disabled" ), false, "disabled option setter" );
testHelper.shouldMove( element, ".draggable('option', 'disabled', false)" );
var expected = element.draggable(),
2015-08-24 12:59:44 +00:00
actual = expected.draggable( "enable" );
equal( actual, expected, "enable is chainable" );
2015-08-24 12:59:44 +00:00
} );
test( "disable", function( assert ) {
expect( 14 );
2015-08-24 12:59:44 +00:00
element = $( "#draggable2" ).draggable( { disabled: false } );
testHelper.shouldMove( element, ".draggable({ disabled: false })" );
element.draggable( "disable" );
testHelper.shouldNotDrag( element, ".draggable('disable')" );
equal( element.draggable( "option", "disabled" ), true, "disabled option getter" );
element.draggable( "destroy" );
2015-08-24 12:59:44 +00:00
element.draggable( { disabled: false } );
testHelper.shouldMove( element, ".draggable({ disabled: false })" );
element.draggable( "option", "disabled", true );
equal( element.draggable( "option", "disabled" ), true, "disabled option setter" );
testHelper.shouldNotDrag( element, ".draggable('option', 'disabled', true)" );
assert.lacksClasses( element.draggable( "widget" ), "ui-state-disabled" );
ok( !element.draggable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" );
assert.hasClasses( element.draggable( "widget" ), "ui-draggable-disabled" );
var expected = element.draggable(),
actual = expected.draggable( "disable" );
equal( actual, expected, "disable is chainable" );
2015-08-24 12:59:44 +00:00
} );
} );