// $Id$ /** * @file * Tests for collapsible fieldsets. */ (function($) { Drupal.dependencies.push(function(settings) { return settings.basePath + 'misc/form.js'; }); Drupal.dependencies.push(function(settings) { return settings.basePath + 'misc/collapse.js'; }); Drupal.tests.collapse = { getInfo: function() { return { 'name': 'Collapsible fieldsets', 'description': 'Tests collapsible fieldsets to make sure they collapse and uncollapse correctly.', 'group': 'System' }; }, setup: function() { $(Drupal.tests.iframe).html('
Test fieldsetContent
' + '
Test fieldset
Content
' + ''); Drupal.attachBehaviors(Drupal.tests.iframe); }, test: function() { // The first fieldset should be visible initially, but we should be able to // toggle it by clicking on the legend. ok($('#1', Drupal.tests.iframe).find('div.fieldset-wrapper').is(':visible'), Drupal.t('First fieldset is initially visible.')); ok($('#1', Drupal.tests.iframe).hasClass('collapsible'), Drupal.t('First fieldset has the "collapsible" class.')); ok(!$('#1', Drupal.tests.iframe).hasClass('collapsed'), Drupal.t('First fieldset does not have the "collapsed" class.')); // Trigger the collapse behavior by simulating a click. $('#1', Drupal.tests.iframe).find('> legend > a').click(); ok($('#1', Drupal.tests.iframe).find('div.fieldset-wrapper').is(':hidden'), Drupal.t('First fieldset is not visible after being toggled.')); ok($('#1', Drupal.tests.iframe).hasClass('collapsible'), Drupal.t('First fieldset has the "collapsible" class after being toggled.')); ok($('#1', Drupal.tests.iframe).hasClass('collapsed'), Drupal.t('First fieldset has the "collapsed" class after being toggled.')); // Trigger the collapse behavior again by simulating a click. ok($('#1', Drupal.tests.iframe).find('div.fieldset-wrapper').is(':visible'), Drupal.t('First fieldset is visible after being toggled again.')); ok($('#1', Drupal.tests.iframe).hasClass('collapsible'), Drupal.t('First fieldset has the "collapsible" class after being toggled again.')); ok(!$('#1', Drupal.tests.iframe).hasClass('collapsed'), Drupal.t('First fieldset does not have the "collapsed" class after being toggled again.')); // The second fieldset should not do anything as it is not collapsible. ok($('#2', Drupal.tests.iframe).find('div.fieldset-wrapper').is(':visible'), Drupal.t('Second fieldset is initially visible.')); ok(!$('#2', Drupal.tests.iframe).hasClass('collapsible'), Drupal.t('Second fieldset does not have the "collapsible" class.')); ok(!$('#2', Drupal.tests.iframe).hasClass('collapsed'), Drupal.t('Second fieldset does not have the "collapsed" class.')); // After toggling, nothing should happen. $('#2', Drupal.tests.iframe).find('> legend > a').click(); ok($('#2', Drupal.tests.iframe).find('div.fieldset-wrapper').is(':visible'), Drupal.t('Second fieldset is still visible after toggling.')); ok(!$('#2', Drupal.tests.iframe).hasClass('collapsible'), Drupal.t('Second fieldset still does not have the "collapsible" class after toggling.')); ok(!$('#2', Drupal.tests.iframe).hasClass('collapsed'), Drupal.t('Second fieldset still does not have the "collapsed" class after toggling.')); // The third fieldset should be initially hidden, but we should be able to // toggle it by clicking on the legend. ok($('#3', Drupal.tests.iframe).find('div.fieldset-wrapper').is(':hidden'), Drupal.t('Third fieldset is not initially visible.')); ok($('#3', Drupal.tests.iframe).hasClass('collapsible'), Drupal.t('Third fieldset has the "collapsible" class.')); ok(!$('#3', Drupal.tests.iframe).hasClass('collapsed'), Drupal.t('Third fieldset has the "collapsed" class.')); // Trigger the collapse behavior by simulating a click. $('#3', Drupal.tests.iframe).find('> legend > a').click(); ok($('#3', Drupal.tests.iframe).find('div.fieldset-wrapper').is(':visible'), Drupal.t('Third fieldset is visible after being toggled.')); ok($('#3', Drupal.tests.iframe).hasClass('collapsible'), Drupal.t('Third fieldset has the "collapsible" class after being toggled.')); ok(!$('#3', Drupal.tests.iframe).hasClass('collapsed'), Drupal.t('Third fieldset does not have the "collapsed" class after being toggled.')); // Trigger the collapse behavior again by simulating a click. ok($('#3', Drupal.tests.iframe).find('div.fieldset-wrapper').is(':hidden'), Drupal.t('Third fieldset is not visible after being toggled again.')); ok($('#3', Drupal.tests.iframe).hasClass('collapsible'), Drupal.t('Third fieldset has the "collapsible" class after being toggled again.')); ok($('#3', Drupal.tests.iframe).hasClass('collapsed'), Drupal.t('Third fieldset has the "collapsed" class after being toggled again.')); } }; })(jQuery);