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

112 lines
2.7 KiB
JavaScript
Raw Normal View History

define( [
"jquery",
"ui/widgets/selectable"
], function( $ ) {
2015-08-24 12:58:20 +00:00
module( "selectable: methods" );
2015-08-24 12:58:20 +00:00
test( "init", function() {
expect( 5 );
2015-08-24 12:58:20 +00:00
$( "<div></div>" ).appendTo( "body" ).selectable().remove();
ok( true, ".selectable() called on element" );
2015-08-24 12:58:20 +00:00
$( [] ).selectable().remove();
ok( true, ".selectable() called on empty collection" );
2015-08-24 12:58:20 +00:00
$( "<div></div>" ).selectable().remove();
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();
2015-08-24 12:58:20 +00:00
ok( true, "arbitrary option getter after init" );
2015-08-24 12:58:20 +00:00
$( "<div></div>" ).selectable().selectable( "option", "foo", "bar" ).remove();
ok( true, "arbitrary option setter after init" );
} );
2015-08-24 12:58:20 +00:00
test( "destroy", function() {
expect( 4 );
2015-08-24 12:58:20 +00:00
$( "<div></div>" ).appendTo( "body" ).selectable().selectable( "destroy" ).remove();
ok( true, ".selectable('destroy') called on element" );
2015-08-24 12:58:20 +00:00
$( [] ).selectable().selectable( "destroy" ).remove();
ok( true, ".selectable('destroy') called on empty collection" );
2015-08-24 12:58:20 +00:00
$( "<div></div>" ).selectable().selectable( "destroy" ).remove();
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" );
equal( actual, expected, "destroy is chainable" );
} );
2015-08-24 12:58:20 +00:00
test( "enable", function() {
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
} );
equal( fired, false, "start fired" );
el.selectable( "enable" );
el.simulate( "drag", {
dx: 20,
dy: 20
2015-08-24 12:58:20 +00:00
} );
equal( fired, true, "start fired" );
el.selectable( "destroy" );
2015-08-24 12:58:20 +00:00
expected = $( "<div></div>" ).selectable();
actual = expected.selectable( "enable" );
equal( actual, expected, "enable is chainable" );
} );
test( "disable", function( 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
} );
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
} );
equal( fired, false, "start fired" );
assert.lacksClasses( element.selectable( "widget" ), "ui-state-disabled" );
ok( !element.selectable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" );
assert.hasClasses( element.selectable( "widget" ), "ui-selectable-disabled" );
element.selectable( "destroy" );
equal( chainable, element, "disable is chainable" );
2015-08-24 12:58:20 +00:00
} );
} );