From 63b833ab18086949cac5a045a8e3671e09a73f3c Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 4 Apr 2012 22:48:46 +0200 Subject: [PATCH] increase qunit coverage of mediawiki.html and mediawiki.util - mw.html * Adding test for mw.html.Raw * Adding more tests for mw.html.element - mw.util * Minor coding style update (local variables) * Updating mw.util.addPortletLink to not create its own "#mw-panel", this was previously done for ./qunit/index.html (which has been removed) but when ran on [[Special:JavaScriptTest/qunit]] it collides with the existing "#mw-panel", so far didn't break anything but that was purely lucky. This element is redundant so taking it out of the html sample * Removing redundant clean up, #qunit-fixture is automatically cleaned after each test Change-Id: Iaf9791ca3cdcac1b732c851cdecc8fcd9f96fdd8 --- .../resources/mediawiki/mediawiki.test.js | 27 ++++++++++--- .../mediawiki/mediawiki.util.test.js | 39 +++++++++---------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js index ea1187e115..e66cac2cf0 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js @@ -266,20 +266,22 @@ test( 'mw.loader.bug30825', function() { mw.loader.load( target ); }); -test( 'mw.html', function() { - expect(11); +test( 'mw.html', function () { + expect(13); - raises( function(){ + raises( function () { mw.html.escape(); }, TypeError, 'html.escape throws a TypeError if argument given is not a string' ); equal( mw.html.escape( '' ), - '<mw awesome="awesome" value='test' />', 'html.escape escapes html snippet' ); + '<mw awesome="awesome" value='test' />', 'escape() escapes special characters to html entities' ); equal( mw.html.element(), - '', 'html.element Always return a valid html string (even without arguments)' ); + '', 'element() always returns a valid html string (even without arguments)' ); + + equal( mw.html.element( 'div' ), '
', 'element() Plain DIV (simple)' ); - equal( mw.html.element( 'div' ), '
', 'html.element DIV (simple)' ); + equal( mw.html.element( 'div', {}, '' ), '
', 'element() Basic DIV (simple)' ); equal( mw.html.element( @@ -294,6 +296,19 @@ test( 'mw.html', function() { equal( mw.html.element( 'p', { title: 12 }, '' ), '

', 'Numbers are valid attribute values' ); + // Example from https://www.mediawiki.org/wiki/ResourceLoader/Default_modules#mediaWiki.html + equal( + mw.html.element( + 'div', + {}, + new mw.html.Raw( + mw.html.element( 'img', { src: '<' } ) + ) + ), + '
', + 'Raw inclusion of another element' + ); + equal( mw.html.element( 'option', { diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js index ea28935ed4..d396b04c1d 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js @@ -140,48 +140,45 @@ test( '$content', function() { * Previously, test elements where invisible to the selector since only * one element can have a given id. */ -test( 'addPortletLink', function() { +test( 'addPortletLink', function () { + var pTestTb, vectorTabs, tbRL, tbMW, $tbMW, tbRLDM, caFoo; expect(7); - var mwPanel = '
\ -
Toolbox
\ + pTestTb = '\
\
    \ -
    \ -
    ', - vectorTabs = '
    \ -
    Views
    \ -
      \ -
      ', - $mwPanel = $(mwPanel).appendTo( '#qunit-fixture' ), - $vectorTabs = $(vectorTabs).appendTo( '#qunit-fixture' ); - - var tbRL = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/ResourceLoader', +
      '; + vectorTabs = '\ +
      \ +
      Views
      \ +
        \ +
        '; + + $('#qunit-fixture').append(pTestTb, vectorTabs); + + tbRL = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/ResourceLoader', 'ResourceLoader', 't-rl', 'More info about ResourceLoader on MediaWiki.org ', 'l' ); ok( $.isDomElement( tbRL ), 'addPortletLink returns a valid DOM Element according to $.isDomElement' ); - var tbMW = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/', - 'MediaWiki.org', 't-mworg', 'Go to MediaWiki.org ', 'm', tbRL ), - $tbMW = $( tbMW ); + tbMW = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/', + 'MediaWiki.org', 't-mworg', 'Go to MediaWiki.org ', 'm', tbRL ); + $tbMW = $( tbMW ); equal( $tbMW.attr( 'id' ), 't-mworg', 'Link has correct ID set' ); equal( $tbMW.closest( '.portlet' ).attr( 'id' ), 'p-test-tb', 'Link was inserted within correct portlet' ); equal( $tbMW.next().attr( 'id' ), 't-rl', 'Link is in the correct position (by passing nextnode)' ); - var tbRLDM = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/RL/DM', + tbRLDM = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/RL/DM', 'Default modules', 't-rldm', 'List of all default modules ', 'd', '#t-rl' ); equal( $( tbRLDM ).next().attr( 'id' ), 't-rl', 'Link is in the correct position (by passing CSS selector)' ); - var caFoo = mw.util.addPortletLink( 'p-test-views', '#', 'Foo' ); + caFoo = mw.util.addPortletLink( 'p-test-views', '#', 'Foo' ); strictEqual( $tbMW.find( 'span').length, 0, 'No element should be added for porlets without vectorTabs class.' ); strictEqual( $( caFoo ).find( 'span').length, 1, 'A element should be added for porlets with vectorTabs class.' ); - - // Clean up - $( [tbRL, tbMW, tbRLDM, caFoo] ).remove(); }); test( 'jsMessage', function() { -- 2.20.1