diff options
Diffstat (limited to 'tests/unit/spinner/options.js')
-rw-r--r-- | tests/unit/spinner/options.js | 155 |
1 files changed, 78 insertions, 77 deletions
diff --git a/tests/unit/spinner/options.js b/tests/unit/spinner/options.js index 8ad5caeaa..381e1b7fa 100644 --- a/tests/unit/spinner/options.js +++ b/tests/unit/spinner/options.js @@ -1,16 +1,17 @@ define( [ + "qunit", "jquery", "ui/widgets/spinner", "globalize", "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 ) { - expect( 4 ); +QUnit.test( "icons: default ", function( assert ) { + assert.expect( 4 ); var element = $( "#spin" ).val( 0 ).spinner(); assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon:first" ), "ui-icon ui-icon-triangle-1-n" ); @@ -27,8 +28,8 @@ test( "icons: default ", function( assert ) { "ui-icon ui-icon-caret-1-s" ); } ); -test( "icons: custom ", function( assert ) { - expect( 2 ); +QUnit.test( "icons: custom ", function( assert ) { + assert.expect( 2 ); var element = $( "#spin" ).val( 0 ).spinner( { icons: { down: "custom-down", @@ -39,15 +40,15 @@ test( "icons: custom ", function( assert ) { assert.hasClasses( element.find( ".ui-icon:last" ), "ui-icon custom-down" ); } ); -test( "incremental, false", function() { - expect( 100 ); +QUnit.test( "incremental, false", function( assert ) { + assert.expect( 100 ); var i, prev = 0, element = $( "#spin" ).val( prev ).spinner( { incremental: false, spin: function( event, ui ) { - equal( ui.value - prev, 1 ); + assert.equal( ui.value - prev, 1 ); prev = ui.value; } } ); @@ -58,8 +59,8 @@ test( "incremental, false", function() { element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } ); } ); -test( "incremental, true", function() { - expect( 100 ); +QUnit.test( "incremental, true", function( assert ) { + assert.expect( 100 ); function fill( num, val ) { return $.map( new Array( num ), function() { @@ -70,12 +71,12 @@ test( "incremental, true", function() { var i, 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( 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 ] ); + assert.equal( ui.value - prev, expected[ i ] ); prev = ui.value; } } ); @@ -86,8 +87,8 @@ test( "incremental, true", function() { element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } ); } ); -test( "incremental, function", function() { - expect( 100 ); +QUnit.test( "incremental, function", function( assert ) { + assert.expect( 100 ); var i, prev = 0, @@ -96,7 +97,7 @@ test( "incremental, function", function() { return i; }, spin: function( event, ui ) { - equal( ui.value - prev, i + 1 ); + assert.equal( ui.value - prev, i + 1 ); prev = ui.value; } } ); @@ -107,86 +108,86 @@ test( "incremental, function", function() { element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } ); } ); -test( "numberFormat, number", function() { - expect( 2 ); +QUnit.test( "numberFormat, number", function( assert ) { + assert.expect( 2 ); 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" ); - equal( element.val(), "1.00", "formatted after step" ); + assert.equal( element.val(), "1.00", "formatted after step" ); } ); -test( "numberFormat, number, simple", function() { - expect( 2 ); +QUnit.test( "numberFormat, number, simple", function( assert ) { + assert.expect( 2 ); 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" ); - equal( element.val(), "1", "formatted after step" ); + assert.equal( element.val(), "1", "formatted after step" ); } ); -test( "numberFormat, currency", function() { - expect( 2 ); +QUnit.test( "numberFormat, currency", function( assert ) { + assert.expect( 2 ); 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" ); - equal( element.val(), "$1.00", "formatted after step" ); + assert.equal( element.val(), "$1.00", "formatted after step" ); } ); -test( "numberFormat, change", function() { - expect( 2 ); +QUnit.test( "numberFormat, change", function( assert ) { + assert.expect( 2 ); 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" ); - equal( element.val(), "$5.00", "formatted after change" ); + assert.equal( element.val(), "$5.00", "formatted after change" ); } ); -test( "culture, null", function() { - expect( 2 ); +QUnit.test( "culture, null", function( assert ) { + assert.expect( 2 ); Globalize.culture( "ja-JP" ); 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" ); - equal( element.val(), "¥1", "formatted after step" ); + assert.equal( element.val(), "¥1", "formatted after step" ); // Reset culture Globalize.culture( "default" ); } ); -test( "currency, ja-JP", function() { - expect( 2 ); +QUnit.test( "currency, ja-JP", function( assert ) { + assert.expect( 2 ); var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "C", culture: "ja-JP" } ); - equal( element.val(), "¥0", "formatted on init" ); + assert.equal( element.val(), "¥0", "formatted on init" ); element.spinner( "stepUp" ); - equal( element.val(), "¥1", "formatted after step" ); + assert.equal( element.val(), "¥1", "formatted after step" ); } ); -test( "currency, change", function() { - expect( 2 ); +QUnit.test( "currency, change", function( assert ) { + assert.expect( 2 ); var element = $( "#spin" ).val( 5 ).spinner( { numberFormat: "C", culture: "ja-JP" } ); - equal( element.val(), "¥5", "formatted on init" ); + assert.equal( element.val(), "¥5", "formatted on init" ); 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() { - expect( 3 ); +QUnit.test( "max", function( assert ) { + assert.expect( 3 ); 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 ); - equal( element.val(), 100, "max constrained in value method" ); + assert.equal( element.val(), 100, "max constrained in value method" ); 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() { - expect( 3 ); +QUnit.test( "max, string", function( assert ) { + assert.expect( 3 ); var element = $( "#spin" ) .val( 1000 ) .spinner( { @@ -194,27 +195,27 @@ test( "max, string", function() { numberFormat: "C", culture: "en" } ); - equal( element.val(), "$1,000.00", "value not constrained on init" ); - equal( element.spinner( "option", "max" ), 100, "option converted to number" ); + assert.equal( element.val(), "$1,000.00", "value not constrained on init" ); + assert.equal( element.spinner( "option", "max" ), 100, "option converted to number" ); 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() { - expect( 3 ); +QUnit.test( "min", function( assert ) { + assert.expect( 3 ); 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 ); - equal( element.val(), -100, "min constrained in value method" ); + assert.equal( element.val(), -100, "min constrained in value method" ); 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() { - expect( 3 ); +QUnit.test( "min, string", function( assert ) { + assert.expect( 3 ); var element = $( "#spin" ) .val( -1000 ) .spinner( { @@ -222,50 +223,50 @@ test( "min, string", function() { numberFormat: "C", culture: "en" } ); - equal( element.val(), "($1,000.00)", "value not constrained on init" ); - equal( element.spinner( "option", "min" ), -100, "option converted to number" ); + assert.equal( element.val(), "($1,000.00)", "value not constrained on init" ); + assert.equal( element.spinner( "option", "min" ), -100, "option converted to number" ); 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() { - expect( 3 ); +QUnit.test( "step, 2", function( assert ) { + assert.expect( 3 ); var element = $( "#spin" ).val( 0 ).spinner( { step: 2 } ); element.spinner( "stepUp" ); - equal( element.val(), "2", "stepUp" ); + assert.equal( element.val(), "2", "stepUp" ); 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.spinner( "stepUp" ); - equal( element.val(), "6", "stepUp" ); + assert.equal( element.val(), "6", "stepUp" ); } ); -test( "step, 0.7", function() { - expect( 1 ); +QUnit.test( "step, 0.7", function( assert ) { + assert.expect( 1 ); var element = $( "#spin" ).val( 0 ).spinner( { step: 0.7 } ); element.spinner( "stepUp" ); - equal( element.val(), "0.7", "stepUp" ); + assert.equal( element.val(), "0.7", "stepUp" ); } ); -test( "step, string", function() { - expect( 2 ); +QUnit.test( "step, string", function( assert ) { + assert.expect( 2 ); var element = $( "#spin" ).val( 0 ).spinner( { step: "$0.70", numberFormat: "C", 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" ); - equal( element.val(), "$0.70", "stepUp" ); + assert.equal( element.val(), "$0.70", "stepUp" ); } ); } ); |