Importing spinner unit tests

This commit is contained in:
jzaefferer 2010-10-22 06:23:52 +02:00
parent f7d8a1ba57
commit af8ca4ed0e
6 changed files with 1160 additions and 0 deletions

View File

@ -0,0 +1,39 @@
<!doctype html>
<html lang="en">
<head>
<title>jQuery UI Spinner Test Suite</title>
<link type="text/css" href="../../../themes/base/jquery.ui.spinner.css" rel="stylesheet" />
<script type="text/javascript" src="../../../jquery-1.4.3.js"></script>
<script type="text/javascript" src="../../../external/jquery.mousewheel-3.0.2.js"></script>
<script type="text/javascript" src="../../../ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="../../../ui/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../../../ui/jquery.ui.spinner.js"></script>
<link rel="stylesheet" href="../../../external/qunit.css" type="text/css"/>
<script type="text/javascript" src="../../../external/qunit.js"></script>
<script type="text/javascript" src="../../jquery.simulate.js"></script>
<script type="text/javascript" src="../testsuite.js"></script>
<script type="text/javascript" src="spinner_core.js"></script>
<script type="text/javascript" src="spinner_defaults.js"></script>
<script type="text/javascript" src="spinner_events.js"></script>
<script type="text/javascript" src="spinner_methods.js"></script>
<script type="text/javascript" src="spinner_options.js"></script>
</head>
<body>
<h1 id="qunit-header">jQuery UI Slider Test Suite</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests">
</ol>
<div id="qunit-fixture">
<input id="spin">
</div>
</body>
</html>

View File

@ -0,0 +1,357 @@
/*
* spinner_core.js
*/
var el,
options,
simulateKeyDownUp = function(el, kCode, shift) {
el.simulate("keydown",{keyCode:kCode, shiftKey: shift || false })
.simulate("keyup",{keyCode:kCode, shiftKey: shift || false });
},
wrapper = function() {
return el.closest('.ui-spinner');
},
upButton = function() {
return wrapper().find('.ui-spinner-up');
},
downButton = function() {
return wrapper().find('.ui-spinner-down');
},
box = function() {
return $('.ui-spinner-input', wrapper());
};
(function($) {
// Spinner Tests
module("spinner: core");
test("init", function() {
expect(3);
$("<input>").appendTo('body').spinner().remove();
ok(true, '.spinner() called on element');
$('<input id="spinner_dis">').spinner().remove();
ok(true, '.spinner() called on disconnected element');
el = $('<input>').spinner();
ok(el.hasClass('ui-spinner-input'), 'input gets ui-spinner-input class on init');
});
test("destroy", function() {
expect(3);
$("<input>").appendTo('body').spinner().spinner("destroy").remove();
ok(true, '.spinner("destroy") called on element');
$('<input id="spinner_dis">').spinner().spinner("destroy").remove();
ok(true, '.spinner().spinner("destroy") called on disconnected element');
el = $('<input>').spinner().spinner('destroy');
ok(!el.hasClass('ui-spinner-input'), 'ui-spinner-input class removed on destroy');
});
test("re-attach", function() {
expect(2);
el = $("<input>").spinner().spinner("destroy").spinner();
ok(true, '.spinner().spinner("destroy").spinner() called on element');
el = $('<input id="spinner_dis">').spinner().spinner("destroy").spinner().remove();
ok(true, '.spinner().spinner("destroy").spinner() called on disconnected element');
});
test("keydown UP on input, increases value not greater than max", function() {
expect(3);
el = $("#spin");
options = {
max:100,
value:50,
step:10
}
el.spinner(options);
simulateKeyDownUp(el, $.ui.keyCode.UP);
equals(el.val(), 60);
for (i = 0; i<11; i++) {
simulateKeyDownUp(el, $.ui.keyCode.UP);
}
equals(el.val(), 100);
el.val(50);
simulateKeyDownUp(el, $.ui.keyCode.UP);
equals(el.val(), 60);
});
test("keydown DOWN on input, decreases value not less than min", function() {
expect(3);
el = $("#spin");
options = {
min:-100,
value:50,
step:10
}
el.spinner(options);
simulateKeyDownUp(el, $.ui.keyCode.DOWN);
equals(el.val(), 40);
for (i = 0; i<21; i++) {
simulateKeyDownUp(el, $.ui.keyCode.DOWN);
}
equals(el.val(), -100);
el.val(50);
simulateKeyDownUp(el, $.ui.keyCode.DOWN);
equals(el.val(), 40);
});
test("keydown PGUP on input, increases value not greater than max", function() {
expect(3);
el = $("#spin");
options = {
max:100,
value:0,
step:10
}
el.spinner(options);
simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);
equals(el.val(), 50);
for (i = 0; i<5; i++) {
simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);
}
equals(el.val(), 100);
el.val(0);
simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);
equals(el.val(), 50);
});
test("keydown PGDN on input, decreases value not less than min", function() {
expect(3);
el = $("#spin");
options = {
min:-100,
value:0,
step:10
}
el.spinner(options);
simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);
equals(el.val(), -50);
for (i = 0; i<5; i++) {
simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);
}
equals(el.val(), -100);
el.val(0);
simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);
equals(el.val(), -50);
});
test("hold SHIFT and keydown UP, increments value but no greater than max", function() {
expect(2);
el = $("#spin");
options = {
max:100,
value:0,
step:10
}
el.spinner(options);
simulateKeyDownUp(el, $.ui.keyCode.UP, true);
equals(el.val(), 50);
for (i = 0; i<5; i++) {
simulateKeyDownUp(el, $.ui.keyCode.UP, true);
}
equals(el.val(), 100);
});
test("hold SHIFT and keydown DOWN, decreases value but no less than min", function() {
expect(2);
el = $("#spin");
options = {
min:-100,
value:0,
step:10
}
el.spinner(options);
simulateKeyDownUp(el, $.ui.keyCode.DOWN, true);
equals(el.val(), -50);
for (i = 0; i<5; i++) {
simulateKeyDownUp(el, $.ui.keyCode.DOWN, true);
}
equals(el.val(), -100);
});
test("keydown HOME on input, sets value to minimum", function() {
el = $("#spin");
options = {
min:-100,
value:50,
step:10
}
el.spinner(options);
simulateKeyDownUp(el, $.ui.keyCode.HOME);
equals(el.val(), -100);
el.spinner('option', 'min', -200);
simulateKeyDownUp(el, $.ui.keyCode.HOME);
equals(el.val(), -200);
});
test("keydown END on input, sets value to maximum", function() {
el = $("#spin");
options = {
max:100,
value:50,
step:10
}
el.spinner(options);
simulateKeyDownUp(el, $.ui.keyCode.END);
equals(el.val(), 100);
el.spinner('option', 'max', 200);
simulateKeyDownUp(el, $.ui.keyCode.END);
equals(el.val(), 200);
});
test("keydown LEFT on input has no effect", function() {
el = $("#spin");
el.spinner();
var value = el.val();
simulateKeyDownUp(el, $.ui.keyCode.LEFT);
equals(el.val(), value);
for (i = 0; i<5; i++) {
simulateKeyDownUp(el, $.ui.keyCode.LEFT);
}
equals(el.val(), value);
});
test("keydown RIGHT on input has no effect", function() {
expect(2);
el = $("#spin");
el.spinner();
var value = el.val();
simulateKeyDownUp(el, $.ui.keyCode.RIGHT);
equals(el.val(), value);
for (i = 0; i<5; i++) {
simulateKeyDownUp(el, $.ui.keyCode.RIGHT);
}
equals(el.val(), value);
});
test("mouse click on buttons", function() {
expect(4);
el = $("#spin").spinner();
val = 0;
$(".ui-spinner-up").trigger("mousedown").trigger("mouseup");
equals(el.val(), ++val, "mouse click to up");
$(".ui-spinner-down").trigger("mousedown").trigger("mouseup");
equals(el.val(), --val, "mouse click to down");
el.val(50);
$(".ui-spinner-up").trigger("mousedown").trigger("mouseup");
equals(el.val(), 51);
el.val(50);
$(".ui-spinner-down").trigger("mousedown").trigger("mouseup");
equals(el.val(), 49);
});
test("mouse wheel on input", function() {
ok(false, 'missing test - untested code is broken code');
});
test("reading HTML5 attributes", function() {
expect(4);
el = $('<input id="spinner" type="number" min="-100" max="100" value="5" step="2">').spinner();
equals(el.spinner('option', 'value'), 5, 'value');
equals(el.spinner('option', 'max'), 100, 'max');
equals(el.spinner('option', 'min'), -100, 'min');
equals(el.spinner('option', 'step'), 2, 'step');
});
test("ARIA attributes", function() {
expect(7);
el = $('#spin').spinner({ min: -5, max: 5, value: 2 });
equals(wrapper().attr('role'), 'spinbutton', 'role');
equals(wrapper().attr('aria-valuemin'), -5, 'aria-valuemin');
equals(wrapper().attr('aria-valuemax'), 5, 'aria-valuemax');
equals(wrapper().attr('aria-valuenow'), 2, 'aria-valuenow');
el.spinner('stepUp');
equals(wrapper().attr('aria-valuenow'), 3, 'stepUp 1 step changes aria-valuenow');
el.spinner('option', { min: -10, max: 10 });
equals(wrapper().attr('aria-valuemin'), -10, 'min option changed aria-valuemin changes');
equals(wrapper().attr('aria-valuemax'), 10, 'max option changed aria-valuemax changes');
});
})(jQuery);

View File

@ -0,0 +1,26 @@
/*
* spinner_defaults.js
*/
var spinner_defaults = {
buttons: 'show',
currency: false,
dir: 'ltr',
disabled: false,
groupSeparator: '',
incremental: true,
max: null,
min: null,
mouseWheel: true,
padding: 0,
page: 5,
precision: 0,
radix: 10,
radixPoint: '.',
spinnerClass: null,
step: null,
value: 0,
width: false
};
commonWidgetTests('spinner', { defaults: spinner_defaults });

View File

@ -0,0 +1,72 @@
/*
* spinner_events.js
*/
(function($) {
module("spinner: events");
test("start", function() {
expect(1);
var start = 0;
el = $("#spin").spinner({
start: function(){
start++;
}
});
simulateKeyDownUp(el, $.ui.keyCode.UP);
equals(start, 1, "Start triggered");
});
test("spin", function() {
expect(1);
var spin = 0;
el = $("#spin").spinner({
spin: function(){
spin++;
}
});
simulateKeyDownUp(el, $.ui.keyCode.UP);
equals(spin, 1, "Spin triggered");
});
test("stop", function() {
expect(1);
var stop = 0;
el = $("#spin").spinner({
stop: function(){
stop++;
}
});
simulateKeyDownUp(el, $.ui.keyCode.DOWN);
equals(stop, 1, "Stop triggered");
});
test("change", function() {
expect(1);
var start = spin = stop = change = 0;
el = $("#spin").spinner({
change: function(){
change++;
}
});
simulateKeyDownUp(el, $.ui.keyCode.UP);
equals(change, 1, "Change triggered");
});
})(jQuery);

View File

@ -0,0 +1,184 @@
/*
* spinner_methods.js
*/
(function($) {
module("spinner: methods");
test("disable", function() {
expect(14);
el = $("#spin").spinner({ disabled: false });
var val = el.val();
ok(!wrapper().hasClass(".ui-spinner-disabled"), "before: wrapper does not have ui-spinner-disabled class");
ok(!box().is(':disabled'), "before: input does not have disabled attribute");
el.spinner("disable");
ok(wrapper().hasClass(".ui-spinner-disabled"), "after: wrapper has ui-spinner-disabled class");
ok(box().is(':disabled'), "after: input has disabled attribute");
simulateKeyDownUp(el, $.ui.keyCode.UP);
equals(val, el.val(), "keyboard - value does not change on key UP");
simulateKeyDownUp(el, $.ui.keyCode.DOWN);
equals(val, el.val(), "keyboard - value does not change on key DOWN");
simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);
equals(val, el.val(), "keyboard - value does not change on key PGUP");
simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);
equals(val, el.val(), "keyboard - value does not change on key PGDN");
upButton().trigger('mousedown').trigger('mouseup');
equals(val, el.val(), "mouse - value does not change on clicking up button");
downButton().trigger('mousedown').trigger('mouseup');
equals(val, el.val(), "mouse - value does not change on clicking down button");
el.spinner('stepUp', 6);
equals(6, el.val(), "script - stepUp 6 steps changes value");
el.spinner('stepDown');
equals(5, el.val(), "script - stepDown 1 step changes value");
el.spinner('pageUp');
equals(10, el.val(), "script - pageUp 1 page changes value");
el.spinner('pageDown');
equals(5, el.val(), "script - pageDown 1 page changes value");
});
test("enable", function() {
expect(14);
el = $("#spin").spinner({ disabled: true });
var val = el.val();
ok(wrapper().hasClass(".ui-spinner-disabled"), "before: wrapper has ui-spinner-disabled class");
ok(box().is(':disabled'), "before: input has disabled attribute");
el.spinner("enable");
ok(!wrapper().hasClass(".ui-spinner-disabled"), "after: wrapper does not have ui-spinner-disabled class");
ok(!box().is(':disabled'), "after: input does not have disabled attribute");
simulateKeyDownUp(el, $.ui.keyCode.UP);
equals(1, el.val(), "keyboard - value changes on key UP");
simulateKeyDownUp(el, $.ui.keyCode.DOWN);
equals(0, el.val(), "keyboard - value changes on key DOWN");
simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);
equals(5, el.val(), "keyboard - value changes on key PGUP");
simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);
equals(0, el.val(), "keyboard - value changes on key PGDN");
upButton().trigger('mousedown').trigger('mouseup');
equals(1, el.val(), "mouse - value changes on clicking up button");
downButton().trigger('mousedown').trigger('mouseup');
equals(0, el.val(), "mouse - value changes on clicking down button");
el.spinner('stepUp', 6);
equals(6, el.val(), "script - stepUp 6 steps changes value");
el.spinner('stepDown');
equals(5, el.val(), "script - stepDown 1 step changes value");
el.spinner('pageUp');
equals(10, el.val(), "script - pageUp 1 page changes value");
el.spinner('pageDown');
equals(5, el.val(), "script - pageDown 1 page changes value");
});
test("pageDown", function() {
expect(4);
el = $('#spin').spinner({ step: 2, page: 5, value: 0, min: -100 });
el.spinner('pageDown');
equals(el.val(), -10, "pageDown 1 page");
el.spinner('pageDown', 3);
equals(el.val(), -40, "pageDown 3 pages");
el.val(-91).spinner('pageDown');
equals(el.val(), -100, "value close to min and pageDown 1 page");
el.spinner('pageDown', 10);
equals(el.val(), -100, "value at min and pageDown 10 pages");
});
test("pageUp", function() {
expect(4);
el = $('#spin').spinner({ step: 2, page: 5, value: 0, max: 100 });
el.spinner('pageUp');
equals(el.val(), 10, "pageUp 1 page");
el.spinner('pageUp', 3);
equals(el.val(), 40, "pageUp 3 pages");
el.val(91).spinner('pageUp');
equals(el.val(), 100, "value close to max and pageUp 1 page");
el.spinner('pageUp', 10);
equals(el.val(), 100, "value at max and pageUp 10 pages");
});
test("stepDown", function() {
expect(4);
el = $('#spin').spinner({ step: 2, page: 5, value: 0, min: -15 });
el.spinner('stepDown')
equals(el.val(), -2, "stepDown 1 step");
el.spinner('stepDown', 5)
equals(el.val(), -12, "stepDown 5 steps");
el.spinner('stepDown', 3);
equals(el.val(), -15, "close to min and stepDown 3 steps");
el.spinner('stepDown');
equals(el.val(), -15, "at min and stepDown 1 step");
});
test("stepUp", function() {
expect(4);
el = $('#spin').spinner({ step: 2, page: 5, value: 0, max: 15 });
el.spinner('stepUp')
equals(el.val(), 2, "stepUp 1 steps");
el.spinner('stepUp', 5)
equals(el.val(), 12, "stepUp 5 steps");
el.spinner('stepUp', 3);
equals(el.val(), 15, "close to min and stepUp 3 steps");
el.spinner('stepUp');
equals(el.val(), 15, "at min and stepUp 1 step");
});
test("value", function() {
expect(2);
el = $('#spin').spinner({ value: 0 });
el.spinner('value', 10);
equals(el.val(), 10, "change value via value method");
equals(10, el.spinner('value'), "get value via value method");
});
})(jQuery);

View File

@ -0,0 +1,482 @@
/*
* spinner_options.js
*/
(function($) {
module("spinner: options");
test("buttons - show (default)", function() {
expect(4);
el = $('#spin');
el.spinner({
buttons: 'show'
});
ok(upButton().is(':visible'), "show - before hover: up button visible");
ok(downButton().is(':visible'), "show - before hover: down button visible");
el.trigger('mouseover');
ok(upButton().is(':visible'), "show - after hover: up button visible");
ok(downButton().is(':visible'), "show - after hover: down button visible");
el.trigger('mouseout');
});
test("buttons - hide", function() {
expect(4);
el = $('#spin');
el.spinner({
buttons: 'hide'
});
ok(upButton().is(':hidden'), "hide - before hover: up button hidden");
ok(downButton().is(':hidden'), "hide - before hover: down button hidden");
el.trigger('mouseover');
ok(upButton().is(':hidden'), "hide - after hover: up button hidden");
ok(downButton().is(':hidden'), "hide - after hover: down button hidden");
el.trigger('mouseout');
});
test("buttons - auto (hover)", function() {
expect(4);
el = $('#spin');
el.spinner({
buttons: 'auto'
});
ok(upButton().is(':hidden'), "auto - before hover: up button hidden");
ok(downButton().is(':hidden'), "auto - before hover: down button hidden");
el.trigger('mouseover');
ok(upButton().is(':visible'), "auto - after hover: up button visible");
ok(downButton().is(':visible'), "auto - after hover: down button visible");
el.trigger('mouseout');
});
test("buttons - auto (focus)", function() {
expect(4);
el = $('#spin');
el.spinner({
buttons: 'auto'
});
ok(upButton().is(':hidden'), "auto - before focus: up button hidden");
ok(downButton().is(':hidden'), "auto - before focus: down button hidden");
el.focus();
ok(upButton().is(':visible'), "auto - after focus: up button visible");
ok(downButton().is(':visible'), "auto - after focus: down button visible");
el.trigger('mouseout');
});
test("currency - single character currency symbol", function() {
expect(5);
el = $("#spin");
options = {
currency:"$",
max:120,
min:-50,
step:0.3
};
el.spinner(options);
equals(el.val(), "$0.00", "start number");
simulateKeyDownUp(el, $.ui.keyCode.UP);
equals(el.val(), "$0.30", "stepping 0.30");
simulateKeyDownUp(el, $.ui.keyCode.END);
equals(el.val(), "$120.00", "End key to max");
simulateKeyDownUp(el, $.ui.keyCode.HOME);
equals(el.val(), "-$50.00", "Home key to min");
for ( var i = 1 ; i<=120 ; i++ ) {
simulateKeyDownUp(el, $.ui.keyCode.UP);
}
equals(el.val(), "-$14.00", "keydown 120 times");
});
test("currency - combined character currency symbol", function() {
expect(2);
el = $('#spin');
options = {
currency: 'HK$',
step: 1500.50,
value: 1000
}
el.spinner(options);
equals(el.val(), "HK$1,000.00", "Hong Kong Dollar");
simulateKeyDownUp(el, $.ui.keyCode.UP);
equals(el.val(), "HK$2,500.50", "Hong Kong Dollar step-up once");
});
test("currency - space as group separator", function() {
expect(2);
el = $('#spin');
options = {
currency: '$',
groupSeparator: ' ',
radixPoint: '.',
step: 1500.50,
value: 1000
}
el.spinner(options);
equals(el.val(), "$1 000.00", "Australian Dollar");
simulateKeyDownUp(el, $.ui.keyCode.UP);
equals(el.val(), "$2 500.50", "Australian Dollar step-up once");
});
test("currency - apos as group separator", function() {
expect(2);
el = $('#spin');
options = {
currency: 'Fr ',
groupSeparator: "'",
radixPoint: '.',
step: 1500.50,
value: 1000
}
el.spinner(options);
equals(el.val(), "Fr 1'000.00", "Swiss Franc");
simulateKeyDownUp(el, $.ui.keyCode.UP);
equals(el.val(), "Fr 2'500.50", "Swiss Franc step-up once");
});
test("currency - period as group separator and comma as radixPoint", function() {
expect(2);
el = $('#spin');
options = {
currency: 'RUB',
groupSeparator: ".",
radixPoint: ',',
step: 1.5,
value: 1000
}
el.spinner(options);
equals(el.val(), "RUB1.000,00", "Russian Ruble");
simulateKeyDownUp(el, $.ui.keyCode.UP);
equals(el.val(), "RUB1.001,50", "Russian Ruble step-up once");
});
test("dir - left-to-right (default)", function() {
expect(3);
el = $("#spin");
el.spinner();
ok(upButton().position().left > box().position().left, 'input on left up button on right');
ok(downButton().position().left > box().position().left, 'input on left down button on right');
ok(wrapper().hasClass('ui-spinner-ltr'), 'container has correct text direction class setting');
});
test("dir - right-to-left", function() {
expect(3);
el = $("#spin");
el.spinner({ dir: 'rtl' });
ok(upButton().position().left < box().position().left, 'input on right up button on left');
ok(downButton().position().left < box().position().left, 'input on right down button on left');
ok(wrapper().hasClass('ui-spinner-rtl'), 'container has correct text direction class setting');
});
test("groupSeparator - comma separator (default)", function() {
expect(1);
el = $('#spin');
options = {
groupSeparator: ',',
value: 1000000
};
el.spinner(options);
equals(el.val(), "1,000,000", "value contains 2 commas separated by 3 digits");
});
test("groupSeparator - space separator", function() {
expect(1);
el = $('#spin');
options = {
groupSeparator: ' ',
value: 1000000
};
el.spinner(options);
equals(el.val(), "1 000 000", "value contains 2 spaces separated by 3 digits");
});
test("groupSeparator - apos separator", function() {
expect(1);
el = $('#spin');
options = {
groupSeparator: "'",
value: 1000000
};
el.spinner(options);
equals(el.val(), "1'000'000", "value contains apos separated by 3 digits");
});
test("incremental - false (default)", function() {
expect(2);
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", function() {
expect(2);
el.spinner('option', 'incremental', true );
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);
el = $("#spin").spinner({ max: 100, value: 1000 });
equals(el.val(), 100, "max constrained if value option is greater");
el.spinner('value', 1000);
equals(el.val(), 100, "max constrained if value method is greater");
el.val(1000).blur();
equals(el.val(), 100, "max constrained if manual entry");
});
test("min", function() {
expect(3);
el = $("#spin").spinner({ min: -100, value: -1000 });
equals(el.val(), -100, "min constrained if value option is greater");
el.spinner('value', -1000);
equals(el.val(), -100, "min constrained if value method is greater");
el.val(-1000).blur();
equals(el.val(), -100, "min constrained if manual entry");
});
test("mouseWheel", function() {
ok(false, 'missing test - untested code is broken code');
});
test("padding", function() {
expect(3);
el = $('#spin').spinner({ padding: 5, value: 10 });
equals(el.val(), '00010', 'padded output');
el.spinner('option', 'padding', 4);
equals(el.val(), '0010', 'padded output');
el.spinner('value', 15);
equals(el.val(), '0015', 'padded output');
});
test("page", function() {
expect(3);
el = $("#spin").spinner({ step: 2, page:2.5 });
equals(el.val(), "0", "start number");
simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);
equals(el.val(), "-5", "PAGE_DOWN on spinner once");
for ( var i = 1 ; i<=11 ; i++ ) {
simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);
}
equals(el.val(), "50", "PAGE_UP 11 times on spinner");
});
test("precision", function() {
expect(3);
el = $("#spin").spinner({ precision: 4, value: 1.23456789 });
equals(el.val(), '1.2346', "4 decimal places");
el.spinner('option', 'precision', 2);
equals(el.val(), '1.23', "2 decimal places");
el.spinner('option', 'precision', 6);
equals(el.val(), '1.234568', "6 decimal places");
});
test("radix", function() {
expect(2);
el = $("#spin").spinner({
radix: 16,
value: 10
});
equals(el.val(), 'a', 'start value');
simulateKeyDownUp(el, $.ui.keyCode.UP);
equals(el.val(), 'b', 'key UP on spinner')
});
test("radixPoint", function() {
el = $("#spin").spinner({
radixPoint: ',',
value: 20.00,
precision: 2
});
equals(el.val(), '20,00', 'comma radix point');
el.spinner('stepUp');
equals(el.val(), '21,00', 'step up one');
el.spinner('pageDown', 10);
equals(el.val(), '-29,00', 'page down into negative space');
});
test("spinnerClass", function() {
expect(3);
el = $('#spin').spinner({spinnerClass: 'my-spinner-class'});
ok(wrapper().hasClass('my-spinner-class'), 'spinner container has custom class');
el.spinner('option', 'spinnerClass', 'new-spinner-class');
ok(!wrapper().hasClass('my-spinner-class'), 'spinner no longer has old custom class');
ok(wrapper().hasClass('new-spinner-class'), 'spinner now has new custom class');
});
test("step", function() {
expect(7);
el = $("#spin").spinner({ step:0.7 });
equals(el.val(), "0.0", "value initialized to");
simulateKeyDownUp(el, $.ui.keyCode.DOWN);
equals(el.val(), "-0.7", "DOWN 1 time with step: 0.7");
for ( var i = 0 ; i < 11 ; i++ ) {
simulateKeyDownUp(el, $.ui.keyCode.UP);
}
equals(el.val(), "7.0", "UP 11 times with step: 0.7");
el.spinner('option', 'step', 1);
for ( var i = 0 ; i < 3 ; i++ ) {
simulateKeyDownUp(el, $.ui.keyCode.UP);
}
equals(el.val(), "10.0", "UP 3 times with step: 1");
el.spinner('option', 'step', 2);
for ( var i = 0 ; i < 5 ; i++ ) {
simulateKeyDownUp(el, $.ui.keyCode.UP);
}
equals(el.val(), "20.0", "UP 5 times with step: 2");
el.spinner('value', '10.5');
equals(el.val(), "10.5", "value reset to");
el.spinner('option', 'step', 2);
for ( var i = 0 ; i < 5 ; i++ ) {
simulateKeyDownUp(el, $.ui.keyCode.UP);
}
equals(el.val(), "20.5", "UP 5 times with step: 2");
});
test("value", function() {
expect(2);
el = $('#spin').spinner({ value: 100 });
equals(el.val(), 100, "starting value");
el.spinner('option', 'value', 1000);
equals(el.val(), 1000, "value option changed and set as current value");
});
test("width", function() {
expect(2);
el = $('#spin').spinner({ width: 1000 });
equals(el.width(), 1000, "spinner width initialized");
el.spinner('option', 'width', 500);
equals(el.width(), 500, "spinner width changed");
});
})(jQuery);