aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2025-03-18 11:45:00 +0100
committerGitHub <noreply@github.com>2025-03-18 11:45:00 +0100
commit6843ced12e4051aefbee47cf87fa79794737eb8a (patch)
tree267c0ae0d63a7b607c408a9223795c020ba4f74d /tests
parentef28a5f57036e32a66e6d469e345d7376ecdaffc (diff)
downloadjquery-ui-6843ced12e4051aefbee47cf87fa79794737eb8a.tar.gz
jquery-ui-6843ced12e4051aefbee47cf87fa79794737eb8a.zip
Spinner: Drop dependency on jQuery Mousewheel
1. Listen to the native `wheel` event without depending on any wrapper plugins. 2. Keep listening to the `mousewheel` event for compatibility with projects using the jQuery Mousewheel plugin but route it to the `wheel` handler. Closes gh-2338
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/spinner/core.js42
1 files changed, 41 insertions, 1 deletions
diff --git a/tests/unit/spinner/core.js b/tests/unit/spinner/core.js
index e9f7bc3d2..befe439f6 100644
--- a/tests/unit/spinner/core.js
+++ b/tests/unit/spinner/core.js
@@ -163,7 +163,47 @@ QUnit.test( "mouse click on up button, increases value not greater than max", fu
assert.equal( element.val(), 0 );
} );
-QUnit.test( "mousewheel on input", function( assert ) {
+QUnit.test( "wheel on input", function( assert ) {
+ var ready = assert.async();
+ assert.expect( 5 );
+
+ var element = $( "#spin" ).val( 0 ).spinner( {
+ step: 2
+ } );
+
+ element.simulate( "focus" );
+ setTimeout( step1 );
+
+ function getWheelEvent( deltaY ) {
+ return jQuery.Event( new WheelEvent( "wheel", { deltaY: deltaY } ) );
+ }
+
+ function step1() {
+ element.trigger( getWheelEvent() );
+ assert.equal( element.val(), 0, "wheel event without delta does not change value" );
+
+ element.trigger( getWheelEvent( -1 ) );
+ assert.equal( element.val(), 2, "delta -1" );
+
+ element.trigger( getWheelEvent( 0.2 ) );
+ assert.equal( element.val(), 0, "delta 0.2" );
+
+ element.trigger( getWheelEvent( 15 ) );
+ assert.equal( element.val(), -2, "delta 15" );
+
+ element.simulate( "blur" );
+ setTimeout( step2 );
+ }
+
+ function step2() {
+ element.trigger( "wheel", -1 );
+ assert.equal( element.val(), -2, "wheel when not focused" );
+
+ ready();
+ }
+} );
+
+QUnit.test( "mousewheel on input (DEPRECATED)", function( assert ) {
var ready = assert.async();
assert.expect( 5 );