2015-04-06 23:46:15 +00:00
|
|
|
define( [
|
2016-04-06 13:26:05 +00:00
|
|
|
"qunit",
|
2015-04-06 23:46:15 +00:00
|
|
|
"jquery",
|
2015-04-07 14:55:52 +00:00
|
|
|
"./helper",
|
2015-07-15 02:10:12 +00:00
|
|
|
"ui/widgets/spinner"
|
2016-04-06 13:26:05 +00:00
|
|
|
], function( QUnit, $, testHelper ) {
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
var simulateKeyDownUp = testHelper.simulateKeyDownUp;
|
2012-04-19 17:12:23 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.module( "spinner: events" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "start", function( assert ) {
|
|
|
|
assert.expect( 10 );
|
2011-08-07 23:11:49 +00:00
|
|
|
var element = $( "#spin" ).spinner();
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2011-08-07 23:11:49 +00:00
|
|
|
function shouldStart( expectation, msg ) {
|
|
|
|
element.spinner( "option", "start", function() {
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.ok( expectation, msg );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-08-07 23:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
shouldStart( true, "key UP" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldStart( true, "key DOWN" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
2011-08-07 23:11:49 +00:00
|
|
|
|
|
|
|
shouldStart( true, "key PAGE_UP" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldStart( true, "key PAGE_DOWN" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
|
2011-08-07 23:11:49 +00:00
|
|
|
|
|
|
|
shouldStart( true, "button up" );
|
2015-05-14 02:01:44 +00:00
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldStart( true, "button down" );
|
2015-05-14 02:01:44 +00:00
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-down" ).trigger( "mousedown" ).trigger( "mouseup" );
|
2011-08-07 23:11:49 +00:00
|
|
|
|
2012-12-27 16:05:25 +00:00
|
|
|
shouldStart( true, "stepUp" );
|
2011-08-07 23:11:49 +00:00
|
|
|
element.spinner( "stepUp" );
|
2012-12-27 16:05:25 +00:00
|
|
|
shouldStart( true, "stepDown" );
|
2011-08-07 23:11:49 +00:00
|
|
|
element.spinner( "stepDown" );
|
|
|
|
|
2012-12-27 16:05:25 +00:00
|
|
|
shouldStart( true, "pageUp" );
|
2011-08-07 23:11:49 +00:00
|
|
|
element.spinner( "pageUp" );
|
2012-12-27 16:05:25 +00:00
|
|
|
shouldStart( true, "pageDown" );
|
2011-08-07 23:11:49 +00:00
|
|
|
element.spinner( "pageDown" );
|
|
|
|
|
|
|
|
shouldStart( false, "value" );
|
|
|
|
element.spinner( "value", 999 );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "spin", function( assert ) {
|
|
|
|
assert.expect( 10 );
|
2011-08-07 23:11:49 +00:00
|
|
|
var element = $( "#spin" ).spinner();
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2011-08-07 23:11:49 +00:00
|
|
|
function shouldSpin( expectation, msg ) {
|
|
|
|
element.spinner( "option", "spin", function() {
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.ok( expectation, msg );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-08-07 23:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
shouldSpin( true, "key UP" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldSpin( true, "key DOWN" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
2011-08-07 23:11:49 +00:00
|
|
|
|
|
|
|
shouldSpin( true, "key PAGE_UP" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldSpin( true, "key PAGE_DOWN" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
|
2011-08-07 23:11:49 +00:00
|
|
|
|
|
|
|
shouldSpin( true, "button up" );
|
2015-05-14 02:01:44 +00:00
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldSpin( true, "button down" );
|
2015-05-14 02:01:44 +00:00
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-down" ).trigger( "mousedown" ).trigger( "mouseup" );
|
2011-08-07 23:11:49 +00:00
|
|
|
|
2012-12-27 16:05:25 +00:00
|
|
|
shouldSpin( true, "stepUp" );
|
2011-08-07 23:11:49 +00:00
|
|
|
element.spinner( "stepUp" );
|
2012-12-27 16:05:25 +00:00
|
|
|
shouldSpin( true, "stepDown" );
|
2011-08-07 23:11:49 +00:00
|
|
|
element.spinner( "stepDown" );
|
|
|
|
|
2012-12-27 16:05:25 +00:00
|
|
|
shouldSpin( true, "pageUp" );
|
2011-08-07 23:11:49 +00:00
|
|
|
element.spinner( "pageUp" );
|
2012-12-27 16:05:25 +00:00
|
|
|
shouldSpin( true, "pageDown" );
|
2011-08-07 23:11:49 +00:00
|
|
|
element.spinner( "pageDown" );
|
|
|
|
|
|
|
|
shouldSpin( false, "value" );
|
|
|
|
element.spinner( "value", 999 );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "stop", function( assert ) {
|
|
|
|
assert.expect( 10 );
|
2011-08-07 23:11:49 +00:00
|
|
|
var element = $( "#spin" ).spinner();
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2011-08-07 23:11:49 +00:00
|
|
|
function shouldStop( expectation, msg ) {
|
|
|
|
element.spinner( "option", "stop", function() {
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.ok( expectation, msg );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-08-07 23:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
shouldStop( true, "key UP" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldStop( true, "key DOWN" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
2011-08-07 23:11:49 +00:00
|
|
|
|
|
|
|
shouldStop( true, "key PAGE_UP" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldStop( true, "key PAGE_DOWN" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
|
2011-08-07 23:11:49 +00:00
|
|
|
|
|
|
|
shouldStop( true, "button up" );
|
2015-05-14 02:01:44 +00:00
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldStop( true, "button down" );
|
2015-05-14 02:01:44 +00:00
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-down" ).trigger( "mousedown" ).trigger( "mouseup" );
|
2011-08-07 23:11:49 +00:00
|
|
|
|
2012-12-27 16:05:25 +00:00
|
|
|
shouldStop( true, "stepUp" );
|
2011-08-07 23:11:49 +00:00
|
|
|
element.spinner( "stepUp" );
|
2012-12-27 16:05:25 +00:00
|
|
|
shouldStop( true, "stepDown" );
|
2011-08-07 23:11:49 +00:00
|
|
|
element.spinner( "stepDown" );
|
|
|
|
|
2012-12-27 16:05:25 +00:00
|
|
|
shouldStop( true, "pageUp" );
|
2011-08-07 23:11:49 +00:00
|
|
|
element.spinner( "pageUp" );
|
2012-12-27 16:05:25 +00:00
|
|
|
shouldStop( true, "pageDown" );
|
2011-08-07 23:11:49 +00:00
|
|
|
element.spinner( "pageDown" );
|
|
|
|
|
|
|
|
shouldStop( false, "value" );
|
|
|
|
element.spinner( "value", 999 );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "change", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 12 );
|
2011-08-07 23:11:49 +00:00
|
|
|
var element = $( "#spin" ).spinner();
|
|
|
|
|
|
|
|
function shouldChange( expectation, msg ) {
|
|
|
|
element.spinner( "option", "change", function() {
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.ok( expectation, msg );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-08-07 23:11:49 +00:00
|
|
|
}
|
|
|
|
|
2012-12-10 15:35:28 +00:00
|
|
|
function focusWrap( fn, next ) {
|
2015-08-24 12:57:40 +00:00
|
|
|
element[ 0 ].focus();
|
2012-12-10 15:35:28 +00:00
|
|
|
setTimeout( function() {
|
|
|
|
fn();
|
2015-08-24 12:57:40 +00:00
|
|
|
setTimeout( function() {
|
|
|
|
element[ 0 ].blur();
|
2012-12-10 15:35:28 +00:00
|
|
|
setTimeout( next );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
|
|
|
} );
|
2012-12-10 15:35:28 +00:00
|
|
|
}
|
2011-08-07 23:11:49 +00:00
|
|
|
|
2012-12-10 15:35:28 +00:00
|
|
|
function step1() {
|
2015-08-24 12:57:40 +00:00
|
|
|
focusWrap( function() {
|
2012-12-10 15:35:28 +00:00
|
|
|
shouldChange( false, "key UP, before blur" );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
|
|
|
shouldChange( true, "blur after key UP" );
|
|
|
|
}, step2 );
|
|
|
|
}
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2012-12-10 15:35:28 +00:00
|
|
|
function step2() {
|
2015-08-24 12:57:40 +00:00
|
|
|
focusWrap( function() {
|
2012-12-10 15:35:28 +00:00
|
|
|
shouldChange( false, "key DOWN, before blur" );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
|
|
|
shouldChange( true, "blur after key DOWN" );
|
|
|
|
}, step3 );
|
|
|
|
}
|
2011-08-07 23:11:49 +00:00
|
|
|
|
2012-12-10 15:35:28 +00:00
|
|
|
function step3() {
|
2015-08-24 12:57:40 +00:00
|
|
|
focusWrap( function() {
|
2012-12-10 15:35:28 +00:00
|
|
|
shouldChange( false, "key PAGE_UP, before blur" );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
|
|
|
|
shouldChange( true, "blur after key PAGE_UP" );
|
|
|
|
}, step4 );
|
|
|
|
}
|
2011-08-07 23:11:49 +00:00
|
|
|
|
2012-12-10 15:35:28 +00:00
|
|
|
function step4() {
|
2015-08-24 12:57:40 +00:00
|
|
|
focusWrap( function() {
|
2012-12-10 15:35:28 +00:00
|
|
|
shouldChange( false, "key PAGE_DOWN, before blur" );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
|
|
|
|
shouldChange( true, "blur after key PAGE_DOWN" );
|
|
|
|
}, step5 );
|
|
|
|
}
|
2011-08-07 23:11:49 +00:00
|
|
|
|
2012-12-10 15:35:28 +00:00
|
|
|
function step5() {
|
2015-08-24 12:57:40 +00:00
|
|
|
focusWrap( function() {
|
2012-12-10 15:35:28 +00:00
|
|
|
shouldChange( false, "many keys, before blur" );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
|
|
|
shouldChange( true, "blur after many keys" );
|
|
|
|
}, step6 );
|
|
|
|
}
|
2011-08-07 23:11:49 +00:00
|
|
|
|
2012-12-10 15:35:28 +00:00
|
|
|
function step6() {
|
2015-08-24 12:57:40 +00:00
|
|
|
focusWrap( function() {
|
2012-12-10 15:35:28 +00:00
|
|
|
shouldChange( false, "many keys, same final value, before blur" );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
|
|
|
shouldChange( false, "blur after many keys, same final value" );
|
2012-05-10 21:59:55 +00:00
|
|
|
|
2012-12-10 15:35:28 +00:00
|
|
|
shouldChange( false, "button up, before blur" );
|
2015-05-14 02:01:44 +00:00
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" );
|
2012-12-10 15:35:28 +00:00
|
|
|
shouldChange( true, "blur after button up" );
|
|
|
|
}, step7 );
|
|
|
|
}
|
2012-05-10 21:59:55 +00:00
|
|
|
|
2012-12-10 15:35:28 +00:00
|
|
|
function step7() {
|
2015-08-24 12:57:40 +00:00
|
|
|
focusWrap( function() {
|
2012-12-10 15:35:28 +00:00
|
|
|
shouldChange( false, "button down, before blur" );
|
2015-05-14 02:01:44 +00:00
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-down" ).trigger( "mousedown" ).trigger( "mouseup" );
|
2012-12-10 15:35:28 +00:00
|
|
|
shouldChange( true, "blur after button down" );
|
|
|
|
}, step8 );
|
|
|
|
}
|
|
|
|
|
|
|
|
function step8() {
|
2015-08-24 12:57:40 +00:00
|
|
|
focusWrap( function() {
|
2012-05-10 21:59:55 +00:00
|
|
|
shouldChange( false, "many buttons, same final value, before blur" );
|
2015-05-14 02:01:44 +00:00
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" );
|
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" );
|
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-down" ).trigger( "mousedown" ).trigger( "mouseup" );
|
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-down" ).trigger( "mousedown" ).trigger( "mouseup" );
|
2012-05-10 21:59:55 +00:00
|
|
|
shouldChange( false, "blur after many buttons, same final value" );
|
2012-12-10 15:35:28 +00:00
|
|
|
}, step9 );
|
|
|
|
}
|
2012-05-10 21:59:55 +00:00
|
|
|
|
2012-12-10 15:35:28 +00:00
|
|
|
function step9() {
|
|
|
|
shouldChange( true, "stepUp" );
|
|
|
|
element.spinner( "stepUp" );
|
2012-05-10 21:59:55 +00:00
|
|
|
|
2012-12-10 15:35:28 +00:00
|
|
|
shouldChange( true, "stepDown" );
|
|
|
|
element.spinner( "stepDown" );
|
2012-05-10 21:59:55 +00:00
|
|
|
|
2012-12-10 15:35:28 +00:00
|
|
|
shouldChange( true, "pageUp" );
|
|
|
|
element.spinner( "pageUp" );
|
2012-05-10 21:59:55 +00:00
|
|
|
|
2012-12-10 15:35:28 +00:00
|
|
|
shouldChange( true, "pageDown" );
|
|
|
|
element.spinner( "pageDown" );
|
2012-05-10 21:59:55 +00:00
|
|
|
|
2012-12-10 15:35:28 +00:00
|
|
|
shouldChange( true, "value" );
|
|
|
|
element.spinner( "value", 999 );
|
2012-05-10 21:59:55 +00:00
|
|
|
|
2012-12-10 15:35:28 +00:00
|
|
|
shouldChange( false, "value, same value" );
|
|
|
|
element.spinner( "value", 999 );
|
2012-05-10 21:59:55 +00:00
|
|
|
|
2014-05-20 00:29:45 +00:00
|
|
|
shouldChange( false, "max, value not changed" );
|
2012-12-10 15:35:28 +00:00
|
|
|
element.spinner( "option", "max", 900 );
|
2012-05-10 21:59:55 +00:00
|
|
|
|
2012-12-10 15:35:28 +00:00
|
|
|
shouldChange( false, "max, value not changed" );
|
|
|
|
element.spinner( "option", "max", 1000 );
|
2012-05-10 21:59:55 +00:00
|
|
|
|
2014-05-20 00:29:45 +00:00
|
|
|
shouldChange( false, "min, value not changed" );
|
2012-12-10 15:35:28 +00:00
|
|
|
element.spinner( "option", "min", 950 );
|
|
|
|
|
|
|
|
shouldChange( false, "min, value not changed" );
|
|
|
|
element.spinner( "option", "min", 200 );
|
2016-04-06 13:26:05 +00:00
|
|
|
ready();
|
2012-12-10 15:35:28 +00:00
|
|
|
}
|
|
|
|
|
2012-12-10 20:54:06 +00:00
|
|
|
setTimeout( step1 );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2015-04-06 23:46:15 +00:00
|
|
|
} );
|