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

114 lines
2.9 KiB
JavaScript
Raw Normal View History

define( [
2016-04-06 13:13:06 +00:00
"qunit",
"jquery",
"lib/helper",
"ui/widgets/selectable"
], function( QUnit, $, helper ) {
QUnit.module( "selectable: methods", { afterEach: helper.moduleAfterEach } );
2016-04-06 13:13:06 +00:00
QUnit.test( "init", function( assert ) {
assert.expect( 5 );
2015-08-24 12:58:20 +00:00
$( "<div></div>" ).appendTo( "body" ).selectable().remove();
2016-04-06 13:13:06 +00:00
assert.ok( true, ".selectable() called on element" );
2015-08-24 12:58:20 +00:00
$( [] ).selectable().remove();
2016-04-06 13:13:06 +00:00
assert.ok( true, ".selectable() called on empty collection" );
2015-08-24 12:58:20 +00:00
$( "<div></div>" ).selectable().remove();
2016-04-06 13:13:06 +00:00
assert.ok( true, ".selectable() called on disconnected DOMElement" );
2015-08-24 12:58:20 +00:00
var el = $( "<div></div>" ).selectable();
el.selectable( "option", "foo" );
el.remove();
2016-04-06 13:13:06 +00:00
assert.ok( true, "arbitrary option getter after init" );
2015-08-24 12:58:20 +00:00
$( "<div></div>" ).selectable().selectable( "option", "foo", "bar" ).remove();
2016-04-06 13:13:06 +00:00
assert.ok( true, "arbitrary option setter after init" );
2015-08-24 12:58:20 +00:00
} );
2016-04-06 13:13:06 +00:00
QUnit.test( "destroy", function( assert ) {
assert.expect( 4 );
2015-08-24 12:58:20 +00:00
$( "<div></div>" ).appendTo( "body" ).selectable().selectable( "destroy" ).remove();
2016-04-06 13:13:06 +00:00
assert.ok( true, ".selectable('destroy') called on element" );
2015-08-24 12:58:20 +00:00
$( [] ).selectable().selectable( "destroy" ).remove();
2016-04-06 13:13:06 +00:00
assert.ok( true, ".selectable('destroy') called on empty collection" );
2015-08-24 12:58:20 +00:00
$( "<div></div>" ).selectable().selectable( "destroy" ).remove();
2016-04-06 13:13:06 +00:00
assert.ok( true, ".selectable('destroy') called on disconnected DOMElement" );
2015-08-24 12:58:20 +00:00
var expected = $( "<div></div>" ).selectable(),
actual = expected.selectable( "destroy" );
2016-04-06 13:13:06 +00:00
assert.equal( actual, expected, "destroy is chainable" );
2015-08-24 12:58:20 +00:00
} );
2016-04-06 13:13:06 +00:00
QUnit.test( "enable", function( assert ) {
assert.expect( 3 );
2012-04-19 02:46:39 +00:00
var expected, actual,
fired = false,
2015-08-24 12:58:20 +00:00
el = $( "#selectable1" );
2015-08-24 12:58:20 +00:00
el.selectable( {
disabled: true,
start: function() { fired = true; }
2015-08-24 12:58:20 +00:00
} );
el.simulate( "drag", {
dx: 20,
dy: 20
2015-08-24 12:58:20 +00:00
} );
2016-04-06 13:13:06 +00:00
assert.equal( fired, false, "start fired" );
2015-08-24 12:58:20 +00:00
el.selectable( "enable" );
el.simulate( "drag", {
dx: 20,
dy: 20
2015-08-24 12:58:20 +00:00
} );
2016-04-06 13:13:06 +00:00
assert.equal( fired, true, "start fired" );
2015-08-24 12:58:20 +00:00
el.selectable( "destroy" );
2015-08-24 12:58:20 +00:00
expected = $( "<div></div>" ).selectable();
actual = expected.selectable( "enable" );
2016-04-06 13:13:06 +00:00
assert.equal( actual, expected, "enable is chainable" );
2015-08-24 12:58:20 +00:00
} );
2016-04-06 13:13:06 +00:00
QUnit.test( "disable", function( assert ) {
assert.expect( 6 );
var chainable,
fired = false,
element = $( "#selectable1" );
2015-08-24 12:58:20 +00:00
element.selectable( {
disabled: false,
start: function() {
fired = true;
}
2015-08-24 12:58:20 +00:00
} );
element.simulate( "drag", {
dx: 20,
dy: 20
2015-08-24 12:58:20 +00:00
} );
2016-04-06 13:13:06 +00:00
assert.equal( fired, true, "start fired" );
chainable = element.selectable( "disable" );
fired = false;
element.simulate( "drag", {
dx: 20,
dy: 20
2015-08-24 12:58:20 +00:00
} );
2016-04-06 13:13:06 +00:00
assert.equal( fired, false, "start fired" );
assert.lacksClasses( element.selectable( "widget" ), "ui-state-disabled" );
2016-04-06 13:13:06 +00:00
assert.ok( !element.selectable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" );
assert.hasClasses( element.selectable( "widget" ), "ui-selectable-disabled" );
element.selectable( "destroy" );
2016-04-06 13:13:06 +00:00
assert.equal( chainable, element, "disable is chainable" );
2015-08-24 12:58:20 +00:00
} );
} );