2011-08-07 12:10:49 +00:00
|
|
|
(function( $ ) {
|
|
|
|
|
|
|
|
module( "spinner: options" );
|
|
|
|
|
2011-09-10 00:08:51 +00:00
|
|
|
test( "incremental, false", function() {
|
|
|
|
expect( 100 );
|
|
|
|
|
|
|
|
var i, diff,
|
|
|
|
prev = 0,
|
|
|
|
element = $( "#spin" ).val( prev ).spinner({
|
|
|
|
incremental: false,
|
|
|
|
spin: function( event, ui ) {
|
|
|
|
equal( ui.value - prev, 1 );
|
|
|
|
prev = ui.value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
for ( i = 0; i < 100; i++ ) {
|
|
|
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test( "incremental, true", function() {
|
|
|
|
expect( 100 );
|
|
|
|
|
|
|
|
function fill( num, val ) {
|
|
|
|
return $.map( new Array( num ), function() {
|
|
|
|
return val;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var i, diff,
|
|
|
|
prev = 0,
|
|
|
|
expected = [].concat( fill( 18, 1 ), fill( 37, 2 ), fill( 14, 3 ),
|
|
|
|
fill( 9, 4 ), fill( 6, 5 ), fill( 5, 6 ), fill ( 5, 7 ),
|
|
|
|
fill( 4, 8 ), fill( 2, 9 ) ),
|
|
|
|
element = $( "#spin" ).val( prev ).spinner({
|
|
|
|
incremental: true,
|
|
|
|
spin: function( event, ui ) {
|
|
|
|
equal( ui.value - prev, expected[ i ] );
|
|
|
|
prev = ui.value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
for ( i = 0; i < 100; i++ ) {
|
|
|
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test( "incremental, function", function() {
|
|
|
|
expect( 100 );
|
|
|
|
|
|
|
|
var i,
|
|
|
|
prev = 0,
|
|
|
|
element = $( "#spin" ).val( prev ).spinner({
|
|
|
|
incremental: function( i ) {
|
|
|
|
return i;
|
|
|
|
},
|
|
|
|
spin: function( event, ui ) {
|
|
|
|
equal( ui.value - prev, i + 1 );
|
|
|
|
prev = ui.value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
for ( i = 0; i < 100; i++ ) {
|
|
|
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-08-07 12:10:49 +00:00
|
|
|
test( "numberFormat, number", function() {
|
2011-08-13 23:05:04 +00:00
|
|
|
expect( 2 );
|
|
|
|
var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "n" });
|
|
|
|
equal( element.val(), "0.00", "formatted on init" );
|
|
|
|
element.spinner( "stepUp" );
|
|
|
|
equal( element.val(), "1.00", "formatted after step" );
|
2011-08-07 12:10:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "numberFormat, number, simple", function() {
|
2011-08-13 23:05:04 +00:00
|
|
|
expect( 2 );
|
|
|
|
var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "n0" });
|
|
|
|
equal( element.val(), "0", "formatted on init" );
|
|
|
|
element.spinner( "stepUp" );
|
|
|
|
equal( element.val(), "1", "formatted after step" );
|
2011-08-07 12:10:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "numberFormat, currency", function() {
|
2011-08-13 23:05:04 +00:00
|
|
|
expect( 2 );
|
|
|
|
var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "C" });
|
|
|
|
equal( element.val(), "$0.00", "formatted on init" );
|
|
|
|
element.spinner( "stepUp" );
|
|
|
|
equal( element.val(), "$1.00", "formatted after step" );
|
2011-08-07 12:10:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "max", function() {
|
|
|
|
expect( 3 );
|
2011-08-13 23:05:04 +00:00
|
|
|
var element = $( "#spin" ).val( 1000 ).spinner({ max: 100 });
|
|
|
|
equals( element.val(), 1000, "value not constrained on init" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "value", 1000 );
|
|
|
|
equals( element.val(), 100, "max constrained if value method is greater" );
|
|
|
|
|
|
|
|
element.val( 1000 ).blur();
|
2011-08-13 23:05:04 +00:00
|
|
|
equals( element.val(), 1000, "max not constrained if manual entry" );
|
2011-08-07 12:10:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "min", function() {
|
|
|
|
expect( 3 );
|
2011-08-13 23:05:04 +00:00
|
|
|
var element = $( "#spin" ).val( -1000 ).spinner({ min: -100 });
|
|
|
|
equals( element.val(), -1000, "value not constrained on init" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "value", -1000 );
|
|
|
|
equals( element.val(), -100, "min constrained if value method is greater" );
|
|
|
|
|
|
|
|
element.val( -1000 ).blur();
|
2011-08-13 23:05:04 +00:00
|
|
|
equals( element.val(), -1000, "min not constrained if manual entry" );
|
2011-08-07 12:10:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "step, 2", function() {
|
2011-08-13 23:05:04 +00:00
|
|
|
expect( 3 );
|
|
|
|
var element = $( "#spin" ).val( 0 ).spinner({ step: 2 });
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "stepUp" );
|
|
|
|
equals( element.val(), "2", "stepUp" );
|
|
|
|
|
|
|
|
element.spinner( "value", "10.5" );
|
2011-09-14 12:54:29 +00:00
|
|
|
equals( element.val(), "10", "value reset to 10" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2011-09-14 12:54:29 +00:00
|
|
|
element.val( "4.5" );
|
2011-08-07 12:10:49 +00:00
|
|
|
element.spinner( "stepUp" );
|
2011-09-14 12:54:29 +00:00
|
|
|
equals( element.val(), "6", "stepUp" );
|
2011-08-07 12:10:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "step, 0.7", function() {
|
2011-08-13 23:05:04 +00:00
|
|
|
expect( 1 );
|
|
|
|
var element = $("#spin").val( 0 ).spinner({
|
2011-08-07 12:10:49 +00:00
|
|
|
step: 0.7
|
|
|
|
});
|
|
|
|
|
|
|
|
element.spinner( "stepUp" );
|
|
|
|
equals( element.val(), "0.7", "stepUp" );
|
|
|
|
});
|
|
|
|
|
|
|
|
})( jQuery );
|