bootstrap-modal.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. $(function () {
  2. module("bootstrap-modal")
  3. test("should be defined on jquery object", function () {
  4. var div = $("<div id='modal-test'></div>")
  5. ok(div.modal, 'modal method is defined')
  6. })
  7. test("should return element", function () {
  8. var div = $("<div id='modal-test'></div>")
  9. ok(div.modal() == div, 'document.body returned')
  10. $('#modal-test').remove()
  11. })
  12. test("should expose defaults var for settings", function () {
  13. ok($.fn.modal.defaults, 'default object exposed')
  14. })
  15. test("should insert into dom when show method is called", function () {
  16. stop()
  17. $.support.transition = false
  18. $("<div id='modal-test'></div>")
  19. .bind("shown", function () {
  20. ok($('#modal-test').length, 'modal insterted into dom')
  21. $(this).remove()
  22. start()
  23. })
  24. .modal("show")
  25. })
  26. test("should hide modal when hide is called", function () {
  27. stop()
  28. $.support.transition = false
  29. $("<div id='modal-test'></div>")
  30. .bind("shown", function () {
  31. ok($('#modal-test').is(":visible"), 'modal visible')
  32. ok($('#modal-test').length, 'modal insterted into dom')
  33. $(this).modal("hide")
  34. })
  35. .bind("hidden", function() {
  36. ok(!$('#modal-test').is(":visible"), 'modal hidden')
  37. $('#modal-test').remove()
  38. start()
  39. })
  40. .modal("show")
  41. })
  42. test("should toggle when toggle is called", function () {
  43. stop()
  44. $.support.transition = false
  45. var div = $("<div id='modal-test'></div>")
  46. div
  47. .bind("shown", function () {
  48. ok($('#modal-test').is(":visible"), 'modal visible')
  49. ok($('#modal-test').length, 'modal insterted into dom')
  50. div.modal("toggle")
  51. })
  52. .bind("hidden", function() {
  53. ok(!$('#modal-test').is(":visible"), 'modal hidden')
  54. div.remove()
  55. start()
  56. })
  57. .modal("toggle")
  58. })
  59. test("should remove from dom when click [data-dismiss=modal]", function () {
  60. stop()
  61. $.support.transition = false
  62. var div = $("<div id='modal-test'><span class='close' data-dismiss='modal'></span></div>")
  63. div
  64. .bind("shown", function () {
  65. ok($('#modal-test').is(":visible"), 'modal visible')
  66. ok($('#modal-test').length, 'modal insterted into dom')
  67. div.find('.close').click()
  68. })
  69. .bind("hidden", function() {
  70. ok(!$('#modal-test').is(":visible"), 'modal hidden')
  71. div.remove()
  72. start()
  73. })
  74. .modal("toggle")
  75. })
  76. })