aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2011-09-09 20:08:51 -0400
committerScott González <scott.gonzalez@gmail.com>2011-09-09 20:08:51 -0400
commit7216c08b2fd9ad5e3cb90500f2b13bed6339f2ba (patch)
tree9f083088cb47dcfce353d5070a2d85698b225ae4 /tests/unit
parent4387d19030820077ac408e373bc135807e6a6002 (diff)
downloadjquery-ui-7216c08b2fd9ad5e3cb90500f2b13bed6339f2ba.tar.gz
jquery-ui-7216c08b2fd9ad5e3cb90500f2b13bed6339f2ba.zip
Spinner: Added ability to specify custom incremental function.
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/spinner/spinner_options.js103
1 files changed, 65 insertions, 38 deletions
diff --git a/tests/unit/spinner/spinner_options.js b/tests/unit/spinner/spinner_options.js
index 647455fe5..48bdf96a9 100644
--- a/tests/unit/spinner/spinner_options.js
+++ b/tests/unit/spinner/spinner_options.js
@@ -2,6 +2,71 @@
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" });
@@ -26,44 +91,6 @@ test( "numberFormat, currency", function() {
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 });