2011-08-07 12:10:49 +00:00
|
|
|
(function( $ ) {
|
|
|
|
|
2012-04-19 17:12:23 +00:00
|
|
|
var simulateKeyDownUp = TestHelpers.spinner.simulateKeyDownUp;
|
|
|
|
|
2011-08-07 12:10:49 +00:00
|
|
|
module( "spinner: methods" );
|
|
|
|
|
2011-08-07 17:05:04 +00:00
|
|
|
test( "destroy", function() {
|
|
|
|
expect( 1 );
|
|
|
|
domEqual( "#spin", function() {
|
|
|
|
$( "#spin" ).spinner().spinner( "destroy" );
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2011-08-07 12:10:49 +00:00
|
|
|
test( "disable", function() {
|
2013-03-14 23:08:21 +00:00
|
|
|
expect( 16 );
|
2011-08-13 23:05:04 +00:00
|
|
|
var element = $( "#spin" ).val( 2 ).spinner(),
|
2011-08-07 12:10:49 +00:00
|
|
|
wrapper = $( "#spin" ).spinner( "widget" );
|
|
|
|
|
|
|
|
ok( !wrapper.hasClass( "ui-spinner-disabled" ), "before: wrapper does not have ui-spinner-disabled class" );
|
|
|
|
ok( !element.is( ":disabled" ), "before: input does not have disabled attribute" );
|
|
|
|
|
|
|
|
element.spinner( "disable" );
|
|
|
|
ok( wrapper.hasClass( "ui-spinner-disabled" ), "after: wrapper has ui-spinner-disabled class" );
|
2013-03-14 23:08:21 +00:00
|
|
|
ok( wrapper.hasClass( "ui-state-disabled" ), "after: wrapper has ui-state-disabled class" );
|
|
|
|
ok( !wrapper.attr( "aria-disabled" ), "after: wrapper does not have aria-disabled attr" );
|
2011-08-07 12:10:49 +00:00
|
|
|
ok( element.is( ":disabled"), "after: input has disabled attribute" );
|
|
|
|
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( 2, element.val(), "keyboard - value does not change on key UP" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( 2, element.val(), "keyboard - value does not change on key DOWN" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( 2, element.val(), "keyboard - value does not change on key PGUP" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( 2, element.val(), "keyboard - value does not change on key PGDN" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
wrapper.find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( 2, element.val(), "mouse - value does not change on clicking up button" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
wrapper.find( ".ui-spinner-down" ).trigger( "mousedown" ).trigger( "mouseup" );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( 2, element.val(), "mouse - value does not change on clicking down button" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "stepUp", 6 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( 8, element.val(), "script - stepUp 6 steps changes value");
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "stepDown" );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( 7, element.val(), "script - stepDown 1 step changes value" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "pageUp" );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( 17, element.val(), "script - pageUp 1 page changes value" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "pageDown" );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( 7, element.val(), "script - pageDown 1 page changes value" );
|
2011-08-07 12:10:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "enable", function() {
|
|
|
|
expect( 5 );
|
2012-04-19 02:36:15 +00:00
|
|
|
var element = $( "#spin" ).val( 1 ).spinner({ disabled: true }),
|
2011-08-07 12:10:49 +00:00
|
|
|
wrapper = element.spinner( "widget" );
|
|
|
|
|
|
|
|
ok( wrapper.hasClass( "ui-spinner-disabled" ), "before: wrapper has ui-spinner-disabled class" );
|
|
|
|
ok( element.is( ":disabled" ), "before: input has disabled attribute" );
|
|
|
|
|
|
|
|
element.spinner( "enable" );
|
|
|
|
|
|
|
|
ok( !wrapper.hasClass( ".ui-spinner-disabled" ), "after: wrapper does not have ui-spinner-disabled class" );
|
|
|
|
ok( !element.is( ":disabled" ), "after: input does not have disabled attribute" );
|
|
|
|
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( 2, element.val(), "keyboard - value changes on key UP" );
|
2011-08-07 12:10:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "pageDown", function() {
|
|
|
|
expect( 4 );
|
2011-08-13 23:05:04 +00:00
|
|
|
var element = $( "#spin" ).val( -12 ).spinner({
|
2011-08-07 12:10:49 +00:00
|
|
|
page: 20,
|
|
|
|
min: -100
|
|
|
|
});
|
|
|
|
|
|
|
|
element.spinner( "pageDown" );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.val(), -32, "pageDown 1 page" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "pageDown", 3 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.val(), -92, "pageDown 3 pages" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "pageDown" );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.val(), -100, "value close to min and pageDown 1 page" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "pageDown", 10 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.val(), -100, "value at min and pageDown 10 pages" );
|
2011-08-07 12:10:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "pageUp", function() {
|
|
|
|
expect( 4 );
|
2011-08-13 23:05:04 +00:00
|
|
|
var element = $( "#spin" ).val( 12 ).spinner({
|
2011-08-07 12:10:49 +00:00
|
|
|
page: 20,
|
|
|
|
max: 100
|
|
|
|
});
|
|
|
|
|
|
|
|
element.spinner( "pageUp" );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.val(), 32, "pageUp 1 page" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "pageUp", 3 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.val(), 92, "pageUp 3 pages" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "pageUp" );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.val(), 100, "value close to max and pageUp 1 page" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "pageUp", 10 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.val(), 100, "value at max and pageUp 10 pages" );
|
2011-08-07 12:10:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "stepDown", function() {
|
|
|
|
expect( 4 );
|
2011-08-13 23:05:04 +00:00
|
|
|
var element = $( "#spin" ).val( 0 ).spinner({
|
2011-08-07 12:10:49 +00:00
|
|
|
step: 2,
|
|
|
|
min: -15
|
|
|
|
});
|
|
|
|
|
|
|
|
element.spinner( "stepDown" );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.val(), "-1", "stepDown 1 step" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "stepDown", 5 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.val(), "-11", "stepDown 5 steps" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "stepDown", 4 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.val(), "-15", "close to min and stepDown 4 steps" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "stepDown" );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.val(), "-15", "at min and stepDown 1 step" );
|
2011-08-07 12:10:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "stepUp", function() {
|
|
|
|
expect( 4 );
|
2011-08-13 23:05:04 +00:00
|
|
|
var element = $( "#spin" ).val( 0 ).spinner({
|
2011-08-07 12:10:49 +00:00
|
|
|
step: 2,
|
2011-09-14 12:54:29 +00:00
|
|
|
max: 16
|
2011-08-07 12:10:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
element.spinner( "stepUp" );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.val(), 2, "stepUp 1 step" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "stepUp", 5 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.val(), 12, "stepUp 5 steps" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "stepUp", 4 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.val(), 16, "close to min and stepUp 4 steps" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "stepUp" );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.val(), 16, "at max and stepUp 1 step" );
|
2011-08-07 12:10:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "value", function() {
|
|
|
|
expect( 2 );
|
2011-09-14 12:54:29 +00:00
|
|
|
var element = $( "#spin" ).val( 0 ).spinner({
|
|
|
|
step: 3
|
|
|
|
});
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "value", 10 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.val(), 9, "change value via value method" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.spinner( "value" ), 9, "get value via value method" );
|
2011-08-07 12:10:49 +00:00
|
|
|
});
|
|
|
|
|
2012-08-27 00:19:35 +00:00
|
|
|
test( "widget", function() {
|
|
|
|
expect( 2 );
|
|
|
|
var element = $( "#spin" ).spinner(),
|
|
|
|
widgetElement = element.spinner( "widget" );
|
|
|
|
equal( widgetElement.length, 1, "one element" );
|
|
|
|
strictEqual( widgetElement[ 0 ], element.parent()[ 0 ], "parent element" );
|
|
|
|
});
|
|
|
|
|
2011-08-07 12:10:49 +00:00
|
|
|
})( jQuery );
|