jenkins-bot has submitted this change and it was merged. Change subject: Added TemplatedWidget QUnit tests ......................................................................
Added TemplatedWidget QUnit tests Change-Id: Ib38ae165188d7fa23e97d7b2ff0eaafcb00e839f --- A repo/tests/qunit/jquery.ui/jquery.ui.TemplatedWidget.tests.js M repo/tests/qunit/resources.php 2 files changed, 85 insertions(+), 0 deletions(-) Approvals: Adrian Lang: Looks good to me, approved jenkins-bot: Verified diff --git a/repo/tests/qunit/jquery.ui/jquery.ui.TemplatedWidget.tests.js b/repo/tests/qunit/jquery.ui/jquery.ui.TemplatedWidget.tests.js new file mode 100644 index 0000000..dab7e11 --- /dev/null +++ b/repo/tests/qunit/jquery.ui/jquery.ui.TemplatedWidget.tests.js @@ -0,0 +1,73 @@ +/** + * @licence GNU GPL v2+ + * @author H. Snater < [email protected] > + */ +( function( mw, $, QUnit ) { + 'use strict'; + +QUnit.module( 'jquery.ui.TemplatedWidget' ); + +QUnit.test( 'Create & destroy', function( assert ) { + var testSets = [ + [ + '<div><span>$1</span></div>', + { + templateParams: ['test'], + templateShortCuts: { + $div: 'span' + } + } + ] + ]; + + /** + * @param {Object} templateShortCuts + */ + function checkShortCuts( templateShortCuts ) { + $.each( templateShortCuts, function( key, selector ) { + assert.ok( + $subject.data( 'TemplatedWidget' )[key] instanceof $, + 'Assigned templateShortCut: ' + key + '.' + ); + } ); + } + + for( var i = 0; i < testSets.length; i++ ) { + mw.wbTemplates.store.set( 'templatedWidget-test', testSets[i][0] ); + + var $subject = $( '<div/>' ); + + $subject.TemplatedWidget( $.extend( { + template: 'templatedWidget-test' + }, testSets[i][1] ) ); + + assert.ok( + $subject.data( 'TemplatedWidget' ) instanceof $.ui.TemplatedWidget, + 'Test set #' + i + ': Initialized widget.' + ); + + $subject.removeAttr( 'class' ); + + assert.equal( + $( '<div/>' ).append( $subject ).html(), + $( '<div/>' ).append( + mw.wbTemplate( 'templatedWidget-test', testSets[i][1].templateParams ) + ).html(), + 'Verified generated HTML.' + ); + + if( testSets[i][1].templateShortCuts ) { + checkShortCuts( testSets[i][1].templateShortCuts ); + } + + $subject.data( 'TemplatedWidget' ).destroy(); + + assert.ok( + $subject.data( 'TemplatedWidget' ) === undefined, + 'Destroyed widget.' + ); + } + +} ); + +}( mediaWiki, jQuery, QUnit ) ); diff --git a/repo/tests/qunit/resources.php b/repo/tests/qunit/resources.php index fe38f43..b2730c7 100644 --- a/repo/tests/qunit/resources.php +++ b/repo/tests/qunit/resources.php @@ -16,6 +16,17 @@ ); $modules = array( + + 'jquery.ui.TemplatedWidget.tests' => $moduleBase + array( + 'scripts' => array( + 'jquery.ui/jquery.ui.TemplatedWidget.tests.js', + ), + 'dependencies' => array( + 'jquery.ui.TemplatedWidget', + 'wikibase.templates', + ), + ), + 'templates.tests' => $moduleBase + array( 'scripts' => array( 'templates.tests.js', @@ -24,6 +35,7 @@ 'wikibase.templates', ), ), + ); return $modules; -- To view, visit https://gerrit.wikimedia.org/r/172506 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib38ae165188d7fa23e97d7b2ff0eaafcb00e839f Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Henning Snater <[email protected]> Gerrit-Reviewer: Adrian Lang <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
