bootstrap-button.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. $(function () {
  2. module("bootstrap-buttons")
  3. test("should be defined on jquery object", function () {
  4. ok($(document.body).button, 'button method is defined')
  5. })
  6. test("should return element", function () {
  7. ok($(document.body).button()[0] == document.body, 'document.body returned')
  8. })
  9. test("should return set state to loading", function () {
  10. var btn = $('<button class="btn" data-loading-text="fat">mdo</button>')
  11. equals(btn.html(), 'mdo', 'btn text equals mdo')
  12. btn.button('loading')
  13. equals(btn.html(), 'fat', 'btn text equals fat')
  14. stop()
  15. setTimeout(function () {
  16. ok(btn.attr('disabled'), 'btn is disabled')
  17. ok(btn.hasClass('disabled'), 'btn has disabled class')
  18. start()
  19. }, 0)
  20. })
  21. test("should return reset state", function () {
  22. var btn = $('<button class="btn" data-loading-text="fat">mdo</button>')
  23. equals(btn.html(), 'mdo', 'btn text equals mdo')
  24. btn.button('loading')
  25. equals(btn.html(), 'fat', 'btn text equals fat')
  26. stop()
  27. setTimeout(function () {
  28. ok(btn.attr('disabled'), 'btn is disabled')
  29. ok(btn.hasClass('disabled'), 'btn has disabled class')
  30. start()
  31. stop()
  32. }, 0)
  33. btn.button('reset')
  34. equals(btn.html(), 'mdo', 'btn text equals mdo')
  35. setTimeout(function () {
  36. ok(!btn.attr('disabled'), 'btn is not disabled')
  37. ok(!btn.hasClass('disabled'), 'btn does not have disabled class')
  38. start()
  39. }, 0)
  40. })
  41. test("should toggle active", function () {
  42. var btn = $('<button class="btn" data-loading-text="fat">mdo</button>')
  43. ok(!btn.hasClass('active'), 'btn does not have active class')
  44. btn.button('toggle')
  45. ok(btn.hasClass('active'), 'btn has class active')
  46. })
  47. })