Debian Codegraph @

tests/qunit/resources/mediawiki.toc.test.js

raw symbols SCIP
1 ( function () {
2 QUnit.module( 'mediawiki.toc', {
3 beforeEach: function () {
4 this.getCookie = this.stub( mw.cookie, 'get' ).returns( null );
5 this.setCookie = this.stub( mw.cookie, 'set' ).returns( null );
6 this.tocHtml = '<div class="toc" role="navigation">' +
7 '<input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" />' +
8 '<div class="toctitle" lang="en" dir="ltr">' +
9 '<span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span>' +
10 '</div>' +
11 '<ul><li class="toclevel-1 tocsection-1">…</li></ul>' +
12 '</div>';
13 }
14 } );
15
16 QUnit.test( 'Use toggle', function ( assert ) {
17 const tocNode = $.parseHTML( this.tocHtml )[ 0 ];
18 const tocToggle = tocNode.querySelector( '.toctogglelabel' );
19 $( '#qunit-fixture' ).append( tocNode );
20 mw.hook( 'wikipage.content' ).fire( $( '#qunit-fixture' ) );
21
22 assert.strictEqual( this.getCookie.callCount, 1, 'Initial cookie reads' );
23 assert.strictEqual( this.setCookie.callCount, 0, 'Initial cookie writes' );
24
25 tocToggle.click();
26
27 assert.propEqual( this.setCookie.args[ 0 ], [ 'hidetoc', '1' ], 'Cookie set' );
28 assert.strictEqual( this.getCookie.callCount, 1, 'Final cookie reads' );
29 assert.strictEqual( this.setCookie.callCount, 1, 'Final cookie writes' );
30 } );
31
32 QUnit.test( 'Initially hidden', function ( assert ) {
33 this.getCookie.returns( '1' );
34
35 const tocNode = $.parseHTML( this.tocHtml )[ 0 ];
36 $( '#qunit-fixture' ).append( tocNode );
37 mw.hook( 'wikipage.content' ).fire( $( '#qunit-fixture' ) );
38
39 assert.strictEqual( this.getCookie.callCount, 1, 'Initial cookie reads' );
40 assert.strictEqual( this.setCookie.callCount, 0, 'Initial cookie writes' );
41 } );
42 }() );