X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fqunit%2Fsuites%2Fresources%2Fmediawiki%2Fmediawiki.util.test.js;h=673cb15cf08be65a50bce50f413a87433053237f;hb=1a625b8ced8b27cf892dc4a2d58a1b7682382b17;hp=272b1471dddf09f0622d9e8c20896ffdf5ec47fe;hpb=9c185ca85c3c58f96e866c9347c2b7f031ddb289;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js index 272b1471dd..673cb15cf0 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js @@ -1,4 +1,4 @@ -( function ( mw, $ ) { +( function () { var util = require( 'mediawiki.util' ), // Based on IPTest.php > testisIPv4 IPV4_CASES = [ @@ -150,6 +150,7 @@ QUnit.test( 'wikiUrlencode', function ( assert ) { assert.strictEqual( util.wikiUrlencode( 'Test:A & B/Here' ), 'Test:A_%26_B/Here' ); // See also wfUrlencodeTest.php#provideURLS + // eslint-disable-next-line no-restricted-properties $.each( { '+': '%2B', '&': '%26', @@ -282,7 +283,7 @@ } ); QUnit.test( '$content', function ( assert ) { - assert.ok( util.$content instanceof jQuery, 'mw.util.$content instance of jQuery' ); + assert.ok( util.$content instanceof $, 'mw.util.$content instance of jQuery' ); assert.strictEqual( util.$content.length, 1, 'mw.util.$content must have length of 1' ); } ); @@ -293,15 +294,14 @@ * one element can have a given id. */ QUnit.test( 'addPortletLink', function ( assert ) { - var pTestTb, pCustom, vectorTabs, tbRL, cuQuux, $cuQuux, tbMW, $tbMW, tbRLDM, caFoo, + var tbRL, cuQuux, $cuQuux, tbMW, $tbMW, tbRLDM, caFoo, addedAfter, tbRLDMnonexistentid, tbRLDMemptyjquery; - pTestTb = + $( '#qunit-fixture' ).append( '
' + '

Toolbox

' + '' + - '
'; - pCustom = + '' + '
' + '

Views

' + '' + '' + '' + - '
'; - vectorTabs = + '' + '
' + '

Views

' + '' + - '
'; - - $( '#qunit-fixture' ).append( pTestTb, pCustom, vectorTabs ); - - tbRL = util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/ResourceLoader', - 'ResourceLoader', 't-rl', 'More info about ResourceLoader on MediaWiki.org ', 'l' + '' ); - assert.ok( tbRL && tbRL.nodeType, 'addPortletLink returns a DOM Node' ); + tbRL = util.addPortletLink( 'p-test-tb', 'https://example.org/next', + 'Next', 't-rl', 'More info about Example Next ', 'l' + ); + assert.strictEqual( tbRL.nodeType, 1, 'returns a DOM Node' ); + assert.strictEqual( tbRL.nodeName, 'LI', 'returns a list item element' ); - tbMW = util.addPortletLink( 'p-test-tb', '//mediawiki.org/', - 'MediaWiki.org', 't-mworg', 'Go to MediaWiki.org', 'm', tbRL ); + tbMW = util.addPortletLink( 'p-test-tb', '//example.org/', + 'Example.org', 't-xmp', 'Go to Example', 'x', tbRL ); $tbMW = $( tbMW ); - assert.propEqual( $tbMW.getAttrs(), { - id: 't-mworg' + id: 't-xmp' }, - 'Validate attributes of created element' + 'List item attributes' ); - assert.propEqual( $tbMW.find( 'a' ).getAttrs(), { - href: '//mediawiki.org/', - title: 'Go to MediaWiki.org [test-m]', - accesskey: 'm' + href: '//example.org/', + title: 'Go to Example [test-x]', + accesskey: 'x' }, - 'Validate attributes of anchor tag in created element' + 'Anchor link attributes' + ); + assert.strictEqual( + $tbMW.closest( '.portlet' ).attr( 'id' ), + 'p-test-tb', + 'Parent portlet ID' + ); + assert.strictEqual( + $tbMW.next()[ 0 ], + tbRL, + 'Next node (set as Node object)' + ); + assert.strictEqual( + $tbMW.find( 'span' ).length, + 0, + 'No wrap for porlets without vectorTabs class' ); - - assert.strictEqual( $tbMW.closest( '.portlet' ).attr( 'id' ), 'p-test-tb', 'Link was inserted within correct portlet' ); - assert.strictEqual( $tbMW.next()[ 0 ], tbRL, 'Link is in the correct position (nextnode as Node object)' ); cuQuux = util.addPortletLink( 'p-test-custom', '#', 'Quux', null, 'Example [shift-x]', 'q' ); $cuQuux = $( cuQuux ); - - assert.strictEqual( $cuQuux.find( 'a' ).attr( 'title' ), 'Example [test-q]', 'Existing accesskey is stripped and updated' ); - + assert.strictEqual( + $cuQuux.find( 'a' ).attr( 'title' ), + 'Example [test-q]', + 'Title has new accesskey and label' + ); assert.strictEqual( $( '#p-test-custom #c-barmenu ul li' ).length, 1, - 'addPortletLink did not add the item to all