2015-04-06 18:38:11 +00:00
|
|
|
define( [
|
2016-04-06 13:13:06 +00:00
|
|
|
"qunit",
|
2015-04-06 18:38:11 +00:00
|
|
|
"jquery",
|
2015-07-15 02:05:54 +00:00
|
|
|
"ui/widgets/selectable"
|
2016-04-06 13:13:06 +00:00
|
|
|
], function( QUnit, $ ) {
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2016-04-06 13:13:06 +00:00
|
|
|
QUnit.module( "selectable: methods" );
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2016-04-06 13:13:06 +00:00
|
|
|
QUnit.test( "init", function( assert ) {
|
|
|
|
assert.expect( 5 );
|
2009-02-04 04:53:09 +00:00
|
|
|
|
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" );
|
2009-02-04 04:53:09 +00:00
|
|
|
|
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" );
|
2009-02-04 04:53:09 +00:00
|
|
|
|
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" );
|
2009-02-04 04:53:09 +00:00
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
var el = $( "<div></div>" ).selectable();
|
|
|
|
el.selectable( "option", "foo" );
|
2009-02-04 04:53:09 +00:00
|
|
|
el.remove();
|
2016-04-06 13:13:06 +00:00
|
|
|
assert.ok( true, "arbitrary option getter after init" );
|
2009-02-04 04:53:09 +00:00
|
|
|
|
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
|
|
|
} );
|
2009-02-04 04:53:09 +00:00
|
|
|
|
2016-04-06 13:13:06 +00:00
|
|
|
QUnit.test( "destroy", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2012-10-31 01:50:08 +00:00
|
|
|
|
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" );
|
2009-02-04 04:53:09 +00:00
|
|
|
|
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" );
|
2009-02-04 04:53:09 +00:00
|
|
|
|
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" );
|
2009-02-04 04:53:09 +00:00
|
|
|
|
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
|
|
|
} );
|
2009-02-04 04:53:09 +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,
|
2012-10-31 01:50:08 +00:00
|
|
|
fired = false,
|
2015-08-24 12:58:20 +00:00
|
|
|
el = $( "#selectable1" );
|
2009-02-04 04:53:09 +00:00
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
el.selectable( {
|
2009-02-04 04:53:09 +00:00
|
|
|
disabled: true,
|
|
|
|
start: function() { fired = true; }
|
2015-08-24 12:58:20 +00:00
|
|
|
} );
|
2012-12-09 02:27:37 +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" );
|
2012-12-09 02:27:37 +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, true, "start fired" );
|
2015-08-24 12:58:20 +00:00
|
|
|
el.selectable( "destroy" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
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
|
|
|
} );
|
2009-02-04 04:53:09 +00:00
|
|
|
|
2016-04-06 13:13:06 +00:00
|
|
|
QUnit.test( "disable", function( assert ) {
|
|
|
|
assert.expect( 6 );
|
2013-03-14 23:08:21 +00:00
|
|
|
var chainable,
|
2012-10-31 01:50:08 +00:00
|
|
|
fired = false,
|
2013-03-14 23:08:21 +00:00
|
|
|
element = $( "#selectable1" );
|
2009-02-04 04:53:09 +00:00
|
|
|
|
2015-08-24 12:58:20 +00:00
|
|
|
element.selectable( {
|
2009-02-04 04:53:09 +00:00
|
|
|
disabled: false,
|
2013-03-14 23:08:21 +00:00
|
|
|
start: function() {
|
|
|
|
fired = true;
|
|
|
|
}
|
2015-08-24 12:58:20 +00:00
|
|
|
} );
|
2013-03-14 23:08:21 +00:00
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
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" );
|
2013-03-14 23:08:21 +00:00
|
|
|
|
|
|
|
chainable = element.selectable( "disable" );
|
2009-02-04 04:53:09 +00:00
|
|
|
fired = false;
|
2012-12-09 02:27:37 +00:00
|
|
|
|
2013-03-14 23:08:21 +00:00
|
|
|
element.simulate( "drag", {
|
2012-12-09 02:27:37 +00:00
|
|
|
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" );
|
2013-03-12 01:28:51 +00:00
|
|
|
|
2015-01-30 15:00:11 +00:00
|
|
|
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" );
|
2015-01-30 15:00:11 +00:00
|
|
|
assert.hasClasses( element.selectable( "widget" ), "ui-selectable-disabled" );
|
2013-03-14 23:08:21 +00:00
|
|
|
|
|
|
|
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
|
|
|
} );
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2015-04-06 18:38:11 +00:00
|
|
|
} );
|