Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/185093
Change subject: Add tests for rendering of thanks button on mobile diff page
......................................................................
Add tests for rendering of thanks button on mobile diff page
This has broken many times and I want this test to ensure its protection
in future.
Bug: T86687
Change-Id: Iea01c5c7c1ba00de47182521eeba86c8aef03522
---
M Thanks.hooks.php
M Thanks.php
M modules/ext.thanks.mobilediff.js
A tests/qunit/test_ext.thanks.mobilediff.js
4 files changed, 60 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Thanks
refs/changes/93/185093/1
diff --git a/Thanks.hooks.php b/Thanks.hooks.php
index 1f46164..c720c02 100644
--- a/Thanks.hooks.php
+++ b/Thanks.hooks.php
@@ -8,6 +8,31 @@
class ThanksHooks {
/**
+ * ResourceLoaderTestModules hook handler
+ * @see
https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules
+ *
+ * @param array $testModules
+ * @param ResourceLoader $resourceLoader
+ * @return bool
+ */
+ public static function onResourceLoaderTestModules( array &$testModules,
+ ResourceLoader &$resourceLoader
+ ) {
+ if ( class_exists( 'SpecialMobileDiff' ) ) {
+ $testModules['qunit']['tests.ext.thanks.mobilediff'] =
array(
+ 'localBasePath' => __DIR__,
+ 'remoteExtPath' => 'Thanks',
+ 'dependencies' => array(
'ext.thanks.mobilediff' ),
+ 'scripts' => array(
+
'tests/qunit/test_ext.thanks.mobilediff.js',
+ ),
+ 'targets' => array( 'desktop', 'mobile' ),
+ );
+ }
+ return true;
+ }
+
+ /**
* Handler for HistoryRevisionTools and DiffRevisionTools hooks.
* Inserts 'thank' link into revision interface
* @param $rev Revision object to add the thank link for
diff --git a/Thanks.php b/Thanks.php
index 234c290..add8fbf 100644
--- a/Thanks.php
+++ b/Thanks.php
@@ -75,6 +75,7 @@
$wgHooks['UnitTestsList'][] = 'ThanksHooks::registerUnitTests';
$wgHooks['GetLogTypesOnUser'][] = 'ThanksHooks::onGetLogTypesOnUser';
$wgHooks['BeforePageDisplay'][] = 'ThanksHooks::onBeforePageDisplay';
+$wgHooks['ResourceLoaderTestModules'][] =
'ThanksHooks::onResourceLoaderTestModules';
// Register modules
$wgResourceModules['ext.thanks'] = array(
diff --git a/modules/ext.thanks.mobilediff.js b/modules/ext.thanks.mobilediff.js
index 7e3e3c8..1629ec0 100644
--- a/modules/ext.thanks.mobilediff.js
+++ b/modules/ext.thanks.mobilediff.js
@@ -74,9 +74,8 @@
}
}
- $( function() {
- var $user = $( '.mw-mf-user' ),
- username = $user.data( 'user-name' ),
+ function init( $user, $container ) {
+ var username = $user.data( 'user-name' ),
rev = $user.data( 'revision-id' ),
gender = $user.data( 'user-gender' ),
$thankBtn;
@@ -84,8 +83,17 @@
if ( !$user.hasClass( 'mw-mf-anon' ) ) {
$thankBtn = createThankLink( username, rev, gender );
if ( $thankBtn ) {
- $thankBtn.prependTo( '#mw-mf-userinfo' );
+ $thankBtn.prependTo( $container );
}
}
+ }
+
+ $( function () {
+ init( $( '.mw-mf-user' ), $( '#mw-mf-userinfo' ) );
+ } );
+
+ // Expose for testing purposes
+ mw.extThanks = $.extend( {}, mw.extThanks || {}, {
+ _mobileDiffInit: init
} );
} )( mw.mobileFrontend, jQuery );
diff --git a/tests/qunit/test_ext.thanks.mobilediff.js
b/tests/qunit/test_ext.thanks.mobilediff.js
new file mode 100644
index 0000000..9a92653
--- /dev/null
+++ b/tests/qunit/test_ext.thanks.mobilediff.js
@@ -0,0 +1,22 @@
+( function ( $ ) {
+ QUnit.module( 'Thanks mobilediff' );
+
+ QUnit.test( 'render button for logged in users', 1, function ( assert )
{
+ var $container = $( '<div>' ),
+ $user = $( '<div>' ).data( 'user-name', 'jon' )
+ .data( 'revision-id', 1 )
+ .data( 'user-gender', 'male' );
+
+ mw.extThanks._mobileDiffInit( $user, $container );
+ assert.strictEqual( $container.find( 'button' ).length, 1,
'Thanks button was created.' );
+ } );
+
+ QUnit.test( 'render button for anon users', 1, function ( assert ) {
+ var $container = $( '<div>' ),
+ $user = $( '<div class="mw-mf-anon">' );
+
+ mw.extThanks._mobileDiffInit( $user, $container );
+ assert.strictEqual( $container.find( 'button' ).length, 0, 'No
thanks button was created.' );
+ } );
+
+}( jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/185093
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iea01c5c7c1ba00de47182521eeba86c8aef03522
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Thanks
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits