Selectable: Shift to use no globals

This commit is contained in:
Amanpreet Singh 2016-04-06 18:43:06 +05:30
parent 611e3648b5
commit b6392d6a6d
3 changed files with 54 additions and 51 deletions

View File

@ -1,18 +1,19 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"lib/helper", "lib/helper",
"ui/widgets/selectable" "ui/widgets/selectable"
], function( $, testHelpers ) { ], function( QUnit, $, testHelpers ) {
module( "selectable: events" ); QUnit.module( "selectable: events" );
test( "start", function() { QUnit.test( "start", function( assert ) {
expect( 2 ); assert.expect( 2 );
var el = $( "#selectable1" ); var el = $( "#selectable1" );
el.selectable( { el.selectable( {
start: function() { start: function() {
ok( true, "drag fired start callback" ); assert.ok( true, "drag fired start callback" );
equal( this, el[ 0 ], "context of callback" ); assert.equal( this, el[ 0 ], "context of callback" );
} }
} ); } );
el.simulate( "drag", { el.simulate( "drag", {
@ -21,13 +22,13 @@ test( "start", function() {
} ); } );
} ); } );
test( "stop", function() { QUnit.test( "stop", function( assert ) {
expect( 2 ); assert.expect( 2 );
var el = $( "#selectable1" ); var el = $( "#selectable1" );
el.selectable( { el.selectable( {
start: function() { start: function() {
ok( true, "drag fired stop callback" ); assert.ok( true, "drag fired stop callback" );
equal( this, el[ 0 ], "context of callback" ); assert.equal( this, el[ 0 ], "context of callback" );
} }
} ); } );
el.simulate( "drag", { el.simulate( "drag", {
@ -36,8 +37,8 @@ test( "stop", function() {
} ); } );
} ); } );
test( "mousedown: initial position of helper", function() { QUnit.test( "mousedown: initial position of helper", function( assert ) {
expect( 2 ); assert.expect( 2 );
var helperOffset, var helperOffset,
element = $( "#selectable1" ).selectable(), element = $( "#selectable1" ).selectable(),
@ -51,8 +52,8 @@ test( "mousedown: initial position of helper", function() {
} ); } );
helperOffset = $( ".ui-selectable-helper" ).offset(); helperOffset = $( ".ui-selectable-helper" ).offset();
ok( helperOffset.top, 110, "Scroll top should be accounted for." ); assert.ok( helperOffset.top, 110, "Scroll top should be accounted for." );
ok( helperOffset.left, 110, "Scroll left should be accounted for." ); assert.ok( helperOffset.left, 110, "Scroll left should be accounted for." );
// Cleanup // Cleanup
element.simulate( "mouseup" ); element.simulate( "mouseup" );

View File

@ -1,50 +1,51 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/selectable" "ui/widgets/selectable"
], function( $ ) { ], function( QUnit, $ ) {
module( "selectable: methods" ); QUnit.module( "selectable: methods" );
test( "init", function() { QUnit.test( "init", function( assert ) {
expect( 5 ); assert.expect( 5 );
$( "<div></div>" ).appendTo( "body" ).selectable().remove(); $( "<div></div>" ).appendTo( "body" ).selectable().remove();
ok( true, ".selectable() called on element" ); assert.ok( true, ".selectable() called on element" );
$( [] ).selectable().remove(); $( [] ).selectable().remove();
ok( true, ".selectable() called on empty collection" ); assert.ok( true, ".selectable() called on empty collection" );
$( "<div></div>" ).selectable().remove(); $( "<div></div>" ).selectable().remove();
ok( true, ".selectable() called on disconnected DOMElement" ); assert.ok( true, ".selectable() called on disconnected DOMElement" );
var el = $( "<div></div>" ).selectable(); var el = $( "<div></div>" ).selectable();
el.selectable( "option", "foo" ); el.selectable( "option", "foo" );
el.remove(); el.remove();
ok( true, "arbitrary option getter after init" ); assert.ok( true, "arbitrary option getter after init" );
$( "<div></div>" ).selectable().selectable( "option", "foo", "bar" ).remove(); $( "<div></div>" ).selectable().selectable( "option", "foo", "bar" ).remove();
ok( true, "arbitrary option setter after init" ); assert.ok( true, "arbitrary option setter after init" );
} ); } );
test( "destroy", function() { QUnit.test( "destroy", function( assert ) {
expect( 4 ); assert.expect( 4 );
$( "<div></div>" ).appendTo( "body" ).selectable().selectable( "destroy" ).remove(); $( "<div></div>" ).appendTo( "body" ).selectable().selectable( "destroy" ).remove();
ok( true, ".selectable('destroy') called on element" ); assert.ok( true, ".selectable('destroy') called on element" );
$( [] ).selectable().selectable( "destroy" ).remove(); $( [] ).selectable().selectable( "destroy" ).remove();
ok( true, ".selectable('destroy') called on empty collection" ); assert.ok( true, ".selectable('destroy') called on empty collection" );
$( "<div></div>" ).selectable().selectable( "destroy" ).remove(); $( "<div></div>" ).selectable().selectable( "destroy" ).remove();
ok( true, ".selectable('destroy') called on disconnected DOMElement" ); assert.ok( true, ".selectable('destroy') called on disconnected DOMElement" );
var expected = $( "<div></div>" ).selectable(), var expected = $( "<div></div>" ).selectable(),
actual = expected.selectable( "destroy" ); actual = expected.selectable( "destroy" );
equal( actual, expected, "destroy is chainable" ); assert.equal( actual, expected, "destroy is chainable" );
} ); } );
test( "enable", function() { QUnit.test( "enable", function( assert ) {
expect( 3 ); assert.expect( 3 );
var expected, actual, var expected, actual,
fired = false, fired = false,
el = $( "#selectable1" ); el = $( "#selectable1" );
@ -57,22 +58,22 @@ test( "enable", function() {
dx: 20, dx: 20,
dy: 20 dy: 20
} ); } );
equal( fired, false, "start fired" ); assert.equal( fired, false, "start fired" );
el.selectable( "enable" ); el.selectable( "enable" );
el.simulate( "drag", { el.simulate( "drag", {
dx: 20, dx: 20,
dy: 20 dy: 20
} ); } );
equal( fired, true, "start fired" ); assert.equal( fired, true, "start fired" );
el.selectable( "destroy" ); el.selectable( "destroy" );
expected = $( "<div></div>" ).selectable(); expected = $( "<div></div>" ).selectable();
actual = expected.selectable( "enable" ); actual = expected.selectable( "enable" );
equal( actual, expected, "enable is chainable" ); assert.equal( actual, expected, "enable is chainable" );
} ); } );
test( "disable", function( assert ) { QUnit.test( "disable", function( assert ) {
expect( 6 ); assert.expect( 6 );
var chainable, var chainable,
fired = false, fired = false,
element = $( "#selectable1" ); element = $( "#selectable1" );
@ -87,7 +88,7 @@ test( "disable", function( assert ) {
dx: 20, dx: 20,
dy: 20 dy: 20
} ); } );
equal( fired, true, "start fired" ); assert.equal( fired, true, "start fired" );
chainable = element.selectable( "disable" ); chainable = element.selectable( "disable" );
fired = false; fired = false;
@ -96,16 +97,16 @@ test( "disable", function( assert ) {
dx: 20, dx: 20,
dy: 20 dy: 20
} ); } );
equal( fired, false, "start fired" ); assert.equal( fired, false, "start fired" );
assert.lacksClasses( element.selectable( "widget" ), "ui-state-disabled" ); assert.lacksClasses( element.selectable( "widget" ), "ui-state-disabled" );
ok( !element.selectable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" ); assert.ok( !element.selectable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" );
assert.hasClasses( element.selectable( "widget" ), "ui-selectable-disabled" ); assert.hasClasses( element.selectable( "widget" ), "ui-selectable-disabled" );
element.selectable( "destroy" ); element.selectable( "destroy" );
equal( chainable, element, "disable is chainable" ); assert.equal( chainable, element, "disable is chainable" );
} ); } );
} ); } );

View File

@ -1,12 +1,13 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/selectable" "ui/widgets/selectable"
], function( $ ) { ], function( QUnit, $ ) {
module( "selectable: options" ); QUnit.module( "selectable: options" );
test( "autoRefresh", function() { QUnit.test( "autoRefresh", function( assert ) {
expect( 3 ); assert.expect( 3 );
var actual = 0, var actual = 0,
el = $( "#selectable1" ), el = $( "#selectable1" ),
@ -19,7 +20,7 @@ test( "autoRefresh", function() {
dx: 1000, dx: 1000,
dy: 1000 dy: 1000
} ); } );
equal( actual, sel.length ); assert.equal( actual, sel.length );
el.selectable( "destroy" ); el.selectable( "destroy" );
actual = 0; actual = 0;
@ -30,21 +31,21 @@ test( "autoRefresh", function() {
dx: 1000, dx: 1000,
dy: 1000 dy: 1000
} ); } );
equal( actual, 0 ); assert.equal( actual, 0 );
sel.show(); sel.show();
$( sel[ 0 ] ).simulate( "drag", { $( sel[ 0 ] ).simulate( "drag", {
dx: 1000, dx: 1000,
dy: 1000 dy: 1000
} ); } );
equal( actual, sel.length ); assert.equal( actual, sel.length );
el.selectable( "destroy" ); el.selectable( "destroy" );
sel.show(); sel.show();
} ); } );
test( "filter", function() { QUnit.test( "filter", function( assert ) {
expect( 2 ); assert.expect( 2 );
var actual = 0, var actual = 0,
el = $( "#selectable1" ), el = $( "#selectable1" ),
@ -56,8 +57,8 @@ test( "filter", function() {
dx: 1000, dx: 1000,
dy: 1000 dy: 1000
} ); } );
ok( sel.length !== 1, "this test assumes more than 1 selectee" ); assert.ok( sel.length !== 1, "this test assumes more than 1 selectee" );
equal( actual, 1 ); assert.equal( actual, 1 );
el.selectable( "destroy" ); el.selectable( "destroy" );
} ); } );