fca2a80b11ace1dcc9552ebbbcc26e48a0476431
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki.special / mediawiki.special.recentchanges.test.js
1 module( 'mediawiki.special.recentchanges' );
2
3 test( '-- Initial check', function() {
4 expect( 2 );
5 ok( mw.special.recentchanges.init,
6 'mw.special.recentchanges.init defined'
7 );
8 ok( mw.special.recentchanges.updateCheckboxes,
9 'mw.special.recentchanges.updateCheckboxes defined'
10 );
11 // TODO: verify checkboxes == [ 'nsassociated', 'nsinvert' ]
12 });
13
14 test( '"all" namespace disable checkboxes', function() {
15
16 // from Special:Recentchanges
17 var select =
18 '<select id="namespace" name="namespace" class="namespaceselector">'
19 + '<option value="" selected="selected">all</option>'
20 + '<option value="0">(Main)</option>'
21 + '<option value="1">Talk</option>'
22 + '<option value="2">User</option>'
23 + '<option value="3">User talk</option>'
24 + '<option value="4">ProjectName</option>'
25 + '<option value="5">ProjectName talk</option>'
26 + '</select>'
27 + '<input name="invert" type="checkbox" value="1" id="nsinvert" title="no title" />'
28 + '<label for="nsinvert" title="no title">Invert selection</label>'
29 + '<input name="associated" type="checkbox" value="1" id="nsassociated" title="no title" />'
30 + '<label for="nsassociated" title="no title">Associated namespace</label>'
31 + '<input type="submit" value="Go" />'
32 + '<input type="hidden" value="Special:RecentChanges" name="title" />'
33 ;
34
35 var $env = $( '<div>' ).html( select ).appendTo( 'body' );
36
37 // TODO abstract the double strictEquals
38
39 // At first checkboxes are enabled
40 strictEqual( $( '#nsinvert' ).attr( 'disabled' ), undefined );
41 strictEqual( $( '#nsassociated' ).attr( 'disabled' ), undefined );
42
43 // Initiate the recentchanges module
44 mw.special.recentchanges.init();
45
46 // By default
47 strictEqual( $( '#nsinvert' ).attr( 'disabled' ), 'disabled' );
48 strictEqual( $( '#nsassociated' ).attr( 'disabled' ), 'disabled' );
49
50 // select second option...
51 var $options = $( '#namespace' ).find( 'option' );
52 $options.eq(0).removeAttr( 'selected' );
53 $options.eq(1).attr( 'selected', 'selected' );
54 $( '#namespace' ).change();
55
56 // ... and checkboxes should be enabled again
57 strictEqual( $( '#nsinvert' ).attr( 'disabled' ), undefined );
58 strictEqual( $( '#nsassociated' ).attr( 'disabled' ), undefined );
59
60 // select first option ( 'all' namespace)...
61 $options.eq(1).removeAttr( 'selected' );
62 $options.eq(0).attr( 'selected', 'selected' );;
63 $( '#namespace' ).change();
64
65 // ... and checkboxes should now be disabled
66 strictEqual( $( '#nsinvert' ).attr( 'disabled' ), 'disabled' );
67 strictEqual( $( '#nsassociated' ).attr( 'disabled' ), 'disabled' );
68
69 // DOM cleanup
70 $env.remove();
71 });