jenkins-bot has submitted this change and it was merged.
Change subject: The first ever Echo QUnit tests
......................................................................
The first ever Echo QUnit tests
Also change coding conventions of Resources to allows use
array for scripts key.
Change-Id: I0c9f358ce3eb62adb07b68623e97c07993c9c45c
---
M Echo.php
M Hooks.php
M Resources.php
A tests/qunit/overlay/test_ext.echo.overlay.js
4 files changed, 125 insertions(+), 2 deletions(-)
Approvals:
Jdlrobson: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Echo.php b/Echo.php
index 02c92af..6e878ef 100644
--- a/Echo.php
+++ b/Echo.php
@@ -137,6 +137,7 @@
$wgHooks['MakeGlobalVariablesScript'][] =
'EchoHooks::makeGlobalVariablesScript';
$wgHooks['UnitTestsList'][] = 'EchoHooks::getUnitTests';
$wgHooks['ResourceLoaderRegisterModules'][] =
'EchoHooks::onResourceLoaderRegisterModules';
+$wgHooks['ResourceLoaderTestModules'][] =
'EchoHooks::onResourceLoaderTestModules';
$wgHooks['UserRights'][] = 'EchoHooks::onUserRights';
$wgHooks['UserLoadOptions'][] = 'EchoHooks::onUserLoadOptions';
$wgHooks['UserSaveOptions'][] = 'EchoHooks::onUserSaveOptions';
diff --git a/Hooks.php b/Hooks.php
index 8f98c58..8a4648c 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -35,6 +35,50 @@
}
/**
+ * 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
+ ) {
+ global $wgResourceModules;
+
+ $testModuleBoilerplate = array(
+ 'localBasePath' => __DIR__,
+ 'remoteExtPath' => 'Echo',
+ 'targets' => array( 'desktop', 'mobile' ),
+ );
+
+ // find test files for every RL module
+ $prefix = 'ext.echo';
+ foreach ( $wgResourceModules as $key => $module ) {
+ if ( substr( $key, 0, strlen( $prefix ) ) === $prefix
&& isset( $module['scripts'] ) ) {
+ $testFiles = array();
+ foreach ( $module['scripts'] as $script ) {
+ $testFile = 'tests/qunit/' . dirname(
$script ) . '/test_' . basename( $script );
+ // if a test file exists for a given JS
file, add it
+ if ( file_exists(
$testModuleBoilerplate['localBasePath'] . '/' . $testFile ) ) {
+ $testFiles[] = $testFile;
+ }
+ }
+ // if test files exist for given module, create
a corresponding test module
+ if ( count( $testFiles ) > 0 ) {
+ $testModules['qunit']["$key.tests"] =
$testModuleBoilerplate + array(
+ 'dependencies' => array( $key ),
+ 'scripts' => $testFiles,
+ );
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
* Handler for ResourceLoaderRegisterModules hook
*/
public static function onResourceLoaderRegisterModules( ResourceLoader
&$resourceLoader ) {
@@ -702,6 +746,13 @@
);
$vars['wgEchoHelpPage'] = $wgEchoHelpPage;
$vars['wgEchoConfig'] = $wgEchoConfig;
+ } else if ( SpecialPage::getTitleFor( 'JavaScriptTest', 'qunit'
)->equals( $outputPage->getTitle() ) ) {
+ // For testing purposes
+ $vars['wgEchoConfig'] = array(
+ 'eventlogging' => array(
+ 'EchoInteraction' => array(),
+ ),
+ );
}
return true;
diff --git a/Resources.php b/Resources.php
index fc814ec..1a56c2f 100644
--- a/Resources.php
+++ b/Resources.php
@@ -34,7 +34,9 @@
// dependencies that do not target mobile.
'ext.echo.base' => $echoResourceTemplate + array(
'styles' => 'base/ext.echo.base.less',
- 'scripts' => 'base/ext.echo.base.js',
+ 'scripts' => array(
+ 'base/ext.echo.base.js',
+ ),
'messages' => array(
'echo-error-preference',
'echo-error-token',
@@ -42,7 +44,9 @@
'targets' => array( 'desktop', 'mobile' ),
),
'ext.echo.desktop' => $echoResourceTemplate + array(
- 'scripts' => 'desktop/ext.echo.desktop.js',
+ 'scripts' => array(
+ 'desktop/ext.echo.desktop.js',
+ ),
'dependencies' => array(
'ext.echo.base',
'mediawiki.api',
diff --git a/tests/qunit/overlay/test_ext.echo.overlay.js
b/tests/qunit/overlay/test_ext.echo.overlay.js
new file mode 100644
index 0000000..31a39c6
--- /dev/null
+++ b/tests/qunit/overlay/test_ext.echo.overlay.js
@@ -0,0 +1,67 @@
+( function( $, mw ) {
+ QUnit.module( 'ext.echo.overlay', {
+ setup: function() {
+ var ApiStub = function() {};
+ ApiStub.prototype = {
+ post: function() {
+ return $.Deferred().resolve( {
+ query: {
+ echomarkread: {
+ count: 0
+ }
+ }
+ } );
+ },
+ get: function() {
+ return new $.Deferred().resolve( {
+ query: {
+ notifications: {
+ index: [ 70, 71
],
+ count: '1',
+ rawcount: 1,
+ list: {
+ 70: {
+
'*': 'Jon mentioned you.',
+
agent: { id: 212, name: 'Jon' },
+
category: 'mention',
+
id: 70,
+
read: '20140805211446',
+
timestamp: {
+
unix: '1407273276'
+
},
+
title: {
+
full: 'Spiders'
+
},
+
type: 'mention'
+ },
+ 71: {
+
'*': 'X talked to you.',
+
category: 'edit-user-talk',
+
id: 71,
+
type: 'edit-user-talk'
+ }
+ }
+ }
+ }
+ } );
+ }
+ };
+ this.sandbox.stub( mw, 'Api', ApiStub );
+ }
+ } );
+
+ QUnit.test( 'mw.echo.overlay.buildOverlay', 5, function( assert ) {
+ var $overlay;
+ mw.echo.overlay.buildOverlay( function( $o ) {
+ $overlay = $o;
+ } );
+ assert.strictEqual( $overlay.find( 'ul' ).length, 1, 'Overlay
contains a list of notifications.' );
+ assert.strictEqual( $overlay.find( 'li' ).length, 2, 'There are
two notifications.' );
+ assert.strictEqual( $overlay.find( '.mw-echo-unread' ).length,
1, 'There is one unread notification.' );
+ assert.strictEqual( $overlay.find( '#mw-echo-overlay-footer a'
).length, 2,
+ 'There is a footer with 2 links to preferences and all
notifications.' );
+ assert.strictEqual( $overlay.find(
'a#mw-echo-overlay-moreinfo-link' ).length, 1,
+ 'There is a help link.' );
+ } );
+
+}( jQuery, mediaWiki ) );
--
To view, visit https://gerrit.wikimedia.org/r/151976
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0c9f358ce3eb62adb07b68623e97c07993c9c45c
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Bsitu <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits