/
offcanvas.spec.ts
255 lines (219 loc) · 7.93 KB
/
offcanvas.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
import {enableAutoUnmount, mount} from '@vue/test-utils'
import {afterEach, beforeEach, describe, expect, it} from 'vitest'
import BButton from '../BButton/BButton.vue'
import BCloseButton from '../BButton/BCloseButton.vue'
import BOverlay from '../BOverlay/BOverlay.vue'
import BOffcanvas from './BOffcanvas.vue'
describe.skip('offcanvas', () => {
enableAutoUnmount(afterEach)
// TODO afaik these tests are not finished
beforeEach(() => {
const el = document.createElement('div')
el.id = 'body-teleports'
document.body.appendChild(el)
})
afterEach(() => {
const el = document.getElementById('body-teleports')
if (el) document.body.removeChild(el)
})
it('has body teleports element set by teleportTo property', () => {
const wrapper = mount(BOffcanvas, {
props: {
teleportTo: '#body-teleports',
modelValue: true,
},
})
expect(wrapper.exists()).toBe(true)
expect(document.getElementById('body-teleports')?.querySelector('.offcanvas')).not.toBe(null)
})
it('has static class offcanvas', () => {
const wrapper = mount(BOffcanvas, {
props: {
modelValue: true,
},
global: {
stubs: ['b-overlay'],
},
})
const offcanvas = wrapper.find('.offcanvas')
expect(offcanvas.exists()).toBe(true)
})
it('has tabindex -1', () => {
const wrapper = mount(BOffcanvas)
const offcanvas = wrapper.get('.offcanvas')
expect(offcanvas.attributes('tabindex')).toBe('-1')
})
it('has aria-labelledby offcanvasLabel', () => {
const wrapper = mount(BOffcanvas)
const offcanvas = wrapper.get('.offcanvas')
expect(offcanvas.attributes('aria-labelledby')).toBe('offcanvasLabel')
})
it('has offcanvas-{type} when prop placement', () => {
const wrapper = mount(BOffcanvas)
const offcanvas = wrapper.get('.offcanvas')
expect(offcanvas.classes()).toContain('offcanvas-start')
})
it('has offcanvas-{type} when prop placement not default', () => {
const wrapper = mount(BOffcanvas, {
props: {placement: 'top'},
})
const offcanvas = wrapper.get('.offcanvas')
expect(offcanvas.classes()).toContain('offcanvas-top')
})
it('backdrop component exists', async () => {
const wrapper = mount(BOffcanvas, {
props: {
modelValue: true,
backdrop: false,
},
})
const $overlay = wrapper.findComponent(BOverlay)
expect($overlay.exists()).toBe(true)
})
it('has backdrop', async () => {
const wrapper = mount(BOffcanvas, {
props: {
modelValue: true,
backdrop: false,
},
})
const $overlay = wrapper.getComponent(BOverlay)
let $div = $overlay.find('div.b-overlay')
expect($div.exists()).toBe(false)
await wrapper.setProps({backdrop: true})
$div = $overlay.find('div.b-overlay')
expect($div.exists()).toBe(true)
})
it(' offcanvas-header exists', () => {
const wrapper = mount(BOffcanvas)
const offcanvas = wrapper.get('.offcanvas')
const $header = offcanvas.find('.offcanvas-header')
expect($header.exists()).toBe(true)
})
it('first child div has child h5 with static class offcanvas-title', () => {
const wrapper = mount(BOffcanvas)
const [, $div] = wrapper.findAll('div')
const $h5 = $div.get('h5')
expect($h5.classes()).toContain('offcanvas-title')
})
it('first child div has child h5 has id offcanvasLabel', () => {
const wrapper = mount(BOffcanvas)
const [, $div] = wrapper.findAll('div')
const $h5 = $div.get('h5')
expect($h5.attributes('id')).toContain('offcanvasLabel')
})
it('first child div has child h5 that has slot title', () => {
const wrapper = mount(BOffcanvas, {
slots: {title: 'foobar'},
})
const [, $div] = wrapper.findAll('div')
const $h5 = $div.get('h5')
expect($h5.text()).toBe('foobar')
})
it('first child div has child h5 that has prop title', () => {
const wrapper = mount(BOffcanvas, {
props: {title: 'foobar'},
})
const [, $div] = wrapper.findAll('div')
const $h5 = $div.get('h5')
expect($h5.text()).toBe('foobar')
})
it('first child div has child BCloseButton', () => {
const wrapper = mount(BOffcanvas)
const [, $div] = wrapper.findAll('div')
const $closebutton = $div.findComponent(BCloseButton)
expect($closebutton.exists()).toBe(true)
})
it('first child div child BCloseButton has prop type to be button', () => {
const wrapper = mount(BOffcanvas)
const [, $div] = wrapper.findAll('div')
const $closebutton = $div.getComponent(BCloseButton)
expect($closebutton.props('type')).toBe('button')
})
it('first child div child BCloseButton has static class text-reset', () => {
const wrapper = mount(BOffcanvas)
const [, $div] = wrapper.findAll('div')
const $closebutton = $div.getComponent(BCloseButton)
expect($closebutton.classes()).toContain('text-reset')
})
it('first child div child BCloseButton has prop ariaLabel to be default close', () => {
const wrapper = mount(BOffcanvas)
const [, $div] = wrapper.findAll('div')
const $closebutton = $div.getComponent(BCloseButton)
expect($closebutton.props('ariaLabel')).toBe('Close')
})
it('first child div child BCloseButton has prop ariaLabel to be prop headerCloseLabel', () => {
const wrapper = mount(BOffcanvas, {
props: {headerCloseLabel: 'foobar'},
})
const [, $div] = wrapper.findAll('div')
const $closebutton = $div.getComponent(BCloseButton)
expect($closebutton.props('ariaLabel')).toBe('foobar')
})
it('first child div child BCloseButton has class when prop headerCloseClass', () => {
const wrapper = mount(BOffcanvas, {
props: {headerCloseClass: 'foobar'},
})
const [, $div] = wrapper.findAll('div')
const $closebutton = $div.getComponent(BCloseButton)
expect($closebutton.classes()).toContain('foobar')
})
it('first child div child BCloseButton has not variant class when headerCloseVariant', () => {
const wrapper = mount(BOffcanvas, {
props: {headerCloseVariant: 'warning'},
})
const [, $div] = wrapper.findAll('div')
const $closebutton = $div.getComponent(BCloseButton)
expect($closebutton.classes()).not.toContain('btn-warning')
})
it('first child div child BButton has class when prop headerCloseClass', () => {
const wrapper = mount(BOffcanvas, {
props: {headerCloseClass: 'foobar'},
slots: {'header-close': 'foobar'},
})
const [, $div] = wrapper.findAll('div')
const $bbutton = $div.getComponent(BButton)
expect($bbutton.classes()).toContain('foobar')
})
it('first child div child BButton has variant class when headerCloseVariant', () => {
const wrapper = mount(BOffcanvas, {
props: {headerCloseVariant: 'warning'},
slots: {'header-close': 'foobar'},
})
const [, $div] = wrapper.findAll('div')
const $bbutton = $div.getComponent(BButton)
expect($bbutton.classes()).toContain('btn-warning')
})
it('second child div has static class offcanvas-body', () => {
const wrapper = mount(BOffcanvas)
const offcanvas = wrapper.find('.offcanvas')
const [, $body] = offcanvas.findAll('div')
expect($body.classes()).toContain('offcanvas-body')
})
it('second child div renders default slot', () => {
const wrapper = mount(BOffcanvas, {
slots: {default: 'foobar'},
})
const offcanvas = wrapper.find('.offcanvas')
const [, $body] = offcanvas.findAll('div')
expect($body.text()).toBe('foobar')
})
it('child body div is given prop bodyClass', () => {
const wrapper = mount(BOffcanvas, {
props: {bodyClass: 'foobar'},
})
const $body = wrapper.getComponent(BOffcanvas)
expect($body.classes()).toContain('foobar')
})
it('child body div is given prop bodyAttrs', () => {
const wrapper = mount(BOffcanvas, {
props: {
bodyAttrs: {
role: 'foo',
},
},
})
const $body = wrapper.getComponent(BOffcanvas)
expect($body.attributes()).toContain('role: "foo"')
})
})