Move toctoggle from mediawiki.util.js to separate file mediawiki.toc.js
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.toc.test.js
1 ( function ( mw, $ ) {
2 QUnit.module( 'mediawiki.toc', QUnit.newMwEnvironment() );
3
4 QUnit.asyncTest( 'toggleToc', 4, function ( assert ) {
5 var tocHtml, $toggleLink, $tocList;
6
7 function actionC() {
8 QUnit.start();
9 }
10
11 function actionB() {
12 assert.strictEqual( $tocList.is( ':hidden' ), true, 'Return boolean true if the TOC is now visible.' );
13 $toggleLink.click();
14 $tocList.promise().done( actionC );
15 }
16
17 function actionA() {
18 assert.strictEqual( $tocList.is( ':hidden' ), false, 'Return boolean false if the TOC is now hidden.' );
19 $toggleLink.click();
20 $tocList.promise().done( actionB );
21 }
22
23 assert.strictEqual( $( '#toc' ).length, 0, 'Return 0 if there is no table of contents on the page.' );
24
25 tocHtml = '<div id="toc" class="toc">' +
26 '<div id="toctitle">' +
27 '<h2>Contents</h2>' +
28 '</div>' +
29 '<ul><li></li></ul>' +
30 '</div>';
31 $( tocHtml ).appendTo( '#qunit-fixture' );
32 mw.hook( 'wikipage.content' ).fire( $( '#qunit-fixture' ) );
33 $tocList = $( '#toc ul:first' );
34 $toggleLink = $( '#togglelink' );
35
36 assert.strictEqual( $toggleLink.length, 1, 'Toggle link is appended to the page.' );
37
38 actionA();
39 } );
40 }( mediaWiki, jQuery ) );