{ 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',
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'
);
} );
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'
);
$.extend( true, {}, { filter1: '1' } ),
'Parameters in Uri query set parameter value in the model'
);
-
- uriProcessor.updateModelBasedOnQuery( { highlight: '1', group1__filter1_color: 'c1', urlversion: '2' } );
- assert.deepEqual(
- filtersModel.getCurrentParameterState(),
- {
- highlight: '1',
- group1__filter1_color: 'c1'
- },
- 'Highlight parameters in Uri query set highlight state in the model'
- );
} );
QUnit.test( 'isNewState', function ( assert ) {
} );
} );
+ 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 ) );