forked from bootstrap-vue-next/bootstrap-vue-next
/
form-radio.spec.ts
593 lines (517 loc) · 19.4 KB
/
form-radio.spec.ts
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
import {afterEach, describe, expect, it} from 'vitest'
import {enableAutoUnmount, mount} from '@vue/test-utils'
import BFormRadio from './BFormRadio.vue'
describe('form-radio', () => {
enableAutoUnmount(afterEach)
it('tag is div', () => {
const wrapper = mount(BFormRadio)
expect(wrapper.element.tagName).toBe('DIV')
})
it('has class form-check if prop plain and prop button are false', () => {
const wrapper = mount(BFormRadio, {
props: {plain: false, button: false},
slots: {
default: 'checkbox',
},
})
expect(wrapper.classes()).toContain('form-check')
})
it('has class form-check if prop plain and prop button are true', () => {
const wrapper = mount(BFormRadio, {
props: {plain: true, button: true},
})
expect(wrapper.classes()).not.toContain('form-check')
})
it('does not have class form-check if prop plain false and prop button true', () => {
const wrapper = mount(BFormRadio, {
props: {plain: false, button: true},
})
expect(wrapper.classes()).not.toContain('form-check')
})
it('does not have class form-check if prop plain true and prop button false', () => {
const wrapper = mount(BFormRadio, {
props: {plain: true, button: false},
})
expect(wrapper.classes()).not.toContain('form-check')
})
it('does not have class form-check if default slot is empty', () => {
const wrapper = mount(BFormRadio, {
props: {plain: true, button: false},
})
expect(wrapper.classes()).not.toContain('form-check')
})
it('has class form-check-inline when prop inline', () => {
const wrapper = mount(BFormRadio, {
props: {inline: true},
})
expect(wrapper.classes()).toContain('form-check-inline')
})
it('has class form-check-inline when prop inline', () => {
const wrapper = mount(BFormRadio, {
props: {inline: false},
})
expect(wrapper.classes()).not.toContain('form-check-inline')
})
it('has class form-check-reverse when prop reverse', () => {
const wrapper = mount(BFormRadio, {
props: {reverse: true},
})
expect(wrapper.classes()).toContain('form-check-reverse')
})
it('does not have class form-check-reverse when prop reverse', () => {
const wrapper = mount(BFormRadio, {
props: {reverse: false},
})
expect(wrapper.classes()).not.toContain('form-check-reverse')
})
it('does not have class form-switch when prop switch is false', () => {
const wrapper = mount(BFormRadio, {
props: {switch: false},
})
expect(wrapper.classes()).not.toContain('form-switch')
})
it('has class form-control-{type} when prop size', () => {
const wrapper = mount(BFormRadio, {
props: {size: 'lg'},
})
expect(wrapper.classes()).toContain('form-control-lg')
})
it('does not have class form-control-{type} when prop size undefined', () => {
const wrapper = mount(BFormRadio, {
props: {size: undefined},
})
expect(wrapper.classes()).not.toContain('form-control-lg')
})
it('has class form-control-{type} when prop size is md', () => {
const wrapper = mount(BFormRadio, {
props: {size: 'md'},
})
expect(wrapper.classes()).not.toContain('form-control-md')
})
it('has input element', () => {
const wrapper = mount(BFormRadio)
const $input = wrapper.find('input')
expect($input.exists()).toBe(true)
})
it('input element has attr id', () => {
const wrapper = mount(BFormRadio)
const $input = wrapper.get('input')
expect($input.attributes('id')).toBeDefined()
})
it('input element attr id contains content from prop id', () => {
const wrapper = mount(BFormRadio, {
props: {id: 'foobar'},
})
const $input = wrapper.get('input')
expect($input.attributes('id')).toBe('foobar')
})
it('input element has attr type to be radio', () => {
const wrapper = mount(BFormRadio)
const $input = wrapper.get('input')
expect($input.attributes('type')).toBe('radio')
})
it('input element has class form-check-input when prop plain and prop button are false', () => {
const wrapper = mount(BFormRadio, {
props: {plain: false, button: false},
})
const $input = wrapper.get('input')
expect($input.classes()).toContain('form-check-input')
})
it('input element does not have class form-check-input when prop plain and prop button false', () => {
const wrapper = mount(BFormRadio, {
props: {plain: true, button: false},
})
const $input = wrapper.get('input')
expect($input.classes()).not.toContain('form-check-input')
})
it('input element does not have class form-check-input when prop plain false and prop button true', () => {
const wrapper = mount(BFormRadio, {
props: {plain: false, button: true},
})
const $input = wrapper.get('input')
expect($input.classes()).not.toContain('form-check-input')
})
it('input element does not have class form-check-input when prop plain and prop button are true', () => {
const wrapper = mount(BFormRadio, {
props: {plain: true, button: true},
})
const $input = wrapper.get('input')
expect($input.classes()).not.toContain('form-check-input')
})
it('input element has class form-check-input when prop plain and prop button are undefined', () => {
const wrapper = mount(BFormRadio, {
props: {plain: undefined, button: undefined},
})
const $input = wrapper.get('input')
expect($input.classes()).toContain('form-check-input')
})
it('input element has class btn-check when prop button is true', () => {
const wrapper = mount(BFormRadio, {
props: {button: true},
})
const $input = wrapper.get('input')
expect($input.classes()).toContain('btn-check')
})
it('input element does not have class btn-check when prop button is false', () => {
const wrapper = mount(BFormRadio, {
props: {button: false},
})
const $input = wrapper.get('input')
expect($input.classes()).not.toContain('btn-check')
})
it('input element does not have class btn-check when prop button is undefined', () => {
const wrapper = mount(BFormRadio, {
props: {button: undefined},
})
const $input = wrapper.get('input')
expect($input.classes()).not.toContain('btn-check')
})
it('input element has attr disabled when prop disabled', () => {
const wrapper = mount(BFormRadio, {
props: {disabled: true},
})
const $input = wrapper.get('input')
expect($input.attributes('disabled')).toBe('')
})
it('input element does not have attr disabled when prop disabled is false', () => {
const wrapper = mount(BFormRadio, {
props: {disabled: false},
})
const $input = wrapper.get('input')
expect($input.attributes('disabled')).toBeUndefined()
})
it('input element does not have attr disabled when prop disabled is undefined', () => {
const wrapper = mount(BFormRadio, {
props: {disabled: undefined},
})
const $input = wrapper.get('input')
expect($input.attributes('disabled')).toBeUndefined()
})
it('input element has attr required when prop name and prop required', () => {
const wrapper = mount(BFormRadio, {
props: {required: true, name: 'foo'},
})
const $input = wrapper.get('input')
expect($input.attributes('required')).toBe('')
})
it('input element does not have attr required when prop name is empty string and prop required', () => {
const wrapper = mount(BFormRadio, {
props: {required: true, name: ''},
})
const $input = wrapper.get('input')
expect($input.attributes('required')).toBeUndefined()
})
it('input element does not have attr required when prop name is undefined and prop required', () => {
const wrapper = mount(BFormRadio, {
props: {required: true, name: undefined},
})
const $input = wrapper.get('input')
expect($input.attributes('required')).toBeUndefined()
})
it('input element does not have attr required when prop name and prop required false', () => {
const wrapper = mount(BFormRadio, {
props: {required: false, name: 'foo'},
})
const $input = wrapper.get('input')
expect($input.attributes('required')).toBeUndefined()
})
it('input element does not have attr required when prop name and prop required undefined', () => {
const wrapper = mount(BFormRadio, {
props: {required: undefined, name: 'foo'},
})
const $input = wrapper.get('input')
expect($input.attributes('required')).toBeUndefined()
})
it('input element has attr name to be prop name', () => {
const wrapper = mount(BFormRadio, {
props: {name: 'foobar'},
})
const $input = wrapper.get('input')
expect($input.attributes('name')).toBe('foobar')
})
it('input element has attr name is undefined when prop name undefined', () => {
const wrapper = mount(BFormRadio, {
props: {name: undefined},
})
const $input = wrapper.get('input')
expect($input.attributes('name')).toBeUndefined()
})
it('input element has attr form to be prop form', () => {
const wrapper = mount(BFormRadio, {
props: {form: 'foobar'},
})
const $input = wrapper.get('input')
expect($input.attributes('form')).toBe('foobar')
})
it('input element has attr form is undefined when prop form undefined', () => {
const wrapper = mount(BFormRadio, {
props: {form: undefined},
})
const $input = wrapper.get('input')
expect($input.attributes('form')).toBeUndefined()
})
it('input element has attr aria-label to be prop ariaLabel', () => {
const wrapper = mount(BFormRadio, {
props: {ariaLabel: 'foobar'},
})
const $input = wrapper.get('input')
expect($input.attributes('aria-label')).toBe('foobar')
})
it('input element has attr aria-label is undefined when prop ariaLabel undefined', () => {
const wrapper = mount(BFormRadio, {
props: {ariaLabel: undefined},
})
const $input = wrapper.get('input')
expect($input.attributes('aria-label')).toBeUndefined()
})
it('input element has attr aria-labelledby to be prop ariaLabelledby', () => {
const wrapper = mount(BFormRadio, {
props: {ariaLabelledby: 'foobar'},
})
const $input = wrapper.get('input')
expect($input.attributes('aria-labelledby')).toBe('foobar')
})
it('input element has attr aria-labelledby is undefined when prop ariaLabelledby undefined', () => {
const wrapper = mount(BFormRadio, {
props: {ariaLabelledby: undefined},
})
const $input = wrapper.get('input')
expect($input.attributes('aria-labelledby')).toBeUndefined()
})
it('input element has attr aria-labelledby is undefined when prop ariaLabelledby undefined', () => {
const wrapper = mount(BFormRadio, {
props: {ariaLabelledby: undefined},
})
const $input = wrapper.get('input')
expect($input.attributes('aria-labelledby')).toBeUndefined()
})
it('input element has attr value to be prop value', () => {
const wrapper = mount(BFormRadio, {
props: {value: 'foobar'},
})
const $input = wrapper.get('input')
expect($input.attributes('value')).toBe('foobar')
})
it('input element has attr value to be true when value is undefined', () => {
const wrapper = mount(BFormRadio, {
props: {value: undefined},
})
const $input = wrapper.get('input')
expect($input.attributes('value')).toBe('true')
})
it('input element aria-required when prop name and prop required true', () => {
const wrapper = mount(BFormRadio, {
props: {name: 'foo', required: true},
})
const $input = wrapper.get('input')
expect($input.attributes('aria-required')).toBe('true')
})
it('input element does not have aria-required when prop name is empty string and prop required true', () => {
const wrapper = mount(BFormRadio, {
props: {name: '', required: true},
})
const $input = wrapper.get('input')
expect($input.attributes('aria-required')).toBeUndefined()
})
it('input element does not have aria-required when prop name and prop required false', () => {
const wrapper = mount(BFormRadio, {
props: {name: 'foo', required: false},
})
const $input = wrapper.get('input')
expect($input.attributes('aria-required')).toBeUndefined()
})
it('has child label by default', () => {
const wrapper = mount(BFormRadio)
const $label = wrapper.find('label')
expect($label.exists()).toBe(true)
})
it('does not have child label when prop plain is true', () => {
const wrapper = mount(BFormRadio, {
props: {plain: true},
})
const $label = wrapper.find('label')
expect($label.exists()).toBe(false)
})
it('has child label when prop plain is false', () => {
const wrapper = mount(BFormRadio, {
props: {plain: false},
})
const $label = wrapper.find('label')
expect($label.exists()).toBe(true)
})
it('has child label when prop plain is false but has default slot', () => {
const wrapper = mount(BFormRadio, {
props: {plain: false},
slots: {default: 'foobar'},
})
const $label = wrapper.find('label')
expect($label.exists()).toBe(true)
})
it('has child label when prop plain is true but has default slot', () => {
const wrapper = mount(BFormRadio, {
props: {plain: true},
slots: {default: 'foobar'},
})
const $label = wrapper.find('label')
expect($label.exists()).toBe(true)
})
it('child label has attr for to be defined by default', () => {
const wrapper = mount(BFormRadio, {
props: {plain: false},
})
const $label = wrapper.get('label')
expect($label.attributes('for')).toBeDefined()
})
it('child label has attr for is prop id', () => {
const wrapper = mount(BFormRadio, {
props: {plain: false, id: 'foobar'},
})
const $label = wrapper.get('label')
expect($label.attributes('for')).toBe('foobar')
})
it('child label attr for is same as input id', () => {
const wrapper = mount(BFormRadio, {
props: {plain: false},
})
const $label = wrapper.get('label')
const $input = wrapper.get('input')
const $labelFor = $label.attributes('for')
const $inputId = $input.attributes('id')
expect($labelFor).toBe($inputId)
})
it('child label does not have class focus by default', () => {
const wrapper = mount(BFormRadio, {
props: {plain: false},
})
const $label = wrapper.get('label')
expect($label.classes()).not.toContain('focus')
})
it('child label removes class focus when input is blurred after focus', async () => {
const wrapper = mount(BFormRadio, {
props: {plain: false},
})
const $label = wrapper.get('label')
const $input = wrapper.get('input')
await $input.trigger('focus')
await $input.trigger('blur')
expect($label.classes()).not.toContain('focus')
})
it('child label has class form-check-label when prop plain and prop button are false', () => {
const wrapper = mount(BFormRadio, {
props: {plain: false, button: false},
})
const $label = wrapper.get('label')
expect($label.classes()).toContain('form-check-label')
})
it('child label has class form-check-label when prop plain and prop button are false', () => {
const wrapper = mount(BFormRadio, {
props: {plain: false, button: false},
})
const $label = wrapper.get('label')
expect($label.classes()).toContain('form-check-label')
})
it('child label does not have class form-check-label when prop plain true and prop button false', () => {
const wrapper = mount(BFormRadio, {
props: {plain: true, button: false},
slots: {default: 'foo'},
})
const $label = wrapper.get('label')
expect($label.classes()).not.toContain('form-check-label')
})
it('child label does not have class form-check-label when prop plain false and prop button true', () => {
const wrapper = mount(BFormRadio, {
props: {plain: false, button: true},
slots: {default: 'foo'},
})
const $label = wrapper.get('label')
expect($label.classes()).not.toContain('form-check-label')
})
it('child label does not have class form-check-label when prop plain and prop button are true', () => {
const wrapper = mount(BFormRadio, {
props: {plain: true, button: true},
slots: {default: 'foo'},
})
const $label = wrapper.get('label')
expect($label.classes()).not.toContain('form-check-label')
})
it('child label has class btn when prop button', () => {
const wrapper = mount(BFormRadio, {
props: {button: true, plain: false},
})
const $label = wrapper.get('label')
expect($label.classes()).toContain('btn')
})
it('child label does not have class btn when prop button false', () => {
const wrapper = mount(BFormRadio, {
props: {button: false, plain: false},
})
const $label = wrapper.get('label')
expect($label.classes()).not.toContain('btn')
})
it('child label has class btn-{type} when prop button and prop buttonVariant', () => {
const wrapper = mount(BFormRadio, {
props: {button: true, buttonVariant: 'danger', plain: false},
})
const $label = wrapper.get('label')
expect($label.classes()).toContain('btn-danger')
})
it('child label does not have class btn-{type} when prop button false and prop buttonVariant', () => {
const wrapper = mount(BFormRadio, {
props: {button: false, buttonVariant: 'danger', plain: false},
})
const $label = wrapper.get('label')
expect($label.classes()).not.toContain('btn-danger')
})
it('child label does not have class btn-{type} when prop button true and prop buttonVariant undefined', () => {
const wrapper = mount(BFormRadio, {
props: {button: true, buttonVariant: undefined, plain: false},
})
const $label = wrapper.get('label')
expect($label.classes()).not.toContain('btn-undefined')
})
it('child label has class btn-{type} when prop button and prop size', () => {
const wrapper = mount(BFormRadio, {
props: {button: true, size: 'lg', plain: false},
})
const $label = wrapper.get('label')
expect($label.classes()).toContain('btn-lg')
})
it('child label does not have class btn-{type} when prop button false and prop size', () => {
const wrapper = mount(BFormRadio, {
props: {button: false, size: 'lg', plain: false},
})
const $label = wrapper.get('label')
expect($label.classes()).not.toContain('btn-lg')
})
it('child label does not have class btn-{type} when prop button true and prop size undefined', () => {
const wrapper = mount(BFormRadio, {
props: {button: true, size: undefined, plain: false},
})
const $label = wrapper.get('label')
expect($label.classes()).not.toContain('btn-undefined')
})
it('child label does not have class btn-md when prop button true and prop size md', () => {
const wrapper = mount(BFormRadio, {
props: {button: true, size: 'md', plain: false},
})
const $label = wrapper.get('label')
expect($label.classes()).not.toContain('btn-md')
})
it('child label has class active when value and modelValue are not the same', () => {
const wrapper = mount(BFormRadio, {
props: {plain: false, value: 'foo1', modelValue: 'foo'},
})
const $label = wrapper.get('label')
expect($label.classes()).not.toContain('active')
})
it('child label renders default slot', () => {
const wrapper = mount(BFormRadio, {
slots: {default: 'foobar'},
})
const $label = wrapper.get('label')
expect($label.text()).toBe('foobar')
})
// TODO onMounted events
// TODO localValue change emit events
// TODO input element has v-model, not sure how this works. Does it bind to value??
})