Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Spinner tests: Don't pollute the global namespace with helpers.

  • Loading branch information...
commit d62d9d4eff764220be9696acc7ffe8bf0d24c570 1 parent e9d5079
@scottgonzalez scottgonzalez authored
View
1  grunt.js
@@ -383,7 +383,6 @@ grunt.initConfig({
shouldnotmove: true,
shouldnotresize: true,
shouldresize: true,
- spinner_simulateKeyDownUp: true,
start: true,
strictEqual: true,
stop: true,
View
42 tests/unit/spinner/spinner_core.js
@@ -1,5 +1,7 @@
(function( $ ) {
+var simulateKeyDownUp = TestHelpers.spinner.simulateKeyDownUp;
+
module( "spinner: core" );
test( "keydown UP on input, increases value not greater than max", function() {
@@ -9,15 +11,15 @@ test( "keydown UP on input, increases value not greater than max", function() {
step: 10
});
- spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
equal( element.val(), 80 );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
equal( element.val(), 90 );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
equal( element.val(), 100 );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
equal( element.val(), 100 );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
equal( element.val(), 100 );
});
@@ -28,15 +30,15 @@ test( "keydown DOWN on input, decreases value not less than min", function() {
step: 10
});
- spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
equal( element.val(), 40 );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
equal( element.val(), 30 );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
equal( element.val(), 20 );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
equal( element.val(), 20 );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
equal( element.val(), 20 );
});
@@ -47,15 +49,15 @@ test( "keydown PAGE_UP on input, increases value not greater than max", function
page: 10
});
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
equal( element.val(), 80 );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
equal( element.val(), 90 );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
equal( element.val(), 100 );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
equal( element.val(), 100 );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
equal( element.val(), 100 );
});
@@ -66,15 +68,15 @@ test( "keydown PAGE_DOWN on input, decreases value not less than min", function(
page: 10
});
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
equal( element.val(), 40 );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
equal( element.val(), 30 );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
equal( element.val(), 20 );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
equal( element.val(), 20 );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
equal( element.val(), 20 );
});
View
52 tests/unit/spinner/spinner_events.js
@@ -1,5 +1,7 @@
(function( $ ) {
+var simulateKeyDownUp = TestHelpers.spinner.simulateKeyDownUp;
+
module( "spinner: events" );
test( "start", function() {
@@ -13,14 +15,14 @@ test( "start", function() {
}
shouldStart( true, "key UP" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
shouldStart( true, "key DOWN" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
shouldStart( true, "key PAGE_UP" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
shouldStart( true, "key PAGE_DOWN" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
shouldStart( true, "button up" );
element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup();
@@ -52,14 +54,14 @@ test( "spin", function() {
}
shouldSpin( true, "key UP" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
shouldSpin( true, "key DOWN" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
shouldSpin( true, "key PAGE_UP" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
shouldSpin( true, "key PAGE_DOWN" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
shouldSpin( true, "button up" );
element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup();
@@ -91,14 +93,14 @@ test( "stop", function() {
}
shouldStop( true, "key UP" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
shouldStop( true, "key DOWN" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
shouldStop( true, "key PAGE_UP" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
shouldStop( true, "key PAGE_DOWN" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
shouldStop( true, "button up" );
element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup();
@@ -131,42 +133,42 @@ test( "change", function() {
element.focus();
shouldChange( false, "key UP, before blur" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ 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 );
+ 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 );
+ 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 );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
shouldChange( true, "blur after key PAGE_DOWN" );
element.blur();
shouldChange( false, "many keys, before blur" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
shouldChange( true, "blur after many keys" );
element.blur();
shouldChange( false, "many keys, same final value, before blur" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
shouldChange( false, "blur after many keys, same final value" );
shouldChange( false, "button up, before blur" );
View
12 tests/unit/spinner/spinner_methods.js
@@ -1,5 +1,7 @@
(function( $ ) {
+var simulateKeyDownUp = TestHelpers.spinner.simulateKeyDownUp;
+
module( "spinner: methods" );
test( "destroy", function() {
@@ -21,16 +23,16 @@ test( "disable", function() {
ok( wrapper.hasClass( "ui-spinner-disabled" ), "after: wrapper has ui-spinner-disabled class" );
ok( element.is( ":disabled"), "after: input has disabled attribute" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
equal( 2, element.val(), "keyboard - value does not change on key UP" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
equal( 2, element.val(), "keyboard - value does not change on key DOWN" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
equal( 2, element.val(), "keyboard - value does not change on key PGUP" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
equal( 2, element.val(), "keyboard - value does not change on key PGDN" );
wrapper.find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" );
@@ -65,7 +67,7 @@ test( "enable", function() {
ok( !wrapper.hasClass( ".ui-spinner-disabled" ), "after: wrapper does not have ui-spinner-disabled class" );
ok( !element.is( ":disabled" ), "after: input does not have disabled attribute" );
- spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
equal( 2, element.val(), "keyboard - value changes on key UP" );
});
View
2  tests/unit/spinner/spinner_options.js
@@ -1,5 +1,7 @@
(function( $ ) {
+var simulateKeyDownUp = TestHelpers.spinner.simulateKeyDownUp;
+
module( "spinner: options" );
// culture is tested after numberFormat, since it depends on numberFormat
View
11 tests/unit/spinner/spinner_test_helpers.js
@@ -1,5 +1,8 @@
-var spinner_simulateKeyDownUp = function( element, keyCode, shift ) {
- element
- .simulate( "keydown", { keyCode: keyCode, shiftKey: shift || false } )
- .simulate( "keyup", { keyCode: keyCode, shiftKey: shift || false } );
+TestHelpers.spinner = {
+ simulateKeyDownUp: function( element, keyCode, shift ) {
+ element
+ .simulate( "keydown", { keyCode: keyCode, shiftKey: shift || false } )
+ .simulate( "keyup", { keyCode: keyCode, shiftKey: shift || false } );
+ }
};
+
Please sign in to comment.
Something went wrong with that request. Please try again.