Tobias Gritschacher has submitted this change and it was merged.
Change subject: Added tests for notifier
......................................................................
Added tests for notifier
Change-Id: I61fa216ec48e3f5b5630789b61c198859f6ea166
---
M DataValues/DataValues.mw.php
A DataValues/tests/qunit/dataValues.util.Notifier.tests.js
2 files changed, 116 insertions(+), 0 deletions(-)
Approvals:
Tobias Gritschacher: Verified; Looks good to me, approved
jenkins-bot: Verified
diff --git a/DataValues/DataValues.mw.php b/DataValues/DataValues.mw.php
index d783abb..db2197d 100644
--- a/DataValues/DataValues.mw.php
+++ b/DataValues/DataValues.mw.php
@@ -141,6 +141,7 @@
$testModules['qunit']['ext.dataValues.util'] = $moduleTemplate + array(
'scripts' => array(
'tests/qunit/dataValues.util.inherit.tests.js',
+ 'tests/qunit/dataValues.util.Notifier.tests.js',
),
'dependencies' => array(
'dataValues.util',
diff --git a/DataValues/tests/qunit/dataValues.util.Notifier.tests.js
b/DataValues/tests/qunit/dataValues.util.Notifier.tests.js
new file mode 100644
index 0000000..a4a59ea
--- /dev/null
+++ b/DataValues/tests/qunit/dataValues.util.Notifier.tests.js
@@ -0,0 +1,115 @@
+/**
+ * QUnit tests for Notifier constructor and instances.
+ *
+ * @since 0.1
+ * @file
+ * @ingroup DataValues
+ *
+ * @licence GNU GPL v2+
+ * @author Daniel Werner < [email protected] >
+ */
+( function( dataValues, $, QUnit ) {
+ 'use strict';
+
+ QUnit.module( 'dataValues.util.Notifier' );
+
+ var Notifier = dataValues.util.Notifier;
+
+
+ QUnit.test( 'Construction of Notifier instances', function( assert ) {
+ assert.ok(
+ Notifier() instanceof Notifier,
+ 'Instance created without using "new" keyword'
+ );
+
+ assert.ok(
+ new Notifier() instanceof Notifier,
+ 'Instance created by using "new" keyword'
+ );
+
+ assert.ok(
+ new Notifier( {} ) instanceof Notifier,
+ 'Instance created with empty object literal as argument'
+ );
+
+ assert.throws(
+ function() {
+ new Notifier( 'foo' );
+ },
+ 'Creating Notifier with wrong argument fails'
+ );
+ } );
+
+ QUnit.test( 'Notifier.prototype.hasListenerFor', function( assert ) {
+ var notificationKeys = [ 'foo', 'bar123', 'xxx' ],
+ notificationMap = {};
+
+ $.map( notificationKeys, function( val, i ) {
+ notificationMap[ val ] = $.noop;
+ } );
+
+ var notifier = new Notifier( notificationMap ),
+ emptyNotifier = new Notifier( {} );
+
+ // check whether all notification keys are available on the
Notifier object:
+ $.each( notificationKeys, function( i, value ) {
+ assert.ok(
+ notifier.hasListenerFor( value ),
+ 'Notifier has registered callback for
notification "' + value + '"'
+ );
+ assert.ok(
+ !emptyNotifier.hasListenerFor( value ),
+ 'Empty Notifier does not have callback for
notification "' + value + '"'
+ );
+ } );
+ } );
+
+ QUnit.test( 'Notifier.prototype.notify', 10, function( assert ) {
+ var notifier;
+
+ // callback with tests for notify() calls:
+ function fnNotifyAssertions( testNotificationKeyName ) {
+ assert.ok(
+ true,
+ 'notification has been triggered'
+ );
+
+ assert.ok(
+ this === notifier,
+ 'Context the notify callback is called in is
the Notifier object'
+ );
+
+ assert.ok(
+ testNotificationKeyName !== undefined,
+ 'Custom notify argument got passed into
callaback'
+ );
+
+ assert.equal(
+ this.current(),
+ testNotificationKeyName,
+ 'Notifier.current() returns callback
notification key "' + testNotificationKeyName + '"'
+ );
+ }
+
+ notifier = new Notifier( {
+ test: fnNotifyAssertions,
+ test2: fnNotifyAssertions
+ } );
+
+ assert.ok(
+ notifier.current() === null,
+ 'Notifier.current() returns null'
+ );
+
+
+ notifier.notify( 'test', [ 'test' ] );
+ notifier.notify( 'test2', [ 'test2' ] );
+ notifier.notify( 'test3' ); // should not do anything
+
+ assert.ok(
+ notifier.current() === null,
+ 'Notifier.current() returns null again'
+ );
+ } );
+
+}( dataValues, jQuery, QUnit ) );
--
To view, visit https://gerrit.wikimedia.org/r/59126
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I61fa216ec48e3f5b5630789b61c198859f6ea166
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits