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

108 lines
3.6 KiB
JavaScript
Raw Normal View History

define( [
2016-04-03 16:21:57 +00:00
"qunit",
"jquery",
"lib/helper",
2015-04-07 14:55:52 +00:00
"./helper",
"ui/widgets/draggable"
], function( QUnit, $, helper, testHelper ) {
var element;
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" );
},
2016-04-03 16:21:57 +00:00
afterEach: function() {
element.remove();
return helper.moduleAfterEach.apply( this, arguments );
}
2015-08-24 12:59:44 +00:00
} );
2016-04-03 16:21:57 +00:00
QUnit.test( "init", function( assert ) {
assert.expect( 5 );
element.draggable();
2016-04-03 16:21:57 +00:00
assert.ok( true, ".draggable() called on element" );
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" );
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" );
element.draggable( "option", "foo" );
2016-04-03 16:21:57 +00:00
assert.ok( true, "arbitrary option getter after init" );
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
} );
2016-04-03 16:21:57 +00:00
QUnit.test( "destroy", function( assert ) {
assert.expect( 4 );
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" );
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" );
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" );
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
} );
2016-04-03 16:21:57 +00:00
QUnit.test( "enable", function( assert ) {
assert.expect( 11 );
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 })" );
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" );
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 })" );
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)" );
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
} );
2016-04-03 16:21:57 +00:00
QUnit.test( "disable", function( assert ) {
assert.expect( 14 );
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 })" );
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" );
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 })" );
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)" );
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" );
assert.hasClasses( element.draggable( "widget" ), "ui-draggable-disabled" );
var expected = element.draggable(),
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
} );
} );