2015-04-06 23:46:15 +00:00
|
|
|
define( [
|
2016-04-06 13:26:05 +00:00
|
|
|
"qunit",
|
2015-04-06 23:46:15 +00:00
|
|
|
"jquery",
|
2020-05-16 07:16:24 +00:00
|
|
|
"lib/helper",
|
2015-07-15 02:10:12 +00:00
|
|
|
"ui/widgets/spinner",
|
2015-04-06 23:46:15 +00:00
|
|
|
"globalize",
|
|
|
|
"globalize/ja-JP"
|
2020-05-16 07:16:24 +00:00
|
|
|
], function( QUnit, $, helper ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2020-05-16 07:16:24 +00:00
|
|
|
QUnit.module( "spinner: options", { afterEach: helper.moduleAfterEach } );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
// Culture is tested after numberFormat, since it depends on numberFormat
|
2011-09-28 22:30:58 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "icons: default ", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2012-12-27 11:50:04 +00:00
|
|
|
var element = $( "#spin" ).val( 0 ).spinner();
|
2020-01-22 15:44:34 +00:00
|
|
|
assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon" ).first(),
|
2015-01-30 15:59:50 +00:00
|
|
|
"ui-icon ui-icon-triangle-1-n" );
|
2020-01-22 15:44:34 +00:00
|
|
|
assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon" ).last(),
|
2015-01-30 15:59:50 +00:00
|
|
|
"ui-icon ui-icon-triangle-1-s" );
|
2012-12-27 11:50:04 +00:00
|
|
|
|
|
|
|
element.spinner( "option", "icons", {
|
2014-11-03 17:08:06 +00:00
|
|
|
up: "ui-icon-caret-1-n",
|
|
|
|
down: "ui-icon-caret-1-s"
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2020-01-22 15:44:34 +00:00
|
|
|
assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon" ).first(),
|
2015-01-30 15:59:50 +00:00
|
|
|
"ui-icon ui-icon-caret-1-n" );
|
2020-01-22 15:44:34 +00:00
|
|
|
assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon" ).last(),
|
2015-01-30 15:59:50 +00:00
|
|
|
"ui-icon ui-icon-caret-1-s" );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2012-07-12 15:59:43 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "icons: custom ", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2015-08-24 12:57:40 +00:00
|
|
|
var element = $( "#spin" ).val( 0 ).spinner( {
|
2012-07-12 15:59:43 +00:00
|
|
|
icons: {
|
|
|
|
down: "custom-down",
|
|
|
|
up: "custom-up"
|
|
|
|
}
|
2015-08-24 12:57:40 +00:00
|
|
|
} ).spinner( "widget" );
|
2020-01-22 15:44:34 +00:00
|
|
|
assert.hasClasses( element.find( ".ui-icon" ).first(), "ui-icon custom-up" );
|
|
|
|
assert.hasClasses( element.find( ".ui-icon" ).last(), "ui-icon custom-down" );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2012-07-12 15:59:43 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "incremental, false", function( assert ) {
|
|
|
|
assert.expect( 100 );
|
2011-09-10 00:08:51 +00:00
|
|
|
|
2012-10-23 14:36:42 +00:00
|
|
|
var i,
|
2011-09-10 00:08:51 +00:00
|
|
|
prev = 0,
|
2015-08-24 12:57:40 +00:00
|
|
|
element = $( "#spin" ).val( prev ).spinner( {
|
2011-09-10 00:08:51 +00:00
|
|
|
incremental: false,
|
|
|
|
spin: function( event, ui ) {
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( ui.value - prev, 1 );
|
2011-09-10 00:08:51 +00:00
|
|
|
prev = ui.value;
|
|
|
|
}
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-09-10 00:08:51 +00:00
|
|
|
|
|
|
|
for ( i = 0; i < 100; i++ ) {
|
|
|
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
|
|
|
|
}
|
2011-10-10 18:01:12 +00:00
|
|
|
element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-09-10 00:08:51 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "incremental, true", function( assert ) {
|
|
|
|
assert.expect( 100 );
|
2011-09-10 00:08:51 +00:00
|
|
|
|
|
|
|
function fill( num, val ) {
|
|
|
|
return $.map( new Array( num ), function() {
|
|
|
|
return val;
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-09-10 00:08:51 +00:00
|
|
|
}
|
|
|
|
|
2012-10-23 14:36:42 +00:00
|
|
|
var i,
|
2011-09-10 00:08:51 +00:00
|
|
|
prev = 0,
|
|
|
|
expected = [].concat( fill( 18, 1 ), fill( 37, 2 ), fill( 14, 3 ),
|
2016-04-06 13:26:05 +00:00
|
|
|
fill( 9, 4 ), fill( 6, 5 ), fill( 5, 6 ), fill( 5, 7 ),
|
2011-09-10 00:08:51 +00:00
|
|
|
fill( 4, 8 ), fill( 2, 9 ) ),
|
2015-08-24 12:57:40 +00:00
|
|
|
element = $( "#spin" ).val( prev ).spinner( {
|
2011-09-10 00:08:51 +00:00
|
|
|
incremental: true,
|
|
|
|
spin: function( event, ui ) {
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( ui.value - prev, expected[ i ] );
|
2011-09-10 00:08:51 +00:00
|
|
|
prev = ui.value;
|
|
|
|
}
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-09-10 00:08:51 +00:00
|
|
|
|
|
|
|
for ( i = 0; i < 100; i++ ) {
|
|
|
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
|
|
|
|
}
|
2011-10-10 18:01:12 +00:00
|
|
|
element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-09-10 00:08:51 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "incremental, function", function( assert ) {
|
|
|
|
assert.expect( 100 );
|
2011-09-10 00:08:51 +00:00
|
|
|
|
|
|
|
var i,
|
|
|
|
prev = 0,
|
2015-08-24 12:57:40 +00:00
|
|
|
element = $( "#spin" ).val( prev ).spinner( {
|
2011-09-10 00:08:51 +00:00
|
|
|
incremental: function( i ) {
|
|
|
|
return i;
|
|
|
|
},
|
|
|
|
spin: function( event, ui ) {
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( ui.value - prev, i + 1 );
|
2011-09-10 00:08:51 +00:00
|
|
|
prev = ui.value;
|
|
|
|
}
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-09-10 00:08:51 +00:00
|
|
|
|
|
|
|
for ( i = 0; i < 100; i++ ) {
|
|
|
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
|
|
|
|
}
|
2011-10-10 18:01:12 +00:00
|
|
|
element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-09-10 00:08:51 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "numberFormat, number", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2015-08-24 12:57:40 +00:00
|
|
|
var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "n" } );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "0.00", "formatted on init" );
|
2011-08-13 23:05:04 +00:00
|
|
|
element.spinner( "stepUp" );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "1.00", "formatted after step" );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "numberFormat, number, simple", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2015-08-24 12:57:40 +00:00
|
|
|
var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "n0" } );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "0", "formatted on init" );
|
2011-08-13 23:05:04 +00:00
|
|
|
element.spinner( "stepUp" );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "1", "formatted after step" );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "numberFormat, currency", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2015-08-24 12:57:40 +00:00
|
|
|
var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "C" } );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "$0.00", "formatted on init" );
|
2011-08-13 23:05:04 +00:00
|
|
|
element.spinner( "stepUp" );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "$1.00", "formatted after step" );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "numberFormat, change", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2015-08-24 12:57:40 +00:00
|
|
|
var element = $( "#spin" ).val( 5 ).spinner( { numberFormat: "n1" } );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "5.0", "formatted on init" );
|
2011-11-16 17:07:33 +00:00
|
|
|
element.spinner( "option", "numberFormat", "c" );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "$5.00", "formatted after change" );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-11-16 17:07:33 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "culture, null", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2011-09-28 22:30:58 +00:00
|
|
|
Globalize.culture( "ja-JP" );
|
2015-08-24 12:57:40 +00:00
|
|
|
var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "C" } );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "¥0", "formatted on init" );
|
2011-09-28 22:30:58 +00:00
|
|
|
element.spinner( "stepUp" );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "¥1", "formatted after step" );
|
2011-09-28 22:30:58 +00:00
|
|
|
|
2015-08-21 04:04:59 +00:00
|
|
|
// Reset culture
|
2011-09-28 22:30:58 +00:00
|
|
|
Globalize.culture( "default" );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-09-28 22:30:58 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "currency, ja-JP", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2015-08-24 12:57:40 +00:00
|
|
|
var element = $( "#spin" ).val( 0 ).spinner( {
|
2011-09-28 22:30:58 +00:00
|
|
|
numberFormat: "C",
|
|
|
|
culture: "ja-JP"
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "¥0", "formatted on init" );
|
2011-09-28 22:30:58 +00:00
|
|
|
element.spinner( "stepUp" );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "¥1", "formatted after step" );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-09-28 22:30:58 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "currency, change", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2015-08-24 12:57:40 +00:00
|
|
|
var element = $( "#spin" ).val( 5 ).spinner( {
|
2011-11-16 17:07:33 +00:00
|
|
|
numberFormat: "C",
|
|
|
|
culture: "ja-JP"
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "¥5", "formatted on init" );
|
2011-11-16 17:07:33 +00:00
|
|
|
element.spinner( "option", "culture", "en" );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "$5.00", "formatted after change" );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-11-16 17:07:33 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "max", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2015-08-24 12:57:40 +00:00
|
|
|
var element = $( "#spin" ).val( 1000 ).spinner( { max: 100 } );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), 1000, "value not constrained on init" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "value", 1000 );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), 100, "max constrained in value method" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2015-05-14 02:01:44 +00:00
|
|
|
element.val( 1000 ).trigger( "blur" );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), 1000, "max not constrained if manual entry" );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "max, string", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2012-01-07 14:12:27 +00:00
|
|
|
var element = $( "#spin" )
|
|
|
|
.val( 1000 )
|
2015-08-24 12:57:40 +00:00
|
|
|
.spinner( {
|
2012-01-07 14:12:27 +00:00
|
|
|
max: "$100.00",
|
|
|
|
numberFormat: "C",
|
|
|
|
culture: "en"
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "$1,000.00", "value not constrained on init" );
|
|
|
|
assert.equal( element.spinner( "option", "max" ), 100, "option converted to number" );
|
2012-01-07 14:12:27 +00:00
|
|
|
|
|
|
|
element.spinner( "value", 1000 );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "$100.00", "max constrained in value method" );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2012-01-07 14:12:27 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "min", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2015-08-24 12:57:40 +00:00
|
|
|
var element = $( "#spin" ).val( -1000 ).spinner( { min: -100 } );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), -1000, "value not constrained on init" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "value", -1000 );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), -100, "min constrained in value method" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2015-05-14 02:01:44 +00:00
|
|
|
element.val( -1000 ).trigger( "blur" );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), -1000, "min not constrained if manual entry" );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "min, string", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2012-01-07 14:12:27 +00:00
|
|
|
var element = $( "#spin" )
|
|
|
|
.val( -1000 )
|
2015-08-24 12:57:40 +00:00
|
|
|
.spinner( {
|
2012-01-07 14:12:27 +00:00
|
|
|
min: "-$100.00",
|
|
|
|
numberFormat: "C",
|
|
|
|
culture: "en"
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "($1,000.00)", "value not constrained on init" );
|
|
|
|
assert.equal( element.spinner( "option", "min" ), -100, "option converted to number" );
|
2012-01-07 14:12:27 +00:00
|
|
|
|
|
|
|
element.spinner( "value", -1000 );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "($100.00)", "min constrained in value method" );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2012-01-07 14:12:27 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "step, 2", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2015-08-24 12:57:40 +00:00
|
|
|
var element = $( "#spin" ).val( 0 ).spinner( { step: 2 } );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "stepUp" );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "2", "stepUp" );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "value", "10.5" );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( 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" );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "6", "stepUp" );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "step, 0.7", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2015-08-24 12:57:40 +00:00
|
|
|
var element = $( "#spin" ).val( 0 ).spinner( {
|
2011-08-07 12:10:49 +00:00
|
|
|
step: 0.7
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
|
|
|
element.spinner( "stepUp" );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "0.7", "stepUp" );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
QUnit.test( "step, string", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2015-08-24 12:57:40 +00:00
|
|
|
var element = $( "#spin" ).val( 0 ).spinner( {
|
2012-01-07 14:12:27 +00:00
|
|
|
step: "$0.70",
|
|
|
|
numberFormat: "C",
|
|
|
|
culture: "en"
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2012-01-07 14:12:27 +00:00
|
|
|
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.spinner( "option", "step" ), 0.7, "option converted to number" );
|
2012-01-07 14:12:27 +00:00
|
|
|
|
|
|
|
element.spinner( "stepUp" );
|
2016-04-06 13:26:05 +00:00
|
|
|
assert.equal( element.val(), "$0.70", "stepUp" );
|
2015-08-24 12:57:40 +00:00
|
|
|
} );
|
2012-01-07 14:12:27 +00:00
|
|
|
|
2015-04-06 23:46:15 +00:00
|
|
|
} );
|