From 4f58bf230488393136b8e8fd8cdefde1eb80d8be Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Mon, 12 Aug 2019 21:12:47 -0400 Subject: [PATCH] Tests: Add qunitjs basic tests --- .eslintrc.js | 2 + package-lock.json | 57 ++++++++++ package.json | 3 +- test/.eslintrc.js | 7 ++ test/index.html | 276 +++++++--------------------------------------- test/manual.html | 239 +++++++++++++++++++++++++++++++++++++++ test/unit.js | 57 ++++++++++ 7 files changed, 401 insertions(+), 240 deletions(-) create mode 100644 test/.eslintrc.js create mode 100644 test/manual.html create mode 100644 test/unit.js diff --git a/.eslintrc.js b/.eslintrc.js index dcf5db97..9c965db3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,4 +1,6 @@ module.exports = { + root: true, + // Support: IE11 without transpilation "parserOptions": { "ecmaVersion": 5 diff --git a/package-lock.json b/package-lock.json index dfaa82fd..c8eb4488 100644 --- a/package-lock.json +++ b/package-lock.json @@ -631,6 +631,12 @@ "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.4.1.tgz", "integrity": "sha512-36+AdBzCL+y6qjw5Tx7HgzeGCzC81MDDgaUP8ld2zhx58HdqXGoBd+tHdrBMiyjGQs0Hxs/MLZTu/eHNJJuWPw==" }, + "js-reporters": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/js-reporters/-/js-reporters-1.2.1.tgz", + "integrity": "sha1-+IxgjjJKM3OpW8xFrTBeXJecRZs=", + "dev": true + }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -665,6 +671,15 @@ "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", "dev": true }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, "minimist": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", @@ -704,6 +719,12 @@ "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", "dev": true }, + "node-watch": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/node-watch/-/node-watch-0.6.0.tgz", + "integrity": "sha512-XAgTL05z75ptd7JSVejH1a2Dm1zmXYhuDr9l230Qk6Z7/7GPcnAs/UyJJ4ggsXSvWil8iOzwQLW0zuGUvHpG8g==", + "dev": true + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -771,6 +792,12 @@ "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", "dev": true }, + "path-parse": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "dev": true + }, "prelude-ls": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", @@ -789,12 +816,42 @@ "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", "dev": true }, + "qunit": { + "version": "2.9.2", + "resolved": "https://registry.npmjs.org/qunit/-/qunit-2.9.2.tgz", + "integrity": "sha512-wTOYHnioWHcx5wa85Wl15IE7D6zTZe2CQlsodS14yj7s2FZ3MviRnQluspBZsueIDEO7doiuzKlv05yfky1R7w==", + "dev": true, + "requires": { + "commander": "2.12.2", + "js-reporters": "1.2.1", + "minimatch": "3.0.4", + "node-watch": "0.6.0", + "resolve": "1.9.0" + }, + "dependencies": { + "commander": { + "version": "2.12.2", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.12.2.tgz", + "integrity": "sha512-BFnaq5ZOGcDN7FlrtBT4xxkgIToalIIxwjxLWVJ8bGTpe1LroqMiqQXdA7ygc7CRvaYS+9zfPGFnJqFSayx+AA==", + "dev": true + } + } + }, "regexpp": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz", "integrity": "sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==", "dev": true }, + "resolve": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.9.0.tgz", + "integrity": "sha512-TZNye00tI67lwYvzxCxHGjwTNlUV70io54/Ed4j6PscB8xVfuBJpRenI/o6dVk0cY0PYTY27AgCoGGxRnYuItQ==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + }, "resolve-from": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", diff --git a/package.json b/package.json index bc2890dd..b383158d 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "build": "npm run lint && npm run minify", "minify": "uglifyjs -m -c --comments /Copyright/ -o jquery.mousewheel.min.js -- jquery.mousewheel.js", "lint": "eslint jquery.mousewheel.js", - "test": "echo whoops" + "test": "echo Load test/index.html in a browser for now" }, "dependencies": { "jquery": ">=1.7.2" @@ -46,6 +46,7 @@ "devDependencies": { "eslint": "^6.1.0", "eslint-config-jquery": "^2.0.0", + "qunit": "^2.9.2", "uglify-js": "^3.6.0" } } diff --git a/test/.eslintrc.js b/test/.eslintrc.js new file mode 100644 index 00000000..bd751c7f --- /dev/null +++ b/test/.eslintrc.js @@ -0,0 +1,7 @@ +module.exports = { + "globals": { + "QUnit": "readonly" + }, + "rules": { + } +}; \ No newline at end of file diff --git a/test/index.html b/test/index.html index 0c683cf4..2e3344d8 100644 --- a/test/index.html +++ b/test/index.html @@ -1,239 +1,37 @@ - - - - - Testing mousewheel plugin - - - - - - - - -

jQuery mousewheel.js Test with jQuery

-

- - - - -
-

Test1

-

Test2

-

Test3

-

Test4

-
-

Test5

-
-

Test6

-

Test7

-
-
-
-
- -
- - + + + + + jQuery Mousewheel Unit Test + + + + + + + + + + +

Using jQuery (unknown)

+

Add ?v=1.8.3 or ?v=2.2.4.min to specify a jQuery version from code.jquery.com.

+

+ In addition to unit tests, run the + manual test and scrolling test + in all supported browsers. +

+ +
+ + + \ No newline at end of file diff --git a/test/manual.html b/test/manual.html new file mode 100644 index 00000000..0c683cf4 --- /dev/null +++ b/test/manual.html @@ -0,0 +1,239 @@ + + + + + Testing mousewheel plugin + + + + + + + + +

jQuery mousewheel.js Test with jQuery

+

+ + + + +
+

Test1

+

Test2

+

Test3

+

Test4

+
+

Test5

+
+

Test6

+

Test7

+
+
+
+
+ +
+ + diff --git a/test/unit.js b/test/unit.js new file mode 100644 index 00000000..6209cf60 --- /dev/null +++ b/test/unit.js @@ -0,0 +1,57 @@ +QUnit.module( "mousewheel" ); + +function makeWheelEvent( deltaX, deltaY ) { + var event = window.document.createEvent( "Event" ); + event.initEvent( "wheel", true, true ); + event.deltaX = deltaX; + event.deltaY = deltaY; + event.deltaMode = 0; + return event; +} + +QUnit.test( ".on() and .trigger()", function( assert ) { + assert.expect( 1 ); + + var markup = jQuery( "
wheelme
" ).appendTo( "body" ); + + markup.on( "mousewheel", function( e ) { + assert.ok( true, "triggered a mousewheel event on " + e.target.innerText ); + } ); + markup.trigger( "mousewheel" ); + + markup.remove(); +} ); + +QUnit.test( ".mousewheel() shorthand", function( assert ) { + assert.expect( 1 ); + + var markup = jQuery( "

wheelme

" ).appendTo( "body" ); + + markup.mousewheel( function( e ) { + assert.ok( true, "triggered a mousewheel event on " + e.target.innerText ); + } ); + markup.trigger( "mousewheel" ); + + markup.remove(); +} ); + +QUnit.test( "natively triggered events", function( assert ) { + assert.expect( 6 ); + + var markup = jQuery( "

wheelme

" ).appendTo( "body" ); + + markup.on( "mousewheel", function( e ) { + assert.ok( true, "triggered a mousewheel event on " + e.target.innerText ); + assert.ok( "deltaX" in e, "got a deltaX in the event" ); + assert.ok( !isNaN( parseFloat( e.deltaY ) ), "deltaY is a number: " + e.deltaY ); + } ); + + // First wheel event "calibrates" so we won't measure this one + var event1 = makeWheelEvent( 0, 2.2 ); + markup[ 0 ].dispatchEvent( event1 ); + + var event2 = makeWheelEvent( 0, 10.528 ); + markup[ 0 ].dispatchEvent( event2 ); + + markup.remove(); +} );