From d62d9d4eff764220be9696acc7ffe8bf0d24c570 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Scott=20Gonz=C3=A1lez?= Date: Thu, 19 Apr 2012 13:12:23 -0400 Subject: [PATCH] Spinner tests: Don't pollute the global namespace with helpers. --- grunt.js | 1 - tests/unit/spinner/spinner_core.js | 42 ++++++++--------- tests/unit/spinner/spinner_events.js | 52 +++++++++++----------- tests/unit/spinner/spinner_methods.js | 12 ++--- tests/unit/spinner/spinner_options.js | 2 + tests/unit/spinner/spinner_test_helpers.js | 11 +++-- 6 files changed, 65 insertions(+), 55 deletions(-) diff --git a/grunt.js b/grunt.js index 82e7fe1e8..d03acdca9 100644 --- a/grunt.js +++ b/grunt.js @@ -383,7 +383,6 @@ grunt.initConfig({ shouldnotmove: true, shouldnotresize: true, shouldresize: true, - spinner_simulateKeyDownUp: true, start: true, strictEqual: true, stop: true, diff --git a/tests/unit/spinner/spinner_core.js b/tests/unit/spinner/spinner_core.js index e38b467a3..a1179bb35 100644 --- a/tests/unit/spinner/spinner_core.js +++ b/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 ); }); diff --git a/tests/unit/spinner/spinner_events.js b/tests/unit/spinner/spinner_events.js index e43ba3365..133a8d5a2 100644 --- a/tests/unit/spinner/spinner_events.js +++ b/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" ); diff --git a/tests/unit/spinner/spinner_methods.js b/tests/unit/spinner/spinner_methods.js index 2cb3c849f..bafd949a7 100644 --- a/tests/unit/spinner/spinner_methods.js +++ b/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" ); }); diff --git a/tests/unit/spinner/spinner_options.js b/tests/unit/spinner/spinner_options.js index 6f5090d3a..e21852630 100644 --- a/tests/unit/spinner/spinner_options.js +++ b/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 diff --git a/tests/unit/spinner/spinner_test_helpers.js b/tests/unit/spinner/spinner_test_helpers.js index af555dbf2..2021e8f7a 100644 --- a/tests/unit/spinner/spinner_test_helpers.js +++ b/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 } ); + } }; + -- 2.39.5