defaults.test.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. describe("bootbox.setDefaults", function() {
  2. beforeEach(function() {
  3. this.find = function(selector) {
  4. return this.dialog.find(selector);
  5. };
  6. });
  7. describe("animate", function() {
  8. describe("when set to false", function() {
  9. beforeEach(function() {
  10. bootbox.setDefaults({
  11. animate: false
  12. });
  13. this.dialog = bootbox.dialog({
  14. message: "test"
  15. });
  16. });
  17. it("does not add the fade class to the dialog", function() {
  18. expect(this.dialog.hasClass("fade")).to.be.false;
  19. });
  20. it("applies the correct class to the body", function() {
  21. expect($("body").hasClass("modal-open")).to.be.true;
  22. });
  23. describe("when clicking the close button", function() {
  24. beforeEach(function() {
  25. this.dialog.find(".close").trigger("click");
  26. });
  27. it("removes the modal-open class from the body", function() {
  28. expect($("body").hasClass("modal-open")).to.be.false;
  29. });
  30. });
  31. });
  32. describe("when set to true", function() {
  33. beforeEach(function() {
  34. bootbox.setDefaults({
  35. animate: true
  36. });
  37. this.dialog = bootbox.dialog({
  38. message: "test"
  39. });
  40. });
  41. it("adds the fade class to the dialog", function() {
  42. expect(this.dialog.hasClass("fade")).to.be.true;
  43. });
  44. });
  45. });
  46. describe("className", function() {
  47. describe("when passed as a string", function() {
  48. beforeEach(function() {
  49. bootbox.setDefaults({
  50. className: "my-class"
  51. });
  52. this.dialog = bootbox.dialog({
  53. message: "test"
  54. });
  55. });
  56. it("adds the extra class to the outer dialog", function() {
  57. expect(this.dialog.hasClass("bootbox")).to.be.true;
  58. expect(this.dialog.hasClass("my-class")).to.be.true;
  59. });
  60. });
  61. });
  62. describe("size", function() {
  63. describe("when set to large", function() {
  64. beforeEach(function() {
  65. bootbox.setDefaults({
  66. size: "large"
  67. });
  68. this.dialog = bootbox.dialog({
  69. message: "test"
  70. });
  71. });
  72. it("adds the large class to the innerDialog", function() {
  73. expect(this.dialog.children(".modal-dialog").hasClass("modal-lg")).to.be.true;
  74. });
  75. });
  76. describe("when set to small", function() {
  77. beforeEach(function() {
  78. bootbox.setDefaults({
  79. size: "small"
  80. });
  81. this.dialog = bootbox.dialog({
  82. message: "test"
  83. });
  84. });
  85. it("adds the small class to the innerDialog", function() {
  86. expect(this.dialog.children(".modal-dialog").hasClass("modal-sm")).to.be.true;
  87. });
  88. });
  89. });
  90. describe("backdrop", function() {
  91. describe("when set to false", function() {
  92. beforeEach(function() {
  93. bootbox.setDefaults({
  94. backdrop: false
  95. });
  96. this.dialog = bootbox.dialog({
  97. message: "test"
  98. });
  99. });
  100. it("does not show a backdrop", function() {
  101. expect(this.dialog.next(".modal-backdrop").length).to.equal(0);
  102. });
  103. });
  104. });
  105. describe("when passed two arguments", function() {
  106. beforeEach(function() {
  107. bootbox.setDefaults("className", "my-class");
  108. this.dialog = bootbox.dialog({
  109. message: "test"
  110. });
  111. });
  112. it("applies the arguments as a key/value pair", function() {
  113. expect(this.dialog.hasClass("bootbox")).to.be.true;
  114. expect(this.dialog.hasClass("my-class")).to.be.true;
  115. });
  116. });
  117. describe("container", function () {
  118. describe("when not explicitly set", function() {
  119. beforeEach(function() {
  120. this.dialog = bootbox.dialog({
  121. message: "test"
  122. });
  123. });
  124. it("defaults to the body element", function() {
  125. expect(this.dialog.parent().is("body")).to.be.true;
  126. });
  127. });
  128. describe("when explicitly set to body", function() {
  129. beforeEach(function() {
  130. bootbox.setDefaults({
  131. container: "body"
  132. });
  133. this.dialog = bootbox.dialog({
  134. message: "test"
  135. });
  136. });
  137. it("sets the correct parent element", function() {
  138. expect(this.dialog.parent().is("body")).to.be.true;
  139. });
  140. });
  141. describe("when set to another dom element", function() {
  142. beforeEach(function() {
  143. this.container = $("<div></div>");
  144. bootbox.setDefaults({
  145. container: this.container
  146. });
  147. this.dialog = bootbox.dialog({
  148. message: "test"
  149. });
  150. });
  151. it("sets the correct parent element", function() {
  152. expect(this.dialog.parent().is(this.container)).to.be.true;
  153. });
  154. });
  155. });
  156. });