forked from felipekian/bootbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefaults.test.js
More file actions
284 lines (239 loc) · 7.17 KB
/
defaults.test.js
File metadata and controls
284 lines (239 loc) · 7.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
describe('bootbox.setDefaults', function() {
'use strict';
beforeEach(function() {
this.find = function(selector) {
return this.dialog.find(selector);
};
});
describe('animate', function() {
describe('when set to false', function() {
beforeEach(function() {
bootbox.setDefaults({
animate: false
});
this.dialog = bootbox.dialog({
message: 'test'
});
});
it('does not add the fade class to the dialog', function() {
expect(this.dialog.hasClass('fade')).to.be.false;
});
it('applies the correct class to the body', function() {
expect($('body').hasClass('modal-open')).to.be.true;
});
describe('when clicking the close button', function() {
beforeEach(function() {
this.dialog.find('.close').trigger('click');
});
it('removes the modal-open class from the body', function() {
expect($('body').hasClass('modal-open')).to.be.false;
});
});
});
describe('when set to true', function() {
beforeEach(function() {
bootbox.setDefaults({
animate: true
});
this.dialog = bootbox.dialog({
message: 'test'
});
});
it('adds the fade class to the dialog', function() {
expect(this.dialog.hasClass('fade')).to.be.true;
});
});
});
describe('className', function() {
describe('when passed as a string', function() {
beforeEach(function() {
bootbox.setDefaults({
className: 'my-class'
});
this.dialog = bootbox.dialog({
message: 'test'
});
});
it('adds the extra class to the outer dialog', function() {
expect(this.dialog.hasClass('bootbox')).to.be.true;
expect(this.dialog.hasClass('my-class')).to.be.true;
});
});
});
describe('size', function() {
describe('when set to extra-large', function() {
beforeEach(function() {
bootbox.setDefaults({
size: 'extra-large'
});
this.dialog = bootbox.dialog({
message: 'test'
});
});
it('adds the extra-large class to the innerDialog', function() {
expect(this.dialog.children('.modal-dialog').hasClass('modal-xl')).to.be.true;
});
});
describe('when set to xl', function() {
beforeEach(function() {
bootbox.setDefaults({
size: 'xl'
});
this.dialog = bootbox.dialog({
message: 'test'
});
});
it('adds the extra-large class to the innerDialog', function() {
expect(this.dialog.children('.modal-dialog').hasClass('modal-xl')).to.be.true;
});
});
describe('when set to large', function() {
beforeEach(function() {
bootbox.setDefaults({
size: 'large'
});
this.dialog = bootbox.dialog({
message: 'test'
});
});
it('adds the large class to the innerDialog', function() {
expect(this.dialog.children('.modal-dialog').hasClass('modal-lg')).to.be.true;
});
});
describe('when set to lg', function() {
beforeEach(function() {
bootbox.setDefaults({
size: 'lg'
});
this.dialog = bootbox.dialog({
message: 'test'
});
});
it('adds the large class to the innerDialog', function() {
expect(this.dialog.children('.modal-dialog').hasClass('modal-lg')).to.be.true;
});
});
describe('when set to small', function() {
beforeEach(function() {
bootbox.setDefaults({
size: 'small'
});
this.dialog = bootbox.dialog({
message: 'test'
});
});
it('adds the small class to the innerDialog', function() {
expect(this.dialog.children('.modal-dialog').hasClass('modal-sm')).to.be.true;
});
});
describe('when set to sm', function() {
beforeEach(function() {
bootbox.setDefaults({
size: 'sm'
});
this.dialog = bootbox.dialog({
message: 'test'
});
});
it('adds the small class to the innerDialog', function() {
expect(this.dialog.children('.modal-dialog').hasClass('modal-sm')).to.be.true;
});
});
});
describe('backdrop', function() {
describe('when set to false', function() {
beforeEach(function() {
bootbox.setDefaults({
backdrop: false
});
this.dialog = bootbox.dialog({
message: 'test'
});
});
it('does not show a backdrop', function() {
expect(this.dialog.next('.modal-backdrop').length).to.equal(0);
});
});
});
describe('centerVertical', function() {
describe('when set to true', function() {
beforeEach(function() {
bootbox.setDefaults({
centerVertical: true
});
this.dialog = bootbox.dialog({
message: 'test'
});
});
it('adds the modal-dialog-centered class to the innerDialog', function() {
expect(this.dialog.children('.modal-dialog').hasClass('modal-dialog-centered')).to.be.true;
});
});
});
describe('scrollable', function() {
describe('when set to true', function() {
beforeEach(function() {
bootbox.setDefaults({
scrollable: true
});
this.dialog = bootbox.dialog({
message: 'test'
});
});
it('adds the modal-dialog-scrollable class to the innerDialog', function() {
expect(this.dialog.children('.modal-dialog').hasClass('modal-dialog-scrollable')).to.be.true;
});
});
});
describe('when passed two arguments', function() {
beforeEach(function() {
bootbox.setDefaults('className', 'my-class');
this.dialog = bootbox.dialog({
message: 'test'
});
});
it('applies the arguments as a key/value pair', function() {
expect(this.dialog.hasClass('bootbox')).to.be.true;
expect(this.dialog.hasClass('my-class')).to.be.true;
});
});
describe('container', function () {
describe('when not explicitly set', function() {
beforeEach(function() {
this.dialog = bootbox.dialog({
message: 'test'
});
});
it('defaults to the body element', function() {
expect(this.dialog.parent().is('body')).to.be.true;
});
});
describe('when explicitly set to body', function() {
beforeEach(function() {
bootbox.setDefaults({
container: 'body'
});
this.dialog = bootbox.dialog({
message: 'test'
});
});
it('sets the correct parent element', function() {
expect(this.dialog.parent().is('body')).to.be.true;
});
});
describe('when set to another dom element', function() {
beforeEach(function() {
this.container = $('<div></div>');
bootbox.setDefaults({
container: this.container
});
this.dialog = bootbox.dialog({
message: 'test'
});
});
it('sets the correct parent element', function() {
expect(this.dialog.parent().is(this.container)).to.be.true;
});
});
});
});