diff options
author | Scott González <scott.gonzalez@gmail.com> | 2011-08-13 19:05:04 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-08-13 19:05:04 -0400 |
commit | 1aea0ff4b83d3bc3242767d4c5a87983b4b47839 (patch) | |
tree | 2c8eb9c75d6b4fc44442a7dc1603cba11bad82da /tests | |
parent | 257021b1af4f5414fb71ada695d86bd51bb5dc04 (diff) | |
download | jquery-ui-1aea0ff4b83d3bc3242767d4c5a87983b4b47839.tar.gz jquery-ui-1aea0ff4b83d3bc3242767d4c5a87983b4b47839.zip |
Spinner: Removed value option. Don't change empty values to zero on init. Don't enforce min/max on blur.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/spinner/spinner_core.js | 42 | ||||
-rw-r--r-- | tests/unit/spinner/spinner_defaults.js | 1 | ||||
-rw-r--r-- | tests/unit/spinner/spinner_events.js | 6 | ||||
-rw-r--r-- | tests/unit/spinner/spinner_methods.js | 16 | ||||
-rw-r--r-- | tests/unit/spinner/spinner_options.js | 57 |
5 files changed, 55 insertions, 67 deletions
diff --git a/tests/unit/spinner/spinner_core.js b/tests/unit/spinner/spinner_core.js index 1c2b7ae17..57b6b3320 100644 --- a/tests/unit/spinner/spinner_core.js +++ b/tests/unit/spinner/spinner_core.js @@ -4,9 +4,8 @@ module( "spinner: core" ); test( "keydown UP on input, increases value not greater than max", function() { expect( 5 ); - var element = $( "#spin" ).spinner({ + var element = $( "#spin" ).val( 70 ).spinner({ max: 100, - value: 70, step: 10 }); @@ -24,9 +23,8 @@ test( "keydown UP on input, increases value not greater than max", function() { test( "keydown DOWN on input, decreases value not less than min", function() { expect( 5 ); - var element = $( "#spin" ).spinner({ + var element = $( "#spin" ).val( 50 ).spinner({ min: 20, - value: 50, step: 10 }); @@ -44,9 +42,8 @@ test( "keydown DOWN on input, decreases value not less than min", function() { test( "keydown PAGE_UP on input, increases value not greater than max", function() { expect( 5 ); - var element = $( "#spin" ).spinner({ + var element = $( "#spin" ).val( 70 ).spinner({ max: 100, - value: 70, page: 10 }); @@ -64,9 +61,8 @@ test( "keydown PAGE_UP on input, increases value not greater than max", function test( "keydown PAGE_DOWN on input, decreases value not less than min", function() { expect( 5 ); - var element = $( "#spin" ).spinner({ + var element = $( "#spin" ).val( 50 ).spinner({ min: 20, - value: 50, page: 10 }); @@ -84,9 +80,8 @@ test( "keydown PAGE_DOWN on input, decreases value not less than min", function( test( "mouse click on up button, increases value not greater than max", function() { expect( 3 ); - var element = $( "#spin" ).spinner({ - max: 20, - value: 18 + var element = $( "#spin" ).val( 18 ).spinner({ + max: 20 }), button = element.spinner( "widget" ).find( ".ui-spinner-up" ); @@ -100,9 +95,8 @@ test( "mouse click on up button, increases value not greater than max", function test( "mouse click on up button, increases value not greater than max", function() { expect( 3 ); - var element = $( "#spin" ).spinner({ - min: 0, - value: 2 + var element = $( "#spin" ).val( 2 ).spinner({ + min: 0 }), button = element.spinner( "widget" ).find( ".ui-spinner-down" ); @@ -137,10 +131,9 @@ test( "mousewheel on input", function() { }); test( "reading HTML5 attributes", function() { - expect( 8 ); + expect( 6 ); var markup = "<input type='number' min='-100' max='100' value='5' step='2'>", element = $( markup ).spinner(); - equal( element.spinner( "option", "value" ), 5, "value from markup" ); equal( element.spinner( "option", "min" ), -100, "min from markup" ); equal( element.spinner( "option", "max" ), 100, "max from markup" ); equal( element.spinner( "option", "step" ), 2, "step from markup" ); @@ -148,10 +141,8 @@ test( "reading HTML5 attributes", function() { element = $( markup ).spinner({ min: -200, max: 200, - value: 20, step: 5 }); - equal( element.spinner( "option", "value" ), 20, "value from options" ); equal( element.spinner( "option", "min" ), -200, "min from options" ); equal( element.spinner( "option", "max" ), 200, "max from options" ); equal( element.spinner( "option", "step" ), 5, "stop from options" ); @@ -159,7 +150,7 @@ test( "reading HTML5 attributes", function() { test( "ARIA attributes", function() { expect( 7 ); - var element = $( "#spin" ).spinner({ min: -5, max: 5, value: 2 }); + var element = $( "#spin" ).val( 2 ).spinner({ min: -5, max: 5 }); equal( element.attr( "role" ), "spinbutton", "role" ); equal( element.attr( "aria-valuemin" ), -5, "aria-valuemin" ); @@ -185,17 +176,22 @@ test( "focus text field when pressing button", function() { ok( element[ 0 ] === document.activeElement, "focused after" ); }); +test( "don't clear invalid value on blur", function() { + expect( 1 ); + var element = $( "#spin" ).spinner(); + element.focus().val( "a" ).blur(); + equal( element.val(), "a" ); +}); + test( "precision", function() { expect( 2 ); - var element = $( "#spin" ).spinner({ - value: .05, + var element = $( "#spin" ).val( .05 ).spinner({ step: .0001 }); element.spinner( "stepUp" ); equal( element.val(), "0.0501", "precision from step" ); - element.spinner( "option", { - value: 1.05, + element.val( 1.05 ).spinner( "option", { step: 1 }); element.spinner( "stepDown" ); diff --git a/tests/unit/spinner/spinner_defaults.js b/tests/unit/spinner/spinner_defaults.js index 18949ff90..f155a658e 100644 --- a/tests/unit/spinner/spinner_defaults.js +++ b/tests/unit/spinner/spinner_defaults.js @@ -7,7 +7,6 @@ commonWidgetTests( "spinner", { numberFormat: null, page: 10, step: 1, - value: 0, // callbacks change: null, diff --git a/tests/unit/spinner/spinner_events.js b/tests/unit/spinner/spinner_events.js index e9f5da1ce..e43ba3365 100644 --- a/tests/unit/spinner/spinner_events.js +++ b/tests/unit/spinner/spinner_events.js @@ -129,24 +129,28 @@ test( "change", function() { }); } + element.focus(); shouldChange( false, "key UP, before blur" ); spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); shouldChange( true, "blur after key UP" ); element.blur(); + element.focus(); shouldChange( false, "key DOWN, before blur" ); spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); shouldChange( true, "blur after key DOWN" ); element.blur(); + element.focus(); shouldChange( false, "key PAGE_UP, before blur" ); spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); shouldChange( true, "blur after key PAGE_UP" ); element.blur(); + element.focus(); shouldChange( false, "key PAGE_DOWN, before blur" ); spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); - shouldChange( true, "key PAGE_DOWN" ); + shouldChange( true, "blur after key PAGE_DOWN" ); element.blur(); shouldChange( false, "many keys, before blur" ); diff --git a/tests/unit/spinner/spinner_methods.js b/tests/unit/spinner/spinner_methods.js index 29494f9cc..fbfcf1bb3 100644 --- a/tests/unit/spinner/spinner_methods.js +++ b/tests/unit/spinner/spinner_methods.js @@ -11,7 +11,7 @@ test( "destroy", function() { test( "disable", function() { expect( 14 ); - var element = $( "#spin" ).spinner({ value: 2 }), + var element = $( "#spin" ).val( 2 ).spinner(), wrapper = $( "#spin" ).spinner( "widget" ); ok( !wrapper.hasClass( "ui-spinner-disabled" ), "before: wrapper does not have ui-spinner-disabled class" ); @@ -71,9 +71,8 @@ test( "enable", function() { test( "pageDown", function() { expect( 4 ); - var element = $( "#spin" ).spinner({ + var element = $( "#spin" ).val( -12 ).spinner({ page: 20, - value: -12, min: -100 }); @@ -92,9 +91,8 @@ test( "pageDown", function() { test( "pageUp", function() { expect( 4 ); - var element = $( "#spin" ).spinner({ + var element = $( "#spin" ).val( 12 ).spinner({ page: 20, - value: 12, max: 100 }); @@ -113,9 +111,8 @@ test( "pageUp", function() { test( "stepDown", function() { expect( 4 ); - var element = $( "#spin" ).spinner({ + var element = $( "#spin" ).val( 0 ).spinner({ step: 2, - value: 0, min: -15 }); @@ -134,9 +131,8 @@ test( "stepDown", function() { test( "stepUp", function() { expect( 4 ); - var element = $( "#spin" ).spinner({ + var element = $( "#spin" ).val( 0 ).spinner({ step: 2, - value: 0, max: 15 }); @@ -155,7 +151,7 @@ test( "stepUp", function() { test( "value", function() { expect( 2 ); - var element = $( "#spin" ).spinner({ value: 0 }); + var element = $( "#spin" ).val( 0 ).spinner(); element.spinner( "value", 10 ); equals( element.val(), 10, "change value via value method" ); diff --git a/tests/unit/spinner/spinner_options.js b/tests/unit/spinner/spinner_options.js index 30155e755..647455fe5 100644 --- a/tests/unit/spinner/spinner_options.js +++ b/tests/unit/spinner/spinner_options.js @@ -3,30 +3,27 @@ module( "spinner: options" ); test( "numberFormat, number", function() { - expect( 1 ); - var element = $( "#spin" ).spinner({ - value: "1", - numberFormat: "n" - }); - equal( element.val(), "1.00", "n" ); + 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" ); }); test( "numberFormat, number, simple", function() { - expect( 1 ); - var element = $( "#spin" ).spinner({ - value: "1", - numberFormat: "n0" - }); - equal( element.val(), "1", "n0" ); + 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" ); }); test( "numberFormat, currency", function() { - expect( 1 ); - var element = $( "#spin" ).spinner({ - value: "1", - numberFormat: "C" - }); - equal( element.val(), "$1.00", "C" ); + 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" ); }); /* TODO figure out how to test this properly @@ -69,32 +66,31 @@ test("incremental - true (default)", function() { test( "max", function() { expect( 3 ); - var element = $( "#spin" ).spinner({ max: 100, value: 1000 }); - equals( element.val(), 100, "max constrained if value option is greater" ); + var element = $( "#spin" ).val( 1000 ).spinner({ max: 100 }); + equals( element.val(), 1000, "value not constrained on init" ); element.spinner( "value", 1000 ); equals( element.val(), 100, "max constrained if value method is greater" ); element.val( 1000 ).blur(); - equals( element.val(), 100, "max constrained if manual entry" ); + equals( element.val(), 1000, "max not constrained if manual entry" ); }); test( "min", function() { expect( 3 ); - var element = $( "#spin" ).spinner({ min: -100, value: -1000 }); - equals( element.val(), -100, "min constrained if value option is greater" ); + var element = $( "#spin" ).val( -1000 ).spinner({ min: -100 }); + equals( element.val(), -1000, "value not constrained on init" ); element.spinner( "value", -1000 ); equals( element.val(), -100, "min constrained if value method is greater" ); element.val( -1000 ).blur(); - equals( element.val(), -100, "min constrained if manual entry" ); + equals( element.val(), -1000, "min not constrained if manual entry" ); }); test( "step, 2", function() { - expect( 4 ); - var element = $( "#spin" ).spinner({ step: 2 }); - equals( element.val(), "0", "value initialized to 0" ); + expect( 3 ); + var element = $( "#spin" ).val( 0 ).spinner({ step: 2 }); element.spinner( "stepUp" ); equals( element.val(), "2", "stepUp" ); @@ -107,16 +103,13 @@ test( "step, 2", function() { }); test( "step, 0.7", function() { - expect( 2 ); - var element = $("#spin").spinner({ + expect( 1 ); + var element = $("#spin").val( 0 ).spinner({ step: 0.7 }); - equals( element.val(), "0", "value initialized to 0" ); element.spinner( "stepUp" ); equals( element.val(), "0.7", "stepUp" ); }); -// TODO: test value - })( jQuery ); |