Spinner: Shift to use no globals

This commit is contained in:
Amanpreet Singh 2016-04-06 18:56:05 +05:30
parent 749f95ee0a
commit b5028f02bf
5 changed files with 257 additions and 250 deletions

View File

@ -1,15 +1,16 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"./helper", "./helper",
"ui/widgets/spinner" "ui/widgets/spinner"
], function( $, testHelper ) { ], function( QUnit, $, testHelper ) {
var simulateKeyDownUp = testHelper.simulateKeyDownUp; var simulateKeyDownUp = testHelper.simulateKeyDownUp;
module( "spinner: core" ); QUnit.module( "spinner: core" );
test( "markup structure", function( assert ) { QUnit.test( "markup structure", function( assert ) {
expect( 6 ); assert.expect( 6 );
var element = $( "#spin" ).spinner(), var element = $( "#spin" ).spinner(),
spinner = element.spinner( "widget" ), spinner = element.spinner( "widget" ),
up = spinner.find( ".ui-spinner-up" ), up = spinner.find( ".ui-spinner-up" ),
@ -18,101 +19,102 @@ test( "markup structure", function( assert ) {
assert.hasClasses( element, "ui-spinner-input" ); assert.hasClasses( element, "ui-spinner-input" );
assert.hasClasses( spinner, "ui-spinner ui-widget ui-widget-content" ); assert.hasClasses( spinner, "ui-spinner ui-widget ui-widget-content" );
assert.hasClasses( up, "ui-spinner-button ui-spinner-up ui-widget" ); assert.hasClasses( up, "ui-spinner-button ui-spinner-up ui-widget" );
equal( up.length, 1, "Spinner contains exactly one up button" ); assert.equal( up.length, 1, "Spinner contains exactly one up button" );
assert.hasClasses( down, "ui-spinner-button ui-spinner-down ui-widget" ); assert.hasClasses( down, "ui-spinner-button ui-spinner-down ui-widget" );
equal( down.length, 1, "Spinner contains exactly one down button" ); assert.equal( down.length, 1, "Spinner contains exactly one down button" );
} ); } );
test( "keydown UP on input, increases value not greater than max", function() { QUnit.test( "keydown UP on input, increases value not greater than max", function( assert ) {
expect( 5 ); assert.expect( 5 );
var element = $( "#spin" ).val( 70 ).spinner( { var element = $( "#spin" ).val( 70 ).spinner( {
max: 100, max: 100,
step: 10 step: 10
} ); } );
simulateKeyDownUp( element, $.ui.keyCode.UP ); simulateKeyDownUp( element, $.ui.keyCode.UP );
equal( element.val(), 80 ); assert.equal( element.val(), 80 );
simulateKeyDownUp( element, $.ui.keyCode.UP ); simulateKeyDownUp( element, $.ui.keyCode.UP );
equal( element.val(), 90 ); assert.equal( element.val(), 90 );
simulateKeyDownUp( element, $.ui.keyCode.UP ); simulateKeyDownUp( element, $.ui.keyCode.UP );
equal( element.val(), 100 ); assert.equal( element.val(), 100 );
simulateKeyDownUp( element, $.ui.keyCode.UP ); simulateKeyDownUp( element, $.ui.keyCode.UP );
equal( element.val(), 100 ); assert.equal( element.val(), 100 );
simulateKeyDownUp( element, $.ui.keyCode.UP ); simulateKeyDownUp( element, $.ui.keyCode.UP );
equal( element.val(), 100 ); assert.equal( element.val(), 100 );
} ); } );
test( "keydown DOWN on input, decreases value not less than min", function() { QUnit.test( "keydown DOWN on input, decreases value not less than min", function( assert ) {
expect( 5 ); assert.expect( 5 );
var element = $( "#spin" ).val( 50 ).spinner( { var element = $( "#spin" ).val( 50 ).spinner( {
min: 20, min: 20,
step: 10 step: 10
} ); } );
simulateKeyDownUp( element, $.ui.keyCode.DOWN ); simulateKeyDownUp( element, $.ui.keyCode.DOWN );
equal( element.val(), 40 ); assert.equal( element.val(), 40 );
simulateKeyDownUp( element, $.ui.keyCode.DOWN ); simulateKeyDownUp( element, $.ui.keyCode.DOWN );
equal( element.val(), 30 ); assert.equal( element.val(), 30 );
simulateKeyDownUp( element, $.ui.keyCode.DOWN ); simulateKeyDownUp( element, $.ui.keyCode.DOWN );
equal( element.val(), 20 ); assert.equal( element.val(), 20 );
simulateKeyDownUp( element, $.ui.keyCode.DOWN ); simulateKeyDownUp( element, $.ui.keyCode.DOWN );
equal( element.val(), 20 ); assert.equal( element.val(), 20 );
simulateKeyDownUp( element, $.ui.keyCode.DOWN ); simulateKeyDownUp( element, $.ui.keyCode.DOWN );
equal( element.val(), 20 ); assert.equal( element.val(), 20 );
} ); } );
test( "keydown PAGE_UP on input, increases value not greater than max", function() { QUnit.test( "keydown PAGE_UP on input, increases value not greater than max", function( assert ) {
expect( 5 ); assert.expect( 5 );
var element = $( "#spin" ).val( 70 ).spinner( { var element = $( "#spin" ).val( 70 ).spinner( {
max: 100, max: 100,
page: 10 page: 10
} ); } );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
equal( element.val(), 80 ); assert.equal( element.val(), 80 );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
equal( element.val(), 90 ); assert.equal( element.val(), 90 );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
equal( element.val(), 100 ); assert.equal( element.val(), 100 );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
equal( element.val(), 100 ); assert.equal( element.val(), 100 );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
equal( element.val(), 100 ); assert.equal( element.val(), 100 );
} ); } );
test( "keydown PAGE_DOWN on input, decreases value not less than min", function() { QUnit.test( "keydown PAGE_DOWN on input, decreases value not less than min", function( assert ) {
expect( 5 ); assert.expect( 5 );
var element = $( "#spin" ).val( 50 ).spinner( { var element = $( "#spin" ).val( 50 ).spinner( {
min: 20, min: 20,
page: 10 page: 10
} ); } );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
equal( element.val(), 40 ); assert.equal( element.val(), 40 );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
equal( element.val(), 30 ); assert.equal( element.val(), 30 );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
equal( element.val(), 20 ); assert.equal( element.val(), 20 );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
equal( element.val(), 20 ); assert.equal( element.val(), 20 );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
equal( element.val(), 20 ); assert.equal( element.val(), 20 );
} ); } );
asyncTest( "blur input while spinning with UP", function() { QUnit.test( "blur input while spinning with UP", function( assert ) {
expect( 3 ); var ready = assert.async();
assert.expect( 3 );
var value, var value,
element = $( "#spin" ).val( 10 ).spinner(); element = $( "#spin" ).val( 10 ).spinner();
function step1() { function step1() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equal( element.val(), 11 ); assert.equal( element.val(), 11 );
setTimeout( step2, 750 ); setTimeout( step2, 750 );
} }
function step2() { function step2() {
value = element.val(); value = element.val();
ok( value > 11, "repeating while key is down" ); assert.ok( value > 11, "repeating while key is down" );
element.on( "blur", function() { element.on( "blur", function() {
value = element.val(); value = element.val();
@ -121,137 +123,137 @@ asyncTest( "blur input while spinning with UP", function() {
} }
function step3() { function step3() {
equal( element.val(), value, "stopped repeating on blur" ); assert.equal( element.val(), value, "stopped repeating on blur" );
start(); ready();
} }
element[ 0 ].focus(); element[ 0 ].focus();
setTimeout( step1 ); setTimeout( step1 );
} ); } );
test( "mouse click on up button, increases value not greater than max", function() { QUnit.test( "mouse click on up button, increases value not greater than max", function( assert ) {
expect( 3 ); assert.expect( 3 );
var element = $( "#spin" ).val( 18 ).spinner( { var element = $( "#spin" ).val( 18 ).spinner( {
max: 20 max: 20
} ), } ),
button = element.spinner( "widget" ).find( ".ui-spinner-up" ); button = element.spinner( "widget" ).find( ".ui-spinner-up" );
button.trigger( "mousedown" ).trigger( "mouseup" ); button.trigger( "mousedown" ).trigger( "mouseup" );
equal( element.val(), 19 ); assert.equal( element.val(), 19 );
button.trigger( "mousedown" ).trigger( "mouseup" ); button.trigger( "mousedown" ).trigger( "mouseup" );
equal( element.val(), 20 ); assert.equal( element.val(), 20 );
button.trigger( "mousedown" ).trigger( "mouseup" ); button.trigger( "mousedown" ).trigger( "mouseup" );
equal( element.val(), 20 ); assert.equal( element.val(), 20 );
} ); } );
test( "mouse click on up button, increases value not greater than max", function() { QUnit.test( "mouse click on up button, increases value not greater than max", function( assert ) {
expect( 3 ); assert.expect( 3 );
var element = $( "#spin" ).val( 2 ).spinner( { var element = $( "#spin" ).val( 2 ).spinner( {
min: 0 min: 0
} ), } ),
button = element.spinner( "widget" ).find( ".ui-spinner-down" ); button = element.spinner( "widget" ).find( ".ui-spinner-down" );
button.trigger( "mousedown" ).trigger( "mouseup" ); button.trigger( "mousedown" ).trigger( "mouseup" );
equal( element.val(), 1 ); assert.equal( element.val(), 1 );
button.trigger( "mousedown" ).trigger( "mouseup" ); button.trigger( "mousedown" ).trigger( "mouseup" );
equal( element.val(), 0 ); assert.equal( element.val(), 0 );
button.trigger( "mousedown" ).trigger( "mouseup" ); button.trigger( "mousedown" ).trigger( "mouseup" );
equal( element.val(), 0 ); assert.equal( element.val(), 0 );
} ); } );
test( "mousewheel on input", function() { QUnit.test( "mousewheel on input", function( assert ) {
expect( 4 ); assert.expect( 4 );
var element = $( "#spin" ).val( 0 ).spinner( { var element = $( "#spin" ).val( 0 ).spinner( {
step: 2 step: 2
} ); } );
element.trigger( "mousewheel" ); element.trigger( "mousewheel" );
equal( element.val(), 0, "mousewheel event without delta does not change value" ); assert.equal( element.val(), 0, "mousewheel event without delta does not change value" );
element.trigger( "mousewheel", 1 ); element.trigger( "mousewheel", 1 );
equal( element.val(), 2 ); assert.equal( element.val(), 2 );
element.trigger( "mousewheel", -0.2 ); element.trigger( "mousewheel", -0.2 );
equal( element.val(), 0 ); assert.equal( element.val(), 0 );
element.trigger( "mousewheel", -15 ); element.trigger( "mousewheel", -15 );
equal( element.val(), -2 ); assert.equal( element.val(), -2 );
} ); } );
test( "reading HTML5 attributes", function() { QUnit.test( "reading HTML5 attributes", function( assert ) {
expect( 6 ); assert.expect( 6 );
var markup = "<input type='number' min='-100' max='100' value='5' step='2'>", var markup = "<input type='number' min='-100' max='100' value='5' step='2'>",
element = $( markup ).spinner(); element = $( markup ).spinner();
equal( element.spinner( "option", "min" ), -100, "min from markup" ); assert.equal( element.spinner( "option", "min" ), -100, "min from markup" );
equal( element.spinner( "option", "max" ), 100, "max from markup" ); assert.equal( element.spinner( "option", "max" ), 100, "max from markup" );
equal( element.spinner( "option", "step" ), 2, "step from markup" ); assert.equal( element.spinner( "option", "step" ), 2, "step from markup" );
element = $( markup ).spinner( { element = $( markup ).spinner( {
min: -200, min: -200,
max: 200, max: 200,
step: 5 step: 5
} ); } );
equal( element.spinner( "option", "min" ), -200, "min from options" ); assert.equal( element.spinner( "option", "min" ), -200, "min from options" );
equal( element.spinner( "option", "max" ), 200, "max from options" ); assert.equal( element.spinner( "option", "max" ), 200, "max from options" );
equal( element.spinner( "option", "step" ), 5, "stop from options" ); assert.equal( element.spinner( "option", "step" ), 5, "stop from options" );
} ); } );
test( "ARIA attributes", function() { QUnit.test( "ARIA attributes", function( assert ) {
expect( 9 ); assert.expect( 9 );
var element = $( "#spin" ).val( 2 ).spinner( { min: -5, max: 5 } ); var element = $( "#spin" ).val( 2 ).spinner( { min: -5, max: 5 } );
equal( element.attr( "role" ), "spinbutton", "role" ); assert.equal( element.attr( "role" ), "spinbutton", "role" );
equal( element.attr( "aria-valuemin" ), "-5", "aria-valuemin" ); assert.equal( element.attr( "aria-valuemin" ), "-5", "aria-valuemin" );
equal( element.attr( "aria-valuemax" ), "5", "aria-valuemax" ); assert.equal( element.attr( "aria-valuemax" ), "5", "aria-valuemax" );
equal( element.attr( "aria-valuenow" ), "2", "aria-valuenow" ); assert.equal( element.attr( "aria-valuenow" ), "2", "aria-valuenow" );
element.spinner( "stepUp" ); element.spinner( "stepUp" );
equal( element.attr( "aria-valuenow" ), "3", "stepUp 1 step changes aria-valuenow" ); assert.equal( element.attr( "aria-valuenow" ), "3", "stepUp 1 step changes aria-valuenow" );
element.spinner( "option", { min: -10, max: 10 } ); element.spinner( "option", { min: -10, max: 10 } );
equal( element.attr( "aria-valuemin" ), "-10", "min option changed aria-valuemin changes" ); assert.equal( element.attr( "aria-valuemin" ), "-10", "min option changed aria-valuemin changes" );
equal( element.attr( "aria-valuemax" ), "10", "max option changed aria-valuemax changes" ); assert.equal( element.attr( "aria-valuemax" ), "10", "max option changed aria-valuemax changes" );
element.spinner( "option", "min", null ); element.spinner( "option", "min", null );
equal( element.attr( "aria-valuemin" ), undefined, "aria-valuemin not set when no min" ); assert.equal( element.attr( "aria-valuemin" ), undefined, "aria-valuemin not set when no min" );
element.spinner( "option", "max", null ); element.spinner( "option", "max", null );
equal( element.attr( "aria-valuemax" ), undefined, "aria-valuemax not set when no max" ); assert.equal( element.attr( "aria-valuemax" ), undefined, "aria-valuemax not set when no max" );
} ); } );
test( "focus text field when pressing button", function() { QUnit.test( "focus text field when pressing button", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#spin" ).spinner(); var element = $( "#spin" ).spinner();
$( "body" ).trigger( "focus" ); $( "body" ).trigger( "focus" );
ok( element[ 0 ] !== document.activeElement, "not focused before" ); assert.ok( element[ 0 ] !== document.activeElement, "not focused before" );
element.spinner( "widget" ).find( ".ui-spinner-up" ).trigger( "mousedown" ); element.spinner( "widget" ).find( ".ui-spinner-up" ).trigger( "mousedown" );
ok( element[ 0 ] === document.activeElement, "focused after" ); assert.ok( element[ 0 ] === document.activeElement, "focused after" );
} ); } );
test( "don't clear invalid value on blur", function() { QUnit.test( "don't clear invalid value on blur", function( assert ) {
expect( 1 ); assert.expect( 1 );
var element = $( "#spin" ).spinner(); var element = $( "#spin" ).spinner();
element.trigger( "focus" ).val( "a" ).trigger( "blur" ); element.trigger( "focus" ).val( "a" ).trigger( "blur" );
equal( element.val(), "a" ); assert.equal( element.val(), "a" );
} ); } );
test( "precision", function() { QUnit.test( "precision", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#spin" ).val( 0.05 ).spinner( { var element = $( "#spin" ).val( 0.05 ).spinner( {
step: 0.0001 step: 0.0001
} ); } );
element.spinner( "stepUp" ); element.spinner( "stepUp" );
equal( element.val(), "0.0501", "precision from step" ); assert.equal( element.val(), "0.0501", "precision from step" );
element.val( 1.05 ).spinner( "option", { element.val( 1.05 ).spinner( "option", {
step: 1, step: 1,
min: -9.95 min: -9.95
} ); } );
element.spinner( "stepDown" ); element.spinner( "stepDown" );
equal( element.val(), "0.05", "precision from min" ); assert.equal( element.val(), "0.05", "precision from min" );
} ); } );
} ); } );

View File

@ -1,11 +1,12 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/spinner" "ui/widgets/spinner"
], function( $ ) { ], function( QUnit, $ ) {
var originalSpinner = $.ui.spinner.prototype; var originalSpinner = $.ui.spinner.prototype;
module( "spinner: deprecated", { QUnit.module( "spinner: deprecated", {
setup: function() { beforeEach: function() {
$.widget( "ui.spinner", $.ui.spinner, { $.widget( "ui.spinner", $.ui.spinner, {
_uiSpinnerHtml: function() { _uiSpinnerHtml: function() {
return "<span class='spin-wrap'>"; return "<span class='spin-wrap'>";
@ -23,13 +24,13 @@ module( "spinner: deprecated", {
} ); } );
}, },
teardown: function() { afterEach: function() {
$.ui.spinner.prototype = originalSpinner; $.ui.spinner.prototype = originalSpinner;
} }
} ); } );
test( "markup structure - custom", function( assert ) { QUnit.test( "markup structure - custom", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#spin" ).spinner(), var element = $( "#spin" ).spinner(),
spinner = element.spinner( "widget" ), spinner = element.spinner( "widget" ),
up = spinner.find( ".ui-spinner-up" ); up = spinner.find( ".ui-spinner-up" );

View File

@ -1,20 +1,21 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"./helper", "./helper",
"ui/widgets/spinner" "ui/widgets/spinner"
], function( $, testHelper ) { ], function( QUnit, $, testHelper ) {
var simulateKeyDownUp = testHelper.simulateKeyDownUp; var simulateKeyDownUp = testHelper.simulateKeyDownUp;
module( "spinner: events" ); QUnit.module( "spinner: events" );
test( "start", function() { QUnit.test( "start", function( assert ) {
expect( 10 ); assert.expect( 10 );
var element = $( "#spin" ).spinner(); var element = $( "#spin" ).spinner();
function shouldStart( expectation, msg ) { function shouldStart( expectation, msg ) {
element.spinner( "option", "start", function() { element.spinner( "option", "start", function() {
ok( expectation, msg ); assert.ok( expectation, msg );
} ); } );
} }
@ -47,13 +48,13 @@ test( "start", function() {
element.spinner( "value", 999 ); element.spinner( "value", 999 );
} ); } );
test( "spin", function() { QUnit.test( "spin", function( assert ) {
expect( 10 ); assert.expect( 10 );
var element = $( "#spin" ).spinner(); var element = $( "#spin" ).spinner();
function shouldSpin( expectation, msg ) { function shouldSpin( expectation, msg ) {
element.spinner( "option", "spin", function() { element.spinner( "option", "spin", function() {
ok( expectation, msg ); assert.ok( expectation, msg );
} ); } );
} }
@ -86,13 +87,13 @@ test( "spin", function() {
element.spinner( "value", 999 ); element.spinner( "value", 999 );
} ); } );
test( "stop", function() { QUnit.test( "stop", function( assert ) {
expect( 10 ); assert.expect( 10 );
var element = $( "#spin" ).spinner(); var element = $( "#spin" ).spinner();
function shouldStop( expectation, msg ) { function shouldStop( expectation, msg ) {
element.spinner( "option", "stop", function() { element.spinner( "option", "stop", function() {
ok( expectation, msg ); assert.ok( expectation, msg );
} ); } );
} }
@ -125,13 +126,14 @@ test( "stop", function() {
element.spinner( "value", 999 ); element.spinner( "value", 999 );
} ); } );
asyncTest( "change", function() { QUnit.test( "change", function( assert ) {
expect( 12 ); var ready = assert.async();
assert.expect( 12 );
var element = $( "#spin" ).spinner(); var element = $( "#spin" ).spinner();
function shouldChange( expectation, msg ) { function shouldChange( expectation, msg ) {
element.spinner( "option", "change", function() { element.spinner( "option", "change", function() {
ok( expectation, msg ); assert.ok( expectation, msg );
} ); } );
} }
@ -254,7 +256,7 @@ asyncTest( "change", function() {
shouldChange( false, "min, value not changed" ); shouldChange( false, "min, value not changed" );
element.spinner( "option", "min", 200 ); element.spinner( "option", "min", 200 );
start(); ready();
} }
setTimeout( step1 ); setTimeout( step1 );

View File

@ -1,211 +1,212 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"./helper", "./helper",
"ui/widgets/spinner" "ui/widgets/spinner"
], function( $, testHelper ) { ], function( QUnit, $, testHelper ) {
var simulateKeyDownUp = testHelper.simulateKeyDownUp; var simulateKeyDownUp = testHelper.simulateKeyDownUp;
module( "spinner: methods" ); QUnit.module( "spinner: methods" );
test( "destroy", function( assert ) { QUnit.test( "destroy", function( assert ) {
expect( 1 ); assert.expect( 1 );
assert.domEqual( "#spin", function() { assert.domEqual( "#spin", function() {
$( "#spin" ).spinner().spinner( "destroy" ); $( "#spin" ).spinner().spinner( "destroy" );
} ); } );
} ); } );
test( "disable", function( assert ) { QUnit.test( "disable", function( assert ) {
expect( 15 ); assert.expect( 15 );
var element = $( "#spin" ).val( 2 ).spinner(), var element = $( "#spin" ).val( 2 ).spinner(),
wrapper = $( "#spin" ).spinner( "widget" ); wrapper = $( "#spin" ).spinner( "widget" );
assert.lacksClasses( wrapper, "ui-spinner-disabled" ); assert.lacksClasses( wrapper, "ui-spinner-disabled" );
ok( !element.is( ":disabled" ), "before: input does not have disabled attribute" ); assert.ok( !element.is( ":disabled" ), "before: input does not have disabled attribute" );
element.spinner( "disable" ); element.spinner( "disable" );
assert.hasClasses( wrapper, "ui-state-disabled ui-spinner-disabled" ); assert.hasClasses( wrapper, "ui-state-disabled ui-spinner-disabled" );
ok( !wrapper.attr( "aria-disabled" ), "after: wrapper does not have aria-disabled attr" ); assert.ok( !wrapper.attr( "aria-disabled" ), "after: wrapper does not have aria-disabled attr" );
ok( element.is( ":disabled" ), "after: input has disabled attribute" ); assert.ok( element.is( ":disabled" ), "after: input has disabled attribute" );
simulateKeyDownUp( element, $.ui.keyCode.UP ); simulateKeyDownUp( element, $.ui.keyCode.UP );
equal( 2, element.val(), "keyboard - value does not change on key UP" ); assert.equal( 2, element.val(), "keyboard - value does not change on key UP" );
simulateKeyDownUp( element, $.ui.keyCode.DOWN ); simulateKeyDownUp( element, $.ui.keyCode.DOWN );
equal( 2, element.val(), "keyboard - value does not change on key DOWN" ); assert.equal( 2, element.val(), "keyboard - value does not change on key DOWN" );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
equal( 2, element.val(), "keyboard - value does not change on key PGUP" ); assert.equal( 2, element.val(), "keyboard - value does not change on key PGUP" );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
equal( 2, element.val(), "keyboard - value does not change on key PGDN" ); assert.equal( 2, element.val(), "keyboard - value does not change on key PGDN" );
wrapper.find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" ); wrapper.find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" );
equal( 2, element.val(), "mouse - value does not change on clicking up button" ); assert.equal( 2, element.val(), "mouse - value does not change on clicking up button" );
wrapper.find( ".ui-spinner-down" ).trigger( "mousedown" ).trigger( "mouseup" ); wrapper.find( ".ui-spinner-down" ).trigger( "mousedown" ).trigger( "mouseup" );
equal( 2, element.val(), "mouse - value does not change on clicking down button" ); assert.equal( 2, element.val(), "mouse - value does not change on clicking down button" );
element.spinner( "stepUp", 6 ); element.spinner( "stepUp", 6 );
equal( 8, element.val(), "script - stepUp 6 steps changes value" ); assert.equal( 8, element.val(), "script - stepUp 6 steps changes value" );
element.spinner( "stepDown" ); element.spinner( "stepDown" );
equal( 7, element.val(), "script - stepDown 1 step changes value" ); assert.equal( 7, element.val(), "script - stepDown 1 step changes value" );
element.spinner( "pageUp" ); element.spinner( "pageUp" );
equal( 17, element.val(), "script - pageUp 1 page changes value" ); assert.equal( 17, element.val(), "script - pageUp 1 page changes value" );
element.spinner( "pageDown" ); element.spinner( "pageDown" );
equal( 7, element.val(), "script - pageDown 1 page changes value" ); assert.equal( 7, element.val(), "script - pageDown 1 page changes value" );
} ); } );
test( "enable", function( assert ) { QUnit.test( "enable", function( assert ) {
expect( 5 ); assert.expect( 5 );
var element = $( "#spin" ).val( 1 ).spinner( { disabled: true } ), var element = $( "#spin" ).val( 1 ).spinner( { disabled: true } ),
wrapper = element.spinner( "widget" ); wrapper = element.spinner( "widget" );
assert.hasClasses( wrapper, "ui-spinner-disabled" ); assert.hasClasses( wrapper, "ui-spinner-disabled" );
ok( element.is( ":disabled" ), "before: input has disabled attribute" ); assert.ok( element.is( ":disabled" ), "before: input has disabled attribute" );
element.spinner( "enable" ); element.spinner( "enable" );
assert.lacksClasses( wrapper, "ui-spinner-disabled" ); assert.lacksClasses( wrapper, "ui-spinner-disabled" );
ok( !element.is( ":disabled" ), "after: input does not have disabled attribute" ); assert.ok( !element.is( ":disabled" ), "after: input does not have disabled attribute" );
simulateKeyDownUp( element, $.ui.keyCode.UP ); simulateKeyDownUp( element, $.ui.keyCode.UP );
equal( 2, element.val(), "keyboard - value changes on key UP" ); assert.equal( 2, element.val(), "keyboard - value changes on key UP" );
} ); } );
test( "isValid", function() { QUnit.test( "isValid", function( assert ) {
expect( 8 ); assert.expect( 8 );
var element = $( "#spin" ).spinner( { var element = $( "#spin" ).spinner( {
min: 0, min: 0,
max: 10, max: 10,
step: 2 step: 2
} ), } ),
spinner = element.spinner( "instance" ); spinner = element.spinner( "instance" );
ok( !spinner.isValid(), "initial state is invalid" ); assert.ok( !spinner.isValid(), "initial state is invalid" );
element.val( "this is not a number" ); element.val( "this is not a number" );
ok( !spinner.isValid(), "text string is not valid" ); assert.ok( !spinner.isValid(), "text string is not valid" );
element.val( "0" ); element.val( "0" );
ok( spinner.isValid(), "min value is valid" ); assert.ok( spinner.isValid(), "min value is valid" );
element.val( "10" ); element.val( "10" );
ok( spinner.isValid(), "max value is valid" ); assert.ok( spinner.isValid(), "max value is valid" );
element.val( "4" ); element.val( "4" );
ok( spinner.isValid(), "inbetween step is valid" ); assert.ok( spinner.isValid(), "inbetween step is valid" );
element.val( "-1" ); element.val( "-1" );
ok( !spinner.isValid(), "below min is invalid" ); assert.ok( !spinner.isValid(), "below min is invalid" );
element.val( "11" ); element.val( "11" );
ok( !spinner.isValid(), "above max is invalid" ); assert.ok( !spinner.isValid(), "above max is invalid" );
element.val( "1" ); element.val( "1" );
ok( !spinner.isValid(), "step mismatch is invalid" ); assert.ok( !spinner.isValid(), "step mismatch is invalid" );
} ); } );
test( "pageDown", function() { QUnit.test( "pageDown", function( assert ) {
expect( 4 ); assert.expect( 4 );
var element = $( "#spin" ).val( -12 ).spinner( { var element = $( "#spin" ).val( -12 ).spinner( {
page: 20, page: 20,
min: -100 min: -100
} ); } );
element.spinner( "pageDown" ); element.spinner( "pageDown" );
equal( element.val(), -32, "pageDown 1 page" ); assert.equal( element.val(), -32, "pageDown 1 page" );
element.spinner( "pageDown", 3 ); element.spinner( "pageDown", 3 );
equal( element.val(), -92, "pageDown 3 pages" ); assert.equal( element.val(), -92, "pageDown 3 pages" );
element.spinner( "pageDown" ); element.spinner( "pageDown" );
equal( element.val(), -100, "value close to min and pageDown 1 page" ); assert.equal( element.val(), -100, "value close to min and pageDown 1 page" );
element.spinner( "pageDown", 10 ); element.spinner( "pageDown", 10 );
equal( element.val(), -100, "value at min and pageDown 10 pages" ); assert.equal( element.val(), -100, "value at min and pageDown 10 pages" );
} ); } );
test( "pageUp", function() { QUnit.test( "pageUp", function( assert ) {
expect( 4 ); assert.expect( 4 );
var element = $( "#spin" ).val( 12 ).spinner( { var element = $( "#spin" ).val( 12 ).spinner( {
page: 20, page: 20,
max: 100 max: 100
} ); } );
element.spinner( "pageUp" ); element.spinner( "pageUp" );
equal( element.val(), 32, "pageUp 1 page" ); assert.equal( element.val(), 32, "pageUp 1 page" );
element.spinner( "pageUp", 3 ); element.spinner( "pageUp", 3 );
equal( element.val(), 92, "pageUp 3 pages" ); assert.equal( element.val(), 92, "pageUp 3 pages" );
element.spinner( "pageUp" ); element.spinner( "pageUp" );
equal( element.val(), 100, "value close to max and pageUp 1 page" ); assert.equal( element.val(), 100, "value close to max and pageUp 1 page" );
element.spinner( "pageUp", 10 ); element.spinner( "pageUp", 10 );
equal( element.val(), 100, "value at max and pageUp 10 pages" ); assert.equal( element.val(), 100, "value at max and pageUp 10 pages" );
} ); } );
test( "stepDown", function() { QUnit.test( "stepDown", function( assert ) {
expect( 4 ); assert.expect( 4 );
var element = $( "#spin" ).val( 0 ).spinner( { var element = $( "#spin" ).val( 0 ).spinner( {
step: 2, step: 2,
min: -15 min: -15
} ); } );
element.spinner( "stepDown" ); element.spinner( "stepDown" );
equal( element.val(), "-1", "stepDown 1 step" ); assert.equal( element.val(), "-1", "stepDown 1 step" );
element.spinner( "stepDown", 5 ); element.spinner( "stepDown", 5 );
equal( element.val(), "-11", "stepDown 5 steps" ); assert.equal( element.val(), "-11", "stepDown 5 steps" );
element.spinner( "stepDown", 4 ); element.spinner( "stepDown", 4 );
equal( element.val(), "-15", "close to min and stepDown 4 steps" ); assert.equal( element.val(), "-15", "close to min and stepDown 4 steps" );
element.spinner( "stepDown" ); element.spinner( "stepDown" );
equal( element.val(), "-15", "at min and stepDown 1 step" ); assert.equal( element.val(), "-15", "at min and stepDown 1 step" );
} ); } );
test( "stepUp", function() { QUnit.test( "stepUp", function( assert ) {
expect( 4 ); assert.expect( 4 );
var element = $( "#spin" ).val( 0 ).spinner( { var element = $( "#spin" ).val( 0 ).spinner( {
step: 2, step: 2,
max: 16 max: 16
} ); } );
element.spinner( "stepUp" ); element.spinner( "stepUp" );
equal( element.val(), 2, "stepUp 1 step" ); assert.equal( element.val(), 2, "stepUp 1 step" );
element.spinner( "stepUp", 5 ); element.spinner( "stepUp", 5 );
equal( element.val(), 12, "stepUp 5 steps" ); assert.equal( element.val(), 12, "stepUp 5 steps" );
element.spinner( "stepUp", 4 ); element.spinner( "stepUp", 4 );
equal( element.val(), 16, "close to max and stepUp 4 steps" ); assert.equal( element.val(), 16, "close to max and stepUp 4 steps" );
element.spinner( "stepUp" ); element.spinner( "stepUp" );
equal( element.val(), 16, "at max and stepUp 1 step" ); assert.equal( element.val(), 16, "at max and stepUp 1 step" );
} ); } );
test( "value", function() { QUnit.test( "value", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#spin" ).val( 0 ).spinner( { var element = $( "#spin" ).val( 0 ).spinner( {
step: 3 step: 3
} ); } );
element.spinner( "value", 10 ); element.spinner( "value", 10 );
equal( element.val(), 9, "change value via value method" ); assert.equal( element.val(), 9, "change value via value method" );
equal( element.spinner( "value" ), 9, "get value via value method" ); assert.equal( element.spinner( "value" ), 9, "get value via value method" );
} ); } );
test( "widget", function() { QUnit.test( "widget", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#spin" ).spinner(), var element = $( "#spin" ).spinner(),
widgetElement = element.spinner( "widget" ); widgetElement = element.spinner( "widget" );
equal( widgetElement.length, 1, "one element" ); assert.equal( widgetElement.length, 1, "one element" );
strictEqual( widgetElement[ 0 ], element.parent()[ 0 ], "parent element" ); assert.strictEqual( widgetElement[ 0 ], element.parent()[ 0 ], "parent element" );
} ); } );
} ); } );

View File

@ -1,16 +1,17 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/spinner", "ui/widgets/spinner",
"globalize", "globalize",
"globalize/ja-JP" "globalize/ja-JP"
], function( $ ) { ], function( QUnit, $ ) {
module( "spinner: options" ); QUnit.module( "spinner: options" );
// culture is tested after numberFormat, since it depends on numberFormat // Culture is tested after numberFormat, since it depends on numberFormat
test( "icons: default ", function( assert ) { QUnit.test( "icons: default ", function( assert ) {
expect( 4 ); assert.expect( 4 );
var element = $( "#spin" ).val( 0 ).spinner(); var element = $( "#spin" ).val( 0 ).spinner();
assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon:first" ), assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon:first" ),
"ui-icon ui-icon-triangle-1-n" ); "ui-icon ui-icon-triangle-1-n" );
@ -27,8 +28,8 @@ test( "icons: default ", function( assert ) {
"ui-icon ui-icon-caret-1-s" ); "ui-icon ui-icon-caret-1-s" );
} ); } );
test( "icons: custom ", function( assert ) { QUnit.test( "icons: custom ", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#spin" ).val( 0 ).spinner( { var element = $( "#spin" ).val( 0 ).spinner( {
icons: { icons: {
down: "custom-down", down: "custom-down",
@ -39,15 +40,15 @@ test( "icons: custom ", function( assert ) {
assert.hasClasses( element.find( ".ui-icon:last" ), "ui-icon custom-down" ); assert.hasClasses( element.find( ".ui-icon:last" ), "ui-icon custom-down" );
} ); } );
test( "incremental, false", function() { QUnit.test( "incremental, false", function( assert ) {
expect( 100 ); assert.expect( 100 );
var i, var i,
prev = 0, prev = 0,
element = $( "#spin" ).val( prev ).spinner( { element = $( "#spin" ).val( prev ).spinner( {
incremental: false, incremental: false,
spin: function( event, ui ) { spin: function( event, ui ) {
equal( ui.value - prev, 1 ); assert.equal( ui.value - prev, 1 );
prev = ui.value; prev = ui.value;
} }
} ); } );
@ -58,8 +59,8 @@ test( "incremental, false", function() {
element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } ); element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } );
} ); } );
test( "incremental, true", function() { QUnit.test( "incremental, true", function( assert ) {
expect( 100 ); assert.expect( 100 );
function fill( num, val ) { function fill( num, val ) {
return $.map( new Array( num ), function() { return $.map( new Array( num ), function() {
@ -75,7 +76,7 @@ test( "incremental, true", function() {
element = $( "#spin" ).val( prev ).spinner( { element = $( "#spin" ).val( prev ).spinner( {
incremental: true, incremental: true,
spin: function( event, ui ) { spin: function( event, ui ) {
equal( ui.value - prev, expected[ i ] ); assert.equal( ui.value - prev, expected[ i ] );
prev = ui.value; prev = ui.value;
} }
} ); } );
@ -86,8 +87,8 @@ test( "incremental, true", function() {
element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } ); element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } );
} ); } );
test( "incremental, function", function() { QUnit.test( "incremental, function", function( assert ) {
expect( 100 ); assert.expect( 100 );
var i, var i,
prev = 0, prev = 0,
@ -96,7 +97,7 @@ test( "incremental, function", function() {
return i; return i;
}, },
spin: function( event, ui ) { spin: function( event, ui ) {
equal( ui.value - prev, i + 1 ); assert.equal( ui.value - prev, i + 1 );
prev = ui.value; prev = ui.value;
} }
} ); } );
@ -107,86 +108,86 @@ test( "incremental, function", function() {
element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } ); element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } );
} ); } );
test( "numberFormat, number", function() { QUnit.test( "numberFormat, number", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "n" } ); var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "n" } );
equal( element.val(), "0.00", "formatted on init" ); assert.equal( element.val(), "0.00", "formatted on init" );
element.spinner( "stepUp" ); element.spinner( "stepUp" );
equal( element.val(), "1.00", "formatted after step" ); assert.equal( element.val(), "1.00", "formatted after step" );
} ); } );
test( "numberFormat, number, simple", function() { QUnit.test( "numberFormat, number, simple", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "n0" } ); var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "n0" } );
equal( element.val(), "0", "formatted on init" ); assert.equal( element.val(), "0", "formatted on init" );
element.spinner( "stepUp" ); element.spinner( "stepUp" );
equal( element.val(), "1", "formatted after step" ); assert.equal( element.val(), "1", "formatted after step" );
} ); } );
test( "numberFormat, currency", function() { QUnit.test( "numberFormat, currency", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "C" } ); var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "C" } );
equal( element.val(), "$0.00", "formatted on init" ); assert.equal( element.val(), "$0.00", "formatted on init" );
element.spinner( "stepUp" ); element.spinner( "stepUp" );
equal( element.val(), "$1.00", "formatted after step" ); assert.equal( element.val(), "$1.00", "formatted after step" );
} ); } );
test( "numberFormat, change", function() { QUnit.test( "numberFormat, change", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#spin" ).val( 5 ).spinner( { numberFormat: "n1" } ); var element = $( "#spin" ).val( 5 ).spinner( { numberFormat: "n1" } );
equal( element.val(), "5.0", "formatted on init" ); assert.equal( element.val(), "5.0", "formatted on init" );
element.spinner( "option", "numberFormat", "c" ); element.spinner( "option", "numberFormat", "c" );
equal( element.val(), "$5.00", "formatted after change" ); assert.equal( element.val(), "$5.00", "formatted after change" );
} ); } );
test( "culture, null", function() { QUnit.test( "culture, null", function( assert ) {
expect( 2 ); assert.expect( 2 );
Globalize.culture( "ja-JP" ); Globalize.culture( "ja-JP" );
var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "C" } ); var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "C" } );
equal( element.val(), "¥0", "formatted on init" ); assert.equal( element.val(), "¥0", "formatted on init" );
element.spinner( "stepUp" ); element.spinner( "stepUp" );
equal( element.val(), "¥1", "formatted after step" ); assert.equal( element.val(), "¥1", "formatted after step" );
// Reset culture // Reset culture
Globalize.culture( "default" ); Globalize.culture( "default" );
} ); } );
test( "currency, ja-JP", function() { QUnit.test( "currency, ja-JP", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#spin" ).val( 0 ).spinner( { var element = $( "#spin" ).val( 0 ).spinner( {
numberFormat: "C", numberFormat: "C",
culture: "ja-JP" culture: "ja-JP"
} ); } );
equal( element.val(), "¥0", "formatted on init" ); assert.equal( element.val(), "¥0", "formatted on init" );
element.spinner( "stepUp" ); element.spinner( "stepUp" );
equal( element.val(), "¥1", "formatted after step" ); assert.equal( element.val(), "¥1", "formatted after step" );
} ); } );
test( "currency, change", function() { QUnit.test( "currency, change", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#spin" ).val( 5 ).spinner( { var element = $( "#spin" ).val( 5 ).spinner( {
numberFormat: "C", numberFormat: "C",
culture: "ja-JP" culture: "ja-JP"
} ); } );
equal( element.val(), "¥5", "formatted on init" ); assert.equal( element.val(), "¥5", "formatted on init" );
element.spinner( "option", "culture", "en" ); element.spinner( "option", "culture", "en" );
equal( element.val(), "$5.00", "formatted after change" ); assert.equal( element.val(), "$5.00", "formatted after change" );
} ); } );
test( "max", function() { QUnit.test( "max", function( assert ) {
expect( 3 ); assert.expect( 3 );
var element = $( "#spin" ).val( 1000 ).spinner( { max: 100 } ); var element = $( "#spin" ).val( 1000 ).spinner( { max: 100 } );
equal( element.val(), 1000, "value not constrained on init" ); assert.equal( element.val(), 1000, "value not constrained on init" );
element.spinner( "value", 1000 ); element.spinner( "value", 1000 );
equal( element.val(), 100, "max constrained in value method" ); assert.equal( element.val(), 100, "max constrained in value method" );
element.val( 1000 ).trigger( "blur" ); element.val( 1000 ).trigger( "blur" );
equal( element.val(), 1000, "max not constrained if manual entry" ); assert.equal( element.val(), 1000, "max not constrained if manual entry" );
} ); } );
test( "max, string", function() { QUnit.test( "max, string", function( assert ) {
expect( 3 ); assert.expect( 3 );
var element = $( "#spin" ) var element = $( "#spin" )
.val( 1000 ) .val( 1000 )
.spinner( { .spinner( {
@ -194,27 +195,27 @@ test( "max, string", function() {
numberFormat: "C", numberFormat: "C",
culture: "en" culture: "en"
} ); } );
equal( element.val(), "$1,000.00", "value not constrained on init" ); assert.equal( element.val(), "$1,000.00", "value not constrained on init" );
equal( element.spinner( "option", "max" ), 100, "option converted to number" ); assert.equal( element.spinner( "option", "max" ), 100, "option converted to number" );
element.spinner( "value", 1000 ); element.spinner( "value", 1000 );
equal( element.val(), "$100.00", "max constrained in value method" ); assert.equal( element.val(), "$100.00", "max constrained in value method" );
} ); } );
test( "min", function() { QUnit.test( "min", function( assert ) {
expect( 3 ); assert.expect( 3 );
var element = $( "#spin" ).val( -1000 ).spinner( { min: -100 } ); var element = $( "#spin" ).val( -1000 ).spinner( { min: -100 } );
equal( element.val(), -1000, "value not constrained on init" ); assert.equal( element.val(), -1000, "value not constrained on init" );
element.spinner( "value", -1000 ); element.spinner( "value", -1000 );
equal( element.val(), -100, "min constrained in value method" ); assert.equal( element.val(), -100, "min constrained in value method" );
element.val( -1000 ).trigger( "blur" ); element.val( -1000 ).trigger( "blur" );
equal( element.val(), -1000, "min not constrained if manual entry" ); assert.equal( element.val(), -1000, "min not constrained if manual entry" );
} ); } );
test( "min, string", function() { QUnit.test( "min, string", function( assert ) {
expect( 3 ); assert.expect( 3 );
var element = $( "#spin" ) var element = $( "#spin" )
.val( -1000 ) .val( -1000 )
.spinner( { .spinner( {
@ -222,50 +223,50 @@ test( "min, string", function() {
numberFormat: "C", numberFormat: "C",
culture: "en" culture: "en"
} ); } );
equal( element.val(), "($1,000.00)", "value not constrained on init" ); assert.equal( element.val(), "($1,000.00)", "value not constrained on init" );
equal( element.spinner( "option", "min" ), -100, "option converted to number" ); assert.equal( element.spinner( "option", "min" ), -100, "option converted to number" );
element.spinner( "value", -1000 ); element.spinner( "value", -1000 );
equal( element.val(), "($100.00)", "min constrained in value method" ); assert.equal( element.val(), "($100.00)", "min constrained in value method" );
} ); } );
test( "step, 2", function() { QUnit.test( "step, 2", function( assert ) {
expect( 3 ); assert.expect( 3 );
var element = $( "#spin" ).val( 0 ).spinner( { step: 2 } ); var element = $( "#spin" ).val( 0 ).spinner( { step: 2 } );
element.spinner( "stepUp" ); element.spinner( "stepUp" );
equal( element.val(), "2", "stepUp" ); assert.equal( element.val(), "2", "stepUp" );
element.spinner( "value", "10.5" ); element.spinner( "value", "10.5" );
equal( element.val(), "10", "value reset to 10" ); assert.equal( element.val(), "10", "value reset to 10" );
element.val( "4.5" ); element.val( "4.5" );
element.spinner( "stepUp" ); element.spinner( "stepUp" );
equal( element.val(), "6", "stepUp" ); assert.equal( element.val(), "6", "stepUp" );
} ); } );
test( "step, 0.7", function() { QUnit.test( "step, 0.7", function( assert ) {
expect( 1 ); assert.expect( 1 );
var element = $( "#spin" ).val( 0 ).spinner( { var element = $( "#spin" ).val( 0 ).spinner( {
step: 0.7 step: 0.7
} ); } );
element.spinner( "stepUp" ); element.spinner( "stepUp" );
equal( element.val(), "0.7", "stepUp" ); assert.equal( element.val(), "0.7", "stepUp" );
} ); } );
test( "step, string", function() { QUnit.test( "step, string", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#spin" ).val( 0 ).spinner( { var element = $( "#spin" ).val( 0 ).spinner( {
step: "$0.70", step: "$0.70",
numberFormat: "C", numberFormat: "C",
culture: "en" culture: "en"
} ); } );
equal( element.spinner( "option", "step" ), 0.7, "option converted to number" ); assert.equal( element.spinner( "option", "step" ), 0.7, "option converted to number" );
element.spinner( "stepUp" ); element.spinner( "stepUp" );
equal( element.val(), "$0.70", "stepUp" ); assert.equal( element.val(), "$0.70", "stepUp" );
} ); } );
} ); } );