From: Heinrich Fenkart Date: Wed, 18 Jun 2014 19:34:01 +0000 (+0200) Subject: Clean collapse unit tests up X-Git-Tag: v3.3.0~379^2~2^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77d055746828165ae9e3d90f4fb08e30d57cabb7;p=thirdparty%2Fbootstrap.git Clean collapse unit tests up --- diff --git a/js/tests/unit/collapse.js b/js/tests/unit/collapse.js index 4a0cf2b2e8..5522d53c6e 100644 --- a/js/tests/unit/collapse.js +++ b/js/tests/unit/collapse.js @@ -19,156 +19,153 @@ $(function () { }) test('should provide no conflict', function () { - ok(!$.fn.collapse, 'collapse was set back to undefined (org value)') + strictEqual($.fn.collapse, undefined, 'collapse was set back to undefined (org value)') }) - test('should return element', function () { - ok($(document.body).bootstrapCollapse()[0] == document.body, 'document.body returned') + test('should return jquery collection containing the element', function () { + var $el = $('
') + var $collapse = $el.bootstrapCollapse() + ok($collapse instanceof $, 'returns jquery collection') + strictEqual($collapse[0], $el[0], 'collection contains element') }) test('should show a collapsed element', function () { - var el = $('
').bootstrapCollapse('show') - ok(el.hasClass('in'), 'has class in') - ok(!/height/.test(el.attr('style')), 'has height reset') + var $el = $('
').bootstrapCollapse('show') + + ok($el.hasClass('in'), 'has class "in"') + ok(!/height/.test($el.attr('style')), 'has height reset') }) test('should hide a collapsed element', function () { - var el = $('
').bootstrapCollapse('hide') - ok(!el.hasClass('in'), 'does not have class in') - ok(/height/.test(el.attr('style')), 'has height set') + var $el = $('
').bootstrapCollapse('hide') + + ok(!$el.hasClass('in'), 'does not have class "in"') + ok(/height/.test($el.attr('style')), 'has height set') }) test('should not fire shown when show is prevented', function () { - $.support.transition = false stop() + $('
') .on('show.bs.collapse', function (e) { e.preventDefault() - ok(true) + ok(true, 'show event fired') start() }) .on('shown.bs.collapse', function () { - ok(false) + ok(false, 'shown event fired') }) .bootstrapCollapse('show') }) test('should reset style to auto after finishing opening collapse', function () { - $.support.transition = false stop() + $('
') .on('show.bs.collapse', function () { - ok(this.style.height == '0px') + equal(this.style.height, '0px', 'height is 0px') }) .on('shown.bs.collapse', function () { - ok(this.style.height === '') + strictEqual(this.style.height, '', 'height is auto') start() }) .bootstrapCollapse('show') }) - test('should add active class to target when collapse shown', function () { - $.support.transition = false + test('should remove "collapsed" class from target when collapse is shown', function () { stop() - var target = $('') - .appendTo($('#qunit-fixture')) + var $target = $('').appendTo('#qunit-fixture') - $('
') - .appendTo($('#qunit-fixture')) + $('
') + .appendTo('#qunit-fixture') .on('show.bs.collapse', function () { - ok(!target.hasClass('collapsed')) + ok(!$target.hasClass('collapsed')) start() }) - target.click() + $target.click() }) - test('should remove active class to target when collapse hidden', function () { - $.support.transition = false + test('should add "collapsed" class to target when collapse is hidden', function () { stop() - var target = $('') - .appendTo($('#qunit-fixture')) + var $target = $('').appendTo('#qunit-fixture') - $('
') - .appendTo($('#qunit-fixture')) + $('
') + .appendTo('#qunit-fixture') .on('hide.bs.collapse', function () { - ok(target.hasClass('collapsed')) + ok($target.hasClass('collapsed')) start() }) - target.click() + $target.click() }) - test('should remove active class from inactive accordion targets', function () { - $.support.transition = false + test('should remove "collapsed" class from active accordion target', function () { stop() - var accordion = $('
') - .appendTo($('#qunit-fixture')) + var accordionHTML = '
' + + '
' + + '
' + + '
' + + '
' + var $groups = $(accordionHTML).appendTo('#qunit-fixture').find('.accordion-group') - var target1 = $('
') - .appendTo(accordion.find('.accordion-group').eq(0)) + var $target1 = $('').appendTo($groups.eq(0)) - $('
') - .appendTo(accordion.find('.accordion-group').eq(0)) + $('
').appendTo($groups.eq(0)) - var target2 = $('') - .appendTo(accordion.find('.accordion-group').eq(1)) + var $target2 = $('
') - .appendTo(accordion.find('.accordion-group').eq(2)) + var $target3 = $('