aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/core/core.html3
-rw-r--r--tests/unit/core/selector.js8
-rw-r--r--tests/unit/spinner/spinner_core.js51
-rw-r--r--tests/unit/spinner/spinner_defaults.js1
-rw-r--r--tests/unit/spinner/spinner_events.js6
-rw-r--r--tests/unit/spinner/spinner_methods.js16
-rw-r--r--tests/unit/spinner/spinner_options.js57
-rw-r--r--tests/unit/tabs/tabs_core.js2
-rw-r--r--tests/unit/widget/widget_core.js30
9 files changed, 97 insertions, 77 deletions
diff --git a/tests/unit/core/core.html b/tests/unit/core/core.html
index fdde81766..e2d988806 100644
--- a/tests/unit/core/core.html
+++ b/tests/unit/core/core.html
@@ -46,6 +46,9 @@
<area shape="rect" coords="1,1,2,2" href="foo.html" id="areaNoImg">
</map>
+<form id="formNoTabindex"></form>
+<form id="formTabindex" tabindex="1"></form>
+
<div>
<input id="visibleAncestor-inputTypeNone">
<input type="text" id="visibleAncestor-inputTypeText">
diff --git a/tests/unit/core/selector.js b/tests/unit/core/selector.js
index de5be3da1..2fb78025c 100644
--- a/tests/unit/core/selector.js
+++ b/tests/unit/core/selector.js
@@ -79,8 +79,10 @@ test("data", function() {
});
test("focusable - visible, enabled elements", function() {
- expect(16);
+ expect(18);
+ isNotFocusable('#formNoTabindex', 'form');
+ isFocusable('#formTabindex', 'form with tabindex');
isFocusable('#visibleAncestor-inputTypeNone', 'input, no type');
isFocusable('#visibleAncestor-inputTypeText', 'input, type text');
isFocusable('#visibleAncestor-inputTypeCheckbox', 'input, type checkbox');
@@ -156,8 +158,10 @@ test("focusable - area elements", function() {
});
test("tabbable - visible, enabled elements", function() {
- expect(16);
+ expect(18);
+ isNotTabbable('#formNoTabindex', 'form');
+ isTabbable('#formTabindex', 'form with tabindex');
isTabbable('#visibleAncestor-inputTypeNone', 'input, no type');
isTabbable('#visibleAncestor-inputTypeText', 'input, type text');
isTabbable('#visibleAncestor-inputTypeCheckbox', 'input, type checkbox');
diff --git a/tests/unit/spinner/spinner_core.js b/tests/unit/spinner/spinner_core.js
index 55b806a7f..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,4 +176,26 @@ 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" ).val( .05 ).spinner({
+ step: .0001
+ });
+ element.spinner( "stepUp" );
+ equal( element.val(), "0.0501", "precision from step" );
+
+ element.val( 1.05 ).spinner( "option", {
+ step: 1
+ });
+ element.spinner( "stepDown" );
+ equal( element.val(), "0.05", "precision from value" );
+});
+
})( jQuery );
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 );
diff --git a/tests/unit/tabs/tabs_core.js b/tests/unit/tabs/tabs_core.js
index 98cb617ec..e7c1ee576 100644
--- a/tests/unit/tabs/tabs_core.js
+++ b/tests/unit/tabs/tabs_core.js
@@ -48,7 +48,7 @@ test( "aria-controls", function() {
tabs = element.find( ".ui-tabs-nav a" );
tabs.each(function() {
var tab = $( this );
- equal( tab.attr( "href" ).substring( 1 ), tab.attr( "aria-controls" ) );
+ equal( tab.prop( "hash" ).substring( 1 ), tab.attr( "aria-controls" ) );
});
element = $( "#tabs2" ).tabs();
diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js
index 8cacdd47d..41ae8ffb4 100644
--- a/tests/unit/widget/widget_core.js
+++ b/tests/unit/widget/widget_core.js
@@ -673,23 +673,31 @@ test( "_bind() with delegate", function() {
this.element = {
bind: function( event, handler ) {
equal( event, "click.testWidget" );
- ok( $.isFunction(handler) );
- },
- delegate: function( selector, event, handler ) {
- equal( selector, "a" );
- equal( event, "click.testWidget" );
- ok( $.isFunction(handler) );
+ ok( $.isFunction(handler) );
},
trigger: $.noop
};
+ this.widget = function() {
+ return {
+ delegate: function( selector, event, handler ) {
+ equal( selector, "a" );
+ equal( event, "click.testWidget" );
+ ok( $.isFunction(handler) );
+ }
+ };
+ };
this._bind({
"click": "handler",
- "click a": "handler",
+ "click a": "handler"
});
- this.element.delegate = function( selector, event, handler ) {
- equal( selector, "form fieldset > input" );
- equal( event, "change.testWidget" );
- ok( $.isFunction(handler) );
+ this.widget = function() {
+ return {
+ delegate: function( selector, event, handler ) {
+ equal( selector, "form fieldset > input" );
+ equal( event, "change.testWidget" );
+ ok( $.isFunction(handler) );
+ }
+ };
};
this._bind({
"change form fieldset > input": "handler"