Nikerabbit has uploaded a new change for review. https://gerrit.wikimedia.org/r/158349
Change subject: Add QUnit tests for ext.cx.editor ...................................................................... Add QUnit tests for ext.cx.editor Change-Id: I8dc1f550959cfa3d4f81288434cf51cf76650e93 --- M ContentTranslation.hooks.php A tests/qunit/editor/ext.cx.editor.test.js 2 files changed, 75 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/49/158349/1 diff --git a/ContentTranslation.hooks.php b/ContentTranslation.hooks.php index ea21786..a612baf 100644 --- a/ContentTranslation.hooks.php +++ b/ContentTranslation.hooks.php @@ -106,6 +106,13 @@ 'remoteExtPath' => 'ContentTranslation', ); + $testModules['qunit']['ext.cx.editor.tests'] = array( + 'scripts' => array( 'tests/qunit/editor/ext.cx.editor.test.js' ), + 'dependencies' => array( 'ext.cx.editor' ), + 'localBasePath' => __DIR__, + 'remoteExtPath' => 'ContentTranslation', + ); + return true; } } diff --git a/tests/qunit/editor/ext.cx.editor.test.js b/tests/qunit/editor/ext.cx.editor.test.js new file mode 100644 index 0000000..4fffcca --- /dev/null +++ b/tests/qunit/editor/ext.cx.editor.test.js @@ -0,0 +1,68 @@ +/** + * @file + * @author Niklas Laxström + * @license GPL-2.0+ + */ + +( function ( $, mw ) { + 'use strict'; + + /** + * Testing persistent hooks is tricky. This should take care of the messy details. + * + * @param {string} hook Name of the hook. + * @param {function} trigger Function to call to trigger an event. + * @param {function} callback Function to bind to the hook. + */ + function triggerSafely( hook, callback, trigger ) { + // Fire wake even so we know we are not getting cached data, + // use timeout as there is no way to know when trigger has + // been processed - especially since the other end uses + // $.debounce. There seems to be no way to clear the hooks + // either. + mw.hook( hook ).fire(); + + trigger.call(); + + setTimeout( function () { + mw.hook( hook ).add( callback ); + }, 300 ); + } + + QUnit.module( 'ext.cx.editor', QUnit.newMwEnvironment( { + setup: function () { + this.hook = null; + this.asserter = null; + this.$section = $( '<div>' ).appendTo( $( '#qunit-fixture' ) ); + this.$section.cxEditor(); + }, + teardown: function () { + mw.hook( this.hook ).remove( this.asserter ); + } + } ) ); + + QUnit.test( 'Initialization', function ( assert ) { + QUnit.expect( 1 ); + assert.strictEqual( + this.$section.attr( 'contenteditable' ), + 'true', + 'Section is content editable' + ); + } ); + + QUnit.test( 'Event (change)', function ( assert ) { + var $section = this.$section; + + this.hook = 'mw.cx.translation.change'; + this.asserter = function ( value ) { + QUnit.start(); + assert.ok( value instanceof jQuery, 'Event was fired' ); + }; + + QUnit.expect( 1 ); + QUnit.stop(); + triggerSafely( this.hook, this.asserter, function () { + $section.text( 'bar' ).trigger( 'input' ); + } ); + } ); +}( jQuery, mediaWiki ) ); -- To view, visit https://gerrit.wikimedia.org/r/158349 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8dc1f550959cfa3d4f81288434cf51cf76650e93 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Nikerabbit <niklas.laxst...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits