modal.coffee 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. define [
  2. "utils/Modal"
  3. ], (Modal) ->
  4. describe "Modal", ->
  5. describe "initialization", ->
  6. beforeEach ->
  7. @modal = Modal.createModal
  8. title: "Test modal"
  9. message : "Test modal message"
  10. buttons: [{
  11. text : "OK"
  12. class : "btn-primary"
  13. }, {
  14. text : "Cancel"
  15. class : "btn-danger"
  16. }]
  17. afterEach ->
  18. @modal.remove()
  19. it "should display the modal", ->
  20. @modal.$el.is(":visible").should.equal true
  21. it "should include the buttons in reverse order", ->
  22. buttons = @modal.$(".modal-footer a")
  23. $(buttons[0]).text().should.equal "Cancel"
  24. $(buttons[0]).hasClass("btn-danger").should.equal true
  25. $(buttons[1]).text().should.equal "OK"
  26. $(buttons[1]).hasClass("btn-primary").should.equal true
  27. it "should include the title", ->
  28. @modal.$("h3").text().should.equal "Test modal"
  29. it "should include the message", ->
  30. @modal.$(".message").text().should.equal "Test modal message"
  31. describe "clicking buttons", ->
  32. beforeEach ->
  33. @callbackCalled = false
  34. @modal = Modal.createModal
  35. title: "Test modal"
  36. message : "Test modal message"
  37. buttons: [{
  38. text : "OK"
  39. class : "btn-primary"
  40. callback : () =>
  41. @callbackCalled = true
  42. }]
  43. @modal.$(".modal-footer a").click()
  44. it "should call the callback", ->
  45. @callbackCalled.should.equal true
  46. it "should remove the modal", ->
  47. @modal.$el.is(":visible").should.equal false
  48. @modal.$el.parent().length.should.equal 0