Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki.special / mediawiki.special.recentchanges.test.js
1 ( function () {
2 QUnit.module( 'mediawiki.special.recentchanges', QUnit.newMwEnvironment() );
3
4 // TODO: verify checkboxes == [ 'nsassociated', 'nsinvert' ]
5
6 QUnit.test( '"all" namespace hides checkboxes', function ( assert ) {
7 var selectHtml, $env, $options,
8 rc = require( 'mediawiki.special.recentchanges' );
9
10 // from Special:Recentchanges
11 selectHtml = '<select id="namespace" name="namespace" class="namespaceselector">'
12 + '<option value="" selected="selected">all</option>'
13 + '<option value="0">(Main)</option>'
14 + '<option value="1">Talk</option>'
15 + '<option value="2">User</option>'
16 + '<option value="3">User talk</option>'
17 + '<option value="4">ProjectName</option>'
18 + '<option value="5">ProjectName talk</option>'
19 + '</select>'
20 + '<span class="mw-input-with-label mw-input-hidden">'
21 + '<input name="invert" type="checkbox" value="1" id="nsinvert" title="no title" />'
22 + '<label for="nsinvert" title="no title">Invert selection</label>'
23 + '</span>'
24 + '<span class="mw-input-with-label mw-input-hidden">'
25 + '<input name="associated" type="checkbox" value="1" id="nsassociated" title="no title" />'
26 + '<label for="nsassociated" title="no title">Associated namespace</label>'
27 + '</span>'
28 + '<input type="submit" value="Go" />'
29 + '<input type="hidden" value="Special:RecentChanges" name="title" />';
30
31 $env = $( '<div>' ).html( selectHtml ).appendTo( 'body' );
32
33 // TODO abstract the double strictEquals
34
35 // At first checkboxes are hidden
36 // eslint-disable-next-line no-jquery/no-class-state
37 assert.strictEqual( $( '#nsinvert' ).closest( '.mw-input-with-label' ).hasClass( 'mw-input-hidden' ), true );
38 // eslint-disable-next-line no-jquery/no-class-state
39 assert.strictEqual( $( '#nsassociated' ).closest( '.mw-input-with-label' ).hasClass( 'mw-input-hidden' ), true );
40
41 // Initiate the recentchanges module
42 rc.init();
43
44 // By default
45 // eslint-disable-next-line no-jquery/no-class-state
46 assert.strictEqual( $( '#nsinvert' ).closest( '.mw-input-with-label' ).hasClass( 'mw-input-hidden' ), true );
47 // eslint-disable-next-line no-jquery/no-class-state
48 assert.strictEqual( $( '#nsassociated' ).closest( '.mw-input-with-label' ).hasClass( 'mw-input-hidden' ), true );
49
50 // select second option...
51 $options = $( '#namespace' ).find( 'option' );
52 $options.eq( 0 ).removeProp( 'selected' );
53 $options.eq( 1 ).prop( 'selected', true );
54 $( '#namespace' ).trigger( 'change' );
55
56 // ... and checkboxes should be visible again
57 // eslint-disable-next-line no-jquery/no-class-state
58 assert.strictEqual( $( '#nsinvert' ).closest( '.mw-input-with-label' ).hasClass( 'mw-input-hidden' ), false );
59 // eslint-disable-next-line no-jquery/no-class-state
60 assert.strictEqual( $( '#nsassociated' ).closest( '.mw-input-with-label' ).hasClass( 'mw-input-hidden' ), false );
61
62 // select first option ( 'all' namespace)...
63 $options.eq( 1 ).removeProp( 'selected' );
64 $options.eq( 0 ).prop( 'selected', true );
65 $( '#namespace' ).trigger( 'change' );
66
67 // ... and checkboxes should now be hidden
68 // eslint-disable-next-line no-jquery/no-class-state
69 assert.strictEqual( $( '#nsinvert' ).closest( '.mw-input-with-label' ).hasClass( 'mw-input-hidden' ), true );
70 // eslint-disable-next-line no-jquery/no-class-state
71 assert.strictEqual( $( '#nsassociated' ).closest( '.mw-input-with-label' ).hasClass( 'mw-input-hidden' ), true );
72
73 // DOM cleanup
74 $env.remove();
75 } );
76 }() );