X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fqunit%2Fsuites%2Fresources%2Fmediawiki.rcfilters%2FUriProcessor.test.js;h=fbd159cbb14f318f42a30e91906cb059599c483e;hp=534af86d6426f80e507bffd3238ea3505b333f45;hb=08edb27f6ce31c676660a4ef89b87da79bde2cc2;hpb=8743d28bf21cde3324cab4c0bbbdb23a1430e4e9 diff --git a/tests/qunit/suites/resources/mediawiki.rcfilters/UriProcessor.test.js b/tests/qunit/suites/resources/mediawiki.rcfilters/UriProcessor.test.js index 534af86d64..fbd159cbb1 100644 --- a/tests/qunit/suites/resources/mediawiki.rcfilters/UriProcessor.test.js +++ b/tests/qunit/suites/resources/mediawiki.rcfilters/UriProcessor.test.js @@ -25,6 +25,15 @@ { name: 'filter5', cssClass: 'filter5class' }, { name: 'filter6' } // Not supporting highlights ] + }, { + name: 'group4', + title: 'Group 4', + type: 'boolean', + sticky: true, + filters: [ + { name: 'stickyFilter7', cssClass: 'filter7class' }, + { name: 'stickyFilter8', cssClass: 'filter8class' } + ] } ], minimalDefaultParams = { filter1: '1', @@ -51,19 +60,24 @@ QUnit.test( 'getUpdatedUri', function ( assert ) { var uriProcessor, - filtersModel = new mw.rcfilters.dm.FiltersViewModel(); + filtersModel = new mw.rcfilters.dm.FiltersViewModel(), + makeUri = function ( queryParams ) { + var uri = new mw.Uri(); + uri.query = queryParams; + return uri; + }; filtersModel.initializeFilters( mockFilterStructure ); uriProcessor = new mw.rcfilters.UriProcessor( filtersModel ); assert.deepEqual( - ( uriProcessor.getUpdatedUri( {} ) ).query, + ( uriProcessor.getUpdatedUri( makeUri( {} ) ) ).query, { urlversion: '2' }, 'Empty model state with empty uri state, assumes the given uri is already normalized, and adds urlversion=2' ); assert.deepEqual( - ( uriProcessor.getUpdatedUri( { foo: 'bar' } ) ).query, + ( uriProcessor.getUpdatedUri( makeUri( { foo: 'bar' } ) ) ).query, { urlversion: '2', foo: 'bar' }, 'Empty model state with unrecognized params retains unrecognized params' ); @@ -75,13 +89,13 @@ } ); assert.deepEqual( - ( uriProcessor.getUpdatedUri( {} ) ).query, + ( uriProcessor.getUpdatedUri( makeUri( {} ) ) ).query, { urlversion: '2', filter2: '1', group3: 'filter5' }, 'Model state is reflected in the updated URI' ); assert.deepEqual( - ( uriProcessor.getUpdatedUri( { foo: 'bar' } ) ).query, + ( uriProcessor.getUpdatedUri( makeUri( { foo: 'bar' } ) ) ).query, { urlversion: '2', filter2: '1', group3: 'filter5', foo: 'bar' }, 'Model state is reflected in the updated URI with existing uri params' ); @@ -263,4 +277,63 @@ } ); } ); + QUnit.test( '_normalizeTargetInUri', function ( assert ) { + var uriProcessor = new mw.rcfilters.UriProcessor( null ), + cases = [ + { + input: 'http://host/wiki/Special:RecentChangesLinked/Moai', + output: 'http://host/wiki/Special:RecentChangesLinked?target=Moai', + message: 'Target as subpage in path' + }, + { + input: 'http://host/wiki/Special:RecentChangesLinked/Château', + output: 'http://host/wiki/Special:RecentChangesLinked?target=Château', + message: 'Target as subpage in path with special characters' + }, + { + input: 'http://host/wiki/Special:RecentChangesLinked/Moai/Sub1', + output: 'http://host/wiki/Special:RecentChangesLinked?target=Moai/Sub1', + message: 'Target as subpage also has a subpage' + }, + { + input: 'http://host/wiki/Special:RecentChangesLinked/Category:Foo', + output: 'http://host/wiki/Special:RecentChangesLinked?target=Category:Foo', + message: 'Target as subpage in path (with namespace)' + }, + { + input: 'http://host/wiki/Special:RecentChangesLinked/Category:Foo/Bar', + output: 'http://host/wiki/Special:RecentChangesLinked?target=Category:Foo/Bar', + message: 'Target as subpage in path also has a subpage (with namespace)' + }, + { + input: 'http://host/w/index.php?title=Special:RecentChangesLinked/Moai', + output: 'http://host/w/index.php?title=Special:RecentChangesLinked&target=Moai', + message: 'Target as subpage in title param' + }, + { + input: 'http://host/w/index.php?title=Special:RecentChangesLinked/Moai/Sub1', + output: 'http://host/w/index.php?title=Special:RecentChangesLinked&target=Moai/Sub1', + message: 'Target as subpage in title param also has a subpage' + }, + { + input: 'http://host/w/index.php?title=Special:RecentChangesLinked/Category:Foo/Bar', + output: 'http://host/w/index.php?title=Special:RecentChangesLinked&target=Category:Foo/Bar', + message: 'Target as subpage in title param also has a subpage (with namespace)' + }, + { + input: 'http://host/wiki/Special:Watchlist', + output: 'http://host/wiki/Special:Watchlist', + message: 'No target specified' + } + ]; + + cases.forEach( function ( testCase ) { + assert.equal( + uriProcessor._normalizeTargetInUri( new mw.Uri( testCase.input ) ).toString(), + new mw.Uri( testCase.output ).toString(), + testCase.message + ); + } ); + } ); + }( mediaWiki, jQuery ) );