1
0

bootstrap-collapse.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. $(function () {
  2. module("bootstrap-collapse")
  3. test("should provide no conflict", function () {
  4. var collapse = $.fn.collapse.noConflict()
  5. ok(!$.fn.collapse, 'collapse was set back to undefined (org value)')
  6. $.fn.collapse = collapse
  7. })
  8. test("should be defined on jquery object", function () {
  9. ok($(document.body).collapse, 'collapse method is defined')
  10. })
  11. test("should return element", function () {
  12. ok($(document.body).collapse()[0] == document.body, 'document.body returned')
  13. })
  14. test("should show a collapsed element", function () {
  15. var el = $('<div class="collapse"></div>').collapse('show')
  16. ok(el.hasClass('in'), 'has class in')
  17. ok(/height/.test(el.attr('style')), 'has height set')
  18. })
  19. test("should hide a collapsed element", function () {
  20. var el = $('<div class="collapse"></div>').collapse('hide')
  21. ok(!el.hasClass('in'), 'does not have class in')
  22. ok(/height/.test(el.attr('style')), 'has height set')
  23. })
  24. test("should not fire shown when show is prevented", function () {
  25. $.support.transition = false
  26. stop()
  27. $('<div class="collapse"/>')
  28. .bind('show', function (e) {
  29. e.preventDefault();
  30. ok(true);
  31. start();
  32. })
  33. .bind('shown', function () {
  34. ok(false);
  35. })
  36. .collapse('show')
  37. })
  38. test("should reset style to auto after finishing opening collapse", function () {
  39. $.support.transition = false
  40. stop()
  41. $('<div class="collapse" style="height: 0px"/>')
  42. .bind('show', function () {
  43. ok(this.style.height == '0px')
  44. })
  45. .bind('shown', function () {
  46. ok(this.style.height == 'auto')
  47. start()
  48. })
  49. .collapse('show')
  50. })
  51. test("should add active class to target when collapse shown", function () {
  52. $.support.transition = false
  53. stop()
  54. var target = $('<a data-toggle="collapse" href="#test1"></a>')
  55. .appendTo($('#qunit-fixture'))
  56. var collapsible = $('<div id="test1"></div>')
  57. .appendTo($('#qunit-fixture'))
  58. .on('show', function () {
  59. ok(!target.hasClass('collapsed'))
  60. start()
  61. })
  62. target.click()
  63. })
  64. test("should remove active class to target when collapse hidden", function () {
  65. $.support.transition = false
  66. stop()
  67. var target = $('<a data-toggle="collapse" href="#test1"></a>')
  68. .appendTo($('#qunit-fixture'))
  69. var collapsible = $('<div id="test1" class="in"></div>')
  70. .appendTo($('#qunit-fixture'))
  71. .on('hide', function () {
  72. ok(target.hasClass('collapsed'))
  73. start()
  74. })
  75. target.click()
  76. })
  77. })