module( "spinner: options" );
+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 } );
+ }
+});
+
test( "numberFormat, number", function() {
expect( 2 );
var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "n" });
equal( element.val(), "$1.00", "formatted after step" );
});
-/* TODO figure out how to test this properly
-test("incremental - false (default)", function() {
- var el = $("#spin").spinner({ incremental:false });
-
- for ( var i = 1 ; i<=120 ; i++ ) {
- el.simulate("keydown",{keyCode:$.ui.keyCode.UP});
- }
- el.simulate("keyup",{keyCode:$.ui.keyCode.UP});
-
- equals(el.val(), 120, "incremental false - keydown 120 times");
-
- for ( var i = 1 ; i<=210 ; i++ ) {
- el.simulate("keydown",{keyCode:$.ui.keyCode.DOWN});
- }
- el.simulate("keyup",{keyCode:$.ui.keyCode.DOWN});
-
- equals(el.val(), -90, "incremental false - keydown 210 times");
-});
-
-test("incremental - true (default)", function() {
- var el = $("#spin").spinner();
-
- for ( var i = 1 ; i<=120 ; i++ ) {
- el.simulate("keydown",{keyCode:$.ui.keyCode.UP});
- }
- el.simulate("keyup",{keyCode:$.ui.keyCode.UP});
-
- equals(el.val(), 300, "incremental true - keydown 120 times (100+20*10)");
-
- for ( var i = 1 ; i<=210 ; i++ ) {
- el.simulate("keydown",{keyCode:$.ui.keyCode.DOWN});
- }
- el.simulate("keyup",{keyCode:$.ui.keyCode.DOWN});
-
- equals(el.val(), -1800, "incremental true - keydown 210 times (300-100-100*10-10*100)");
-});
-*/
-
test( "max", function() {
expect( 3 );
var element = $( "#spin" ).val( 1000 ).spinner({ max: 100 });