From: MatmaRex Date: Mon, 25 Mar 2013 19:16:07 +0000 (+0100) Subject: jquery.makeCollapsible: basic test suite X-Git-Tag: 1.31.0-rc.0~20114^2 X-Git-Url: http://git.cyclocoop.org/%24dirpuce/puce%24spip_lang_rtl.gif?a=commitdiff_plain;h=f4d8165c9e54725f9fce8780e300991e36dad55c;p=lhc%2Fweb%2Fwiklou.git jquery.makeCollapsible: basic test suite For now it just verifies that the very basic synchronous functionality of the module works; not much more is possible without triggering some events to hook to, and currently jquery.makeCollapsible doesn't trigger any. Change-Id: Icdd8f392e4921007a6bdfb3ae934949e4c875232 --- diff --git a/tests/qunit/QUnitTestResources.php b/tests/qunit/QUnitTestResources.php index 01072d83c4..1cc7fc32a5 100644 --- a/tests/qunit/QUnitTestResources.php +++ b/tests/qunit/QUnitTestResources.php @@ -16,6 +16,7 @@ return array( 'tests/qunit/suites/resources/jquery/jquery.hidpi.test.js', 'tests/qunit/suites/resources/jquery/jquery.highlightText.test.js', 'tests/qunit/suites/resources/jquery/jquery.localize.test.js', + 'tests/qunit/suites/resources/jquery/jquery.makeCollapsible.test.js', 'tests/qunit/suites/resources/jquery/jquery.mwExtension.test.js', 'tests/qunit/suites/resources/jquery/jquery.tabIndex.test.js', 'tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js', @@ -45,6 +46,7 @@ return array( 'jquery.hidpi', 'jquery.highlightText', 'jquery.localize', + 'jquery.makeCollapsible', 'jquery.mwExtension', 'jquery.tabIndex', 'jquery.tablesorter', diff --git a/tests/qunit/suites/resources/jquery/jquery.makeCollapsible.test.js b/tests/qunit/suites/resources/jquery/jquery.makeCollapsible.test.js new file mode 100644 index 0000000000..082d86b451 --- /dev/null +++ b/tests/qunit/suites/resources/jquery/jquery.makeCollapsible.test.js @@ -0,0 +1,51 @@ +( function ( mw, $ ) { + var loremIpsum = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.'; + + QUnit.module( 'jquery.makeCollapsible', QUnit.newMwEnvironment() ); + + function prepareCollapsible( html, options ) { + return $( $.parseHTML( html ) ) + .appendTo( '#qunit-fixture' ) + // options might be undefined here - this is okay + .makeCollapsible( options ); + } + + QUnit.test( 'basic operation with instantHide (synchronous test)', 2, function ( assert ) { + var $collapsible, $content; + $collapsible = prepareCollapsible( + '
' + loremIpsum + '
', + { instantHide: true } + ); + $content = $collapsible.find( '.mw-collapsible-content' ); + + assert.assertTrue( $content.is( ':visible' ), 'content is visible' ); + + $collapsible.find( '.mw-collapsible-toggle' ).trigger( 'click' ); + + assert.assertTrue( $content.is( ':hidden' ), 'after collapsing: content is hidden' ); + } ); + + QUnit.test( 'initially collapsed - mw-collapsed class', 1, function ( assert ) { + var $collapsible, $content; + $collapsible = prepareCollapsible( + '
' + loremIpsum + '
' + ); + $content = $collapsible.find( '.mw-collapsible-content' ); + + // Synchronous - mw-collapsed should cause instantHide: true to be used on initial collapsing + assert.assertTrue( $content.is( ':hidden' ), 'content is hidden' ); + } ); + + QUnit.test( 'initially collapsed - options', 1, function ( assert ) { + var $collapsible, $content; + $collapsible = prepareCollapsible( + '
' + loremIpsum + '
', + { collapsed: true } + ); + $content = $collapsible.find( '.mw-collapsible-content' ); + + // Synchronous - collapsed: true should cause instantHide: true to be used on initial collapsing + assert.assertTrue( $content.is( ':hidden' ), 'content is hidden' ); + } ); + +}( mediaWiki, jQuery ) );