2 QUnit
.module( 'mediawiki.rcfilters - FiltersViewModel' );
4 QUnit
.test( 'Setting up filters', function ( assert
) {
8 type
: 'send_unselected_if_any',
11 name
: 'group1filter1',
12 label
: 'Group 1: Filter 1',
13 description
: 'Description of Filter 1 in Group 1'
16 name
: 'group1filter2',
17 label
: 'Group 1: Filter 2',
18 description
: 'Description of Filter 2 in Group 1'
24 type
: 'send_unselected_if_any',
27 name
: 'group2filter1',
28 label
: 'Group 2: Filter 1',
29 description
: 'Description of Filter 1 in Group 2'
32 name
: 'group2filter2',
33 label
: 'Group 2: Filter 2',
34 description
: 'Description of Filter 2 in Group 2'
39 model
= new mw
.rcfilters
.dm
.FiltersViewModel();
41 model
.initializeFilters( definition
);
44 model
.getItemByName( 'group1filter1' ) instanceof mw
.rcfilters
.dm
.FilterItem
&&
45 model
.getItemByName( 'group1filter2' ) instanceof mw
.rcfilters
.dm
.FilterItem
&&
46 model
.getItemByName( 'group2filter1' ) instanceof mw
.rcfilters
.dm
.FilterItem
&&
47 model
.getItemByName( 'group2filter2' ) instanceof mw
.rcfilters
.dm
.FilterItem
,
48 'Filters instantiated and stored correctly'
59 'Initial state of filters'
62 model
.updateFilters( {
74 'Updating filter states correctly'
78 QUnit
.test( 'Finding matching filters', function ( assert
) {
83 type
: 'send_unselected_if_any',
86 name
: 'group1filter1',
87 label
: 'Group 1: Filter 1',
88 description
: 'Description of Filter 1 in Group 1'
91 name
: 'group1filter2',
92 label
: 'Group 1: Filter 2',
93 description
: 'Description of Filter 2 in Group 1'
99 type
: 'send_unselected_if_any',
102 name
: 'group2filter1',
103 label
: 'Group 2: Filter 1',
104 description
: 'Description of Filter 1 in Group 2'
107 name
: 'group2filter2',
108 label
: 'Group 2: Filter 2',
109 description
: 'Description of Filter 2 in Group 2'
114 model
= new mw
.rcfilters
.dm
.FiltersViewModel();
116 model
.initializeFilters( definition
);
118 matches
= model
.findMatches( 'group 1' );
120 matches
.group1
.length
,
122 'findMatches finds correct group with correct number of results'
126 matches
.group1
.map( function ( item
) { return item
.getName(); } ),
127 [ 'group1filter1', 'group1filter2' ],
128 'findMatches finds the correct items within a single group'
131 matches
= model
.findMatches( 'filter 1' );
133 matches
.group1
.length
=== 1 && matches
.group2
.length
=== 1,
134 'findMatches finds correct number of results in multiple groups'
139 matches
.group1
.map( function ( item
) { return item
.getName(); } ),
140 matches
.group2
.map( function ( item
) { return item
.getName(); } )
146 'findMatches finds the correct items within multiple groups'
149 matches
= model
.findMatches( 'foo' );
151 $.isEmptyObject( matches
),
152 'findMatches returns an empty object when no results found'
156 QUnit
.test( 'getParametersFromFilters', function ( assert
) {
160 type
: 'send_unselected_if_any',
164 label
: 'Group 1: Filter 1',
165 description
: 'Description of Filter 1 in Group 1'
169 label
: 'Group 1: Filter 2',
170 description
: 'Description of Filter 2 in Group 1'
174 label
: 'Group 1: Filter 3',
175 description
: 'Description of Filter 3 in Group 1'
181 type
: 'send_unselected_if_any',
185 label
: 'Group 2: Filter 1',
186 description
: 'Description of Filter 1 in Group 2'
190 label
: 'Group 2: Filter 2',
191 description
: 'Description of Filter 2 in Group 2'
195 label
: 'Group 2: Filter 3',
196 description
: 'Description of Filter 3 in Group 2'
201 model
= new mw
.rcfilters
.dm
.FiltersViewModel();
203 model
.initializeFilters( definition
);
205 // Starting with all filters unselected
207 model
.getParametersFromFilters(),
216 'Unselected filters return all parameters falsey.'
220 model
.updateFilters( {
228 // Only one filter in one group
230 model
.getParametersFromFilters(),
232 // Group 1 (one selected, the others are true)
236 // Group 2 (nothing is selected, all false)
241 'One filters in one "send_unselected_if_any" group returns the other parameters truthy.'
245 model
.updateFilters( {
253 // Two selected filters in one group
255 model
.getParametersFromFilters(),
257 // Group 1 (two selected, the others are true)
261 // Group 2 (nothing is selected, all false)
266 'One filters in one "send_unselected_if_any" group returns the other parameters truthy.'
270 model
.updateFilters( {
278 // All filters of the group are selected == this is the same as not selecting any
280 model
.getParametersFromFilters(),
282 // Group 1 (all selected, all false)
286 // Group 2 (nothing is selected, all false)
291 'All filters selected in one "send_unselected_if_any" group returns all parameters falsy.'
295 QUnit
.test( 'getFiltersFromParameters', function ( assert
) {
299 type
: 'send_unselected_if_any',
303 label
: 'Show filter 1',
304 description
: 'Description of Filter 1 in Group 1'
308 label
: 'Show filter 2',
309 description
: 'Description of Filter 2 in Group 1'
313 label
: 'Show filter 3',
314 description
: 'Description of Filter 3 in Group 1'
320 type
: 'send_unselected_if_any',
324 label
: 'Show filter 4',
325 description
: 'Description of Filter 1 in Group 2'
329 label
: 'Show filter 5',
330 description
: 'Description of Filter 2 in Group 2'
334 label
: 'Show filter 6',
335 description
: 'Description of Filter 3 in Group 2'
340 model
= new mw
.rcfilters
.dm
.FiltersViewModel();
342 model
.initializeFilters( definition
);
344 // Empty query = empty filter definition
346 model
.getFiltersFromParameters( {} ),
348 hidefilter1
: false, // The text is "show filter 1"
349 hidefilter2
: false, // The text is "show filter 2"
350 hidefilter3
: false, // The text is "show filter 3"
351 hidefilter4
: false, // The text is "show filter 4"
352 hidefilter5
: false, // The text is "show filter 5"
353 hidefilter6
: false // The text is "show filter 6"
355 'Empty parameter query results in filters in initial state'
359 model
.getFiltersFromParameters( {
363 hidefilter1
: false, // The text is "show filter 1"
364 hidefilter2
: true, // The text is "show filter 2"
365 hidefilter3
: true, // The text is "show filter 3"
366 hidefilter4
: false, // The text is "show filter 4"
367 hidefilter5
: false, // The text is "show filter 5"
368 hidefilter6
: false // The text is "show filter 6"
370 'One falsey parameter in a group makes the rest of the filters in the group truthy (checked) in the interface'
374 model
.getFiltersFromParameters( {
379 hidefilter1
: false, // The text is "show filter 1"
380 hidefilter2
: false, // The text is "show filter 2"
381 hidefilter3
: true, // The text is "show filter 3"
382 hidefilter4
: false, // The text is "show filter 4"
383 hidefilter5
: false, // The text is "show filter 5"
384 hidefilter6
: false // The text is "show filter 6"
386 'Two falsey parameters in a group makes the rest of the filters in the group truthy (checked) in the interface'
390 model
.getFiltersFromParameters( {
396 // TODO: This will have to be represented as a different state, though.
397 hidefilter1
: false, // The text is "show filter 1"
398 hidefilter2
: false, // The text is "show filter 2"
399 hidefilter3
: false, // The text is "show filter 3"
400 hidefilter4
: false, // The text is "show filter 4"
401 hidefilter5
: false, // The text is "show filter 5"
402 hidefilter6
: false // The text is "show filter 6"
404 'All paremeters in the same group false is equivalent to none are truthy (checked) in the interface'
407 // The ones above don't update the model, so we have a clean state.
410 model
.getFiltersFromParameters( {
416 model
.getFiltersFromParameters( {
421 // 1 and 3 are separately unchecked via hide parameters, 2 should still be
423 // This can simulate separate filters in the same group being hidden different
424 // ways (e.g. preferences and URL).
428 hidefilter1
: false, // The text is "show filter 1"
429 hidefilter2
: true, // The text is "show filter 2"
430 hidefilter3
: false, // The text is "show filter 3"
431 hidefilter4
: false, // The text is "show filter 4"
432 hidefilter5
: false, // The text is "show filter 5"
433 hidefilter6
: false // The text is "show filter 6"
435 'After unchecking 2 of 3 filters via separate updateFilters calls, only the remaining one is still checked.'
439 model
= new mw
.rcfilters
.dm
.FiltersViewModel();
440 model
.initializeFilters( definition
);
443 model
.getFiltersFromParameters( {
448 model
.getFiltersFromParameters( {
453 // Simulates minor edits being hidden in preferences, then unhidden via URL
458 hidefilter1
: false, // The text is "show filter 1"
459 hidefilter2
: false, // The text is "show filter 2"
460 hidefilter3
: false, // The text is "show filter 3"
461 hidefilter4
: false, // The text is "show filter 4"
462 hidefilter5
: false, // The text is "show filter 5"
463 hidefilter6
: false // The text is "show filter 6"
465 'After unchecking then checking a filter (without touching other filters in that group), all are checked'
468 }( mediaWiki
, jQuery
) );