jquery.makeCollapsible: basic test suite
authorMatmaRex <matma.rex@gmail.com>
Mon, 25 Mar 2013 19:16:07 +0000 (20:16 +0100)
committerMatmaRex <matma.rex@gmail.com>
Wed, 3 Apr 2013 15:48:35 +0000 (17:48 +0200)
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

tests/qunit/QUnitTestResources.php
tests/qunit/suites/resources/jquery/jquery.makeCollapsible.test.js [new file with mode: 0644]

index 01072d8..1cc7fc3 100644 (file)
@@ -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 (file)
index 0000000..082d86b
--- /dev/null
@@ -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(
+                       '<div class="mw-collapsible">' + loremIpsum + '</div>',
+                       { 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(
+                       '<div class="mw-collapsible mw-collapsed">' + loremIpsum + '</div>'
+               );
+               $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(
+                       '<div class="mw-collapsible">' + loremIpsum + '</div>',
+                       { 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 ) );