1
0

bootstrap-alert.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. $(function () {
  2. module("bootstrap-alerts")
  3. test("should provide no conflict", function () {
  4. var alert = $.fn.alert.noConflict()
  5. ok(!$.fn.alert, 'alert was set back to undefined (org value)')
  6. $.fn.alert = alert
  7. })
  8. test("should be defined on jquery object", function () {
  9. ok($(document.body).alert, 'alert method is defined')
  10. })
  11. test("should return element", function () {
  12. ok($(document.body).alert()[0] == document.body, 'document.body returned')
  13. })
  14. test("should fade element out on clicking .close", function () {
  15. var alertHTML = '<div class="alert-message warning fade in">'
  16. + '<a class="close" href="#" data-dismiss="alert">×</a>'
  17. + '<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>'
  18. + '</div>'
  19. , alert = $(alertHTML).alert()
  20. alert.find('.close').click()
  21. ok(!alert.hasClass('in'), 'remove .in class on .close click')
  22. })
  23. test("should remove element when clicking .close", function () {
  24. $.support.transition = false
  25. var alertHTML = '<div class="alert-message warning fade in">'
  26. + '<a class="close" href="#" data-dismiss="alert">×</a>'
  27. + '<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>'
  28. + '</div>'
  29. , alert = $(alertHTML).appendTo('#qunit-fixture').alert()
  30. ok($('#qunit-fixture').find('.alert-message').length, 'element added to dom')
  31. alert.find('.close').click()
  32. ok(!$('#qunit-fixture').find('.alert-message').length, 'element removed from dom')
  33. })
  34. test("should not fire closed when close is prevented", function () {
  35. $.support.transition = false
  36. stop();
  37. $('<div class="alert"/>')
  38. .bind('close', function (e) {
  39. e.preventDefault();
  40. ok(true);
  41. start();
  42. })
  43. .bind('closed', function () {
  44. ok(false);
  45. })
  46. .alert('close')
  47. })
  48. })