1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/bootstrap-source/bootstrap-3.0.3/js/tests/unit/collapse.js Fri Dec 20 22:49:16 2013 +0100
1.3 @@ -0,0 +1,164 @@
1.4 +$(function () {
1.5 +
1.6 + module("collapse")
1.7 +
1.8 + test("should provide no conflict", function () {
1.9 + var collapse = $.fn.collapse.noConflict()
1.10 + ok(!$.fn.collapse, 'collapse was set back to undefined (org value)')
1.11 + $.fn.collapse = collapse
1.12 + })
1.13 +
1.14 + test("should be defined on jquery object", function () {
1.15 + ok($(document.body).collapse, 'collapse method is defined')
1.16 + })
1.17 +
1.18 + test("should return element", function () {
1.19 + ok($(document.body).collapse()[0] == document.body, 'document.body returned')
1.20 + })
1.21 +
1.22 + test("should show a collapsed element", function () {
1.23 + var el = $('<div class="collapse"></div>').collapse('show')
1.24 + ok(el.hasClass('in'), 'has class in')
1.25 + ok(/height/.test(el.attr('style')), 'has height set')
1.26 + })
1.27 +
1.28 + test("should hide a collapsed element", function () {
1.29 + var el = $('<div class="collapse"></div>').collapse('hide')
1.30 + ok(!el.hasClass('in'), 'does not have class in')
1.31 + ok(/height/.test(el.attr('style')), 'has height set')
1.32 + })
1.33 +
1.34 + test("should not fire shown when show is prevented", function () {
1.35 + $.support.transition = false
1.36 + stop()
1.37 + $('<div class="collapse"/>')
1.38 + .on('show.bs.collapse', function (e) {
1.39 + e.preventDefault();
1.40 + ok(true);
1.41 + start();
1.42 + })
1.43 + .on('shown.bs.collapse', function () {
1.44 + ok(false);
1.45 + })
1.46 + .collapse('show')
1.47 + })
1.48 +
1.49 + test("should reset style to auto after finishing opening collapse", function () {
1.50 + $.support.transition = false
1.51 + stop()
1.52 + $('<div class="collapse" style="height: 0px"/>')
1.53 + .on('show.bs.collapse', function () {
1.54 + ok(this.style.height == '0px')
1.55 + })
1.56 + .on('shown.bs.collapse', function () {
1.57 + ok(this.style.height == 'auto')
1.58 + start()
1.59 + })
1.60 + .collapse('show')
1.61 + })
1.62 +
1.63 + test("should add active class to target when collapse shown", function () {
1.64 + $.support.transition = false
1.65 + stop()
1.66 +
1.67 + var target = $('<a data-toggle="collapse" href="#test1"></a>')
1.68 + .appendTo($('#qunit-fixture'))
1.69 +
1.70 + var collapsible = $('<div id="test1"></div>')
1.71 + .appendTo($('#qunit-fixture'))
1.72 + .on('show.bs.collapse', function () {
1.73 + ok(!target.hasClass('collapsed'))
1.74 + start()
1.75 + })
1.76 +
1.77 + target.click()
1.78 + })
1.79 +
1.80 + test("should remove active class to target when collapse hidden", function () {
1.81 + $.support.transition = false
1.82 + stop()
1.83 +
1.84 + var target = $('<a data-toggle="collapse" href="#test1"></a>')
1.85 + .appendTo($('#qunit-fixture'))
1.86 +
1.87 + var collapsible = $('<div id="test1" class="in"></div>')
1.88 + .appendTo($('#qunit-fixture'))
1.89 + .on('hide.bs.collapse', function () {
1.90 + ok(target.hasClass('collapsed'))
1.91 + start()
1.92 + })
1.93 +
1.94 + target.click()
1.95 + })
1.96 +
1.97 + test("should remove active class from inactive accordion targets", function () {
1.98 + $.support.transition = false
1.99 + stop()
1.100 +
1.101 + var accordion = $('<div id="accordion"><div class="accordion-group"></div><div class="accordion-group"></div><div class="accordion-group"></div></div>')
1.102 + .appendTo($('#qunit-fixture'))
1.103 +
1.104 + var target1 = $('<a data-toggle="collapse" href="#body1" data-parent="#accordion"></a>')
1.105 + .appendTo(accordion.find('.accordion-group').eq(0))
1.106 +
1.107 + var collapsible1 = $('<div id="body1" class="in"></div>')
1.108 + .appendTo(accordion.find('.accordion-group').eq(0))
1.109 +
1.110 + var target2 = $('<a class="collapsed" data-toggle="collapse" href="#body2" data-parent="#accordion"></a>')
1.111 + .appendTo(accordion.find('.accordion-group').eq(1))
1.112 +
1.113 + var collapsible2 = $('<div id="body2"></div>')
1.114 + .appendTo(accordion.find('.accordion-group').eq(1))
1.115 +
1.116 + var target3 = $('<a class="collapsed" data-toggle="collapse" href="#body3" data-parent="#accordion"></a>')
1.117 + .appendTo(accordion.find('.accordion-group').eq(2))
1.118 +
1.119 + var collapsible3 = $('<div id="body3"></div>')
1.120 + .appendTo(accordion.find('.accordion-group').eq(2))
1.121 + .on('show.bs.collapse', function () {
1.122 + ok(target1.hasClass('collapsed'))
1.123 + ok(target2.hasClass('collapsed'))
1.124 + ok(!target3.hasClass('collapsed'))
1.125 +
1.126 + start()
1.127 + })
1.128 +
1.129 + target3.click()
1.130 + })
1.131 +
1.132 + test("should allow dots in data-parent", function () {
1.133 + $.support.transition = false
1.134 + stop()
1.135 +
1.136 + var accordion = $('<div class="accordion"><div class="accordion-group"></div><div class="accordion-group"></div><div class="accordion-group"></div></div>')
1.137 + .appendTo($('#qunit-fixture'))
1.138 +
1.139 + var target1 = $('<a data-toggle="collapse" href="#body1" data-parent=".accordion"></a>')
1.140 + .appendTo(accordion.find('.accordion-group').eq(0))
1.141 +
1.142 + var collapsible1 = $('<div id="body1" class="in"></div>')
1.143 + .appendTo(accordion.find('.accordion-group').eq(0))
1.144 +
1.145 + var target2 = $('<a class="collapsed" data-toggle="collapse" href="#body2" data-parent=".accordion"></a>')
1.146 + .appendTo(accordion.find('.accordion-group').eq(1))
1.147 +
1.148 + var collapsible2 = $('<div id="body2"></div>')
1.149 + .appendTo(accordion.find('.accordion-group').eq(1))
1.150 +
1.151 + var target3 = $('<a class="collapsed" data-toggle="collapse" href="#body3" data-parent=".accordion"></a>')
1.152 + .appendTo(accordion.find('.accordion-group').eq(2))
1.153 +
1.154 + var collapsible3 = $('<div id="body3"></div>')
1.155 + .appendTo(accordion.find('.accordion-group').eq(2))
1.156 + .on('show.bs.collapse', function () {
1.157 + ok(target1.hasClass('collapsed'))
1.158 + ok(target2.hasClass('collapsed'))
1.159 + ok(!target3.hasClass('collapsed'))
1.160 +
1.161 + start()
1.162 + })
1.163 +
1.164 + target3.click()
1.165 + })
1.166 +
1.167 +})