Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/151976
Change subject: The first ever Echo QUnit tests
......................................................................
The first ever Echo QUnit tests
Change-Id: I0c9f358ce3eb62adb07b68623e97c07993c9c45c
---
M Echo.php
M Hooks.php
A tests/qunit/overlay/test_ext.echo.overlay.js
3 files changed, 120 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo
refs/changes/76/151976/1
diff --git a/Echo.php b/Echo.php
index 159ba31..e344dbd 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..bd54197 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 ( !empty( $testFiles ) ) {
+ $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/tests/qunit/overlay/test_ext.echo.overlay.js
b/tests/qunit/overlay/test_ext.echo.overlay.js
new file mode 100644
index 0000000..55bebdd
--- /dev/null
+++ b/tests/qunit/overlay/test_ext.echo.overlay.js
@@ -0,0 +1,68 @@
+( function( $ ) {
+ QUnit.module( 'ext.echo.overlay', {
+ setup: function() {
+ var ApiStub;
+ 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 ) );
--
To view, visit https://gerrit.wikimedia.org/r/151976
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0c9f358ce3eb62adb07b68623e97c07993c9c45c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits