form-select-option-group.spec.js
4.57 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
import { mount } from '@vue/test-utils'
import { BFormSelectOptionGroup } from './form-select-option-group'
describe('form-select-option-group', () => {
afterAll(() => {
console.warn.mockClear()
})
it('has expected default structure', async () => {
const wrapper = mount(BFormSelectOptionGroup, {
propsData: {
label: 'foo'
}
})
expect(wrapper.element.tagName).toBe('OPTGROUP')
expect(wrapper.attributes('label')).toBeDefined()
expect(wrapper.attributes('label')).toEqual('foo')
expect(wrapper.text()).toEqual('')
wrapper.destroy()
})
it('has option elements from simple options array', async () => {
const wrapper = mount(BFormSelectOptionGroup, {
propsData: {
label: 'foo',
options: ['one', 'two', 'three']
}
})
expect(wrapper.element.tagName).toBe('OPTGROUP')
expect(wrapper.attributes('label')).toBeDefined()
expect(wrapper.attributes('label')).toEqual('foo')
const $options = wrapper.findAll('option')
expect($options.length).toBe(3)
expect($options.at(0).text()).toBe('one')
expect($options.at(1).text()).toBe('two')
expect($options.at(2).text()).toBe('three')
expect($options.at(0).attributes('value')).toBe('one')
expect($options.at(1).attributes('value')).toBe('two')
expect($options.at(2).attributes('value')).toBe('three')
expect($options.wrappers.every(o => o.find('[disabled]').exists())).toBe(false)
wrapper.destroy()
})
it('has option elements from options array of objects', async () => {
const wrapper = mount(BFormSelectOptionGroup, {
propsData: {
label: 'foo',
options: [
{ text: 'one', value: 1 },
{ text: 'two', value: 2, disabled: true },
{ text: 'three', value: 3 }
]
}
})
expect(wrapper.element.tagName).toBe('OPTGROUP')
expect(wrapper.attributes('label')).toBeDefined()
expect(wrapper.attributes('label')).toEqual('foo')
const $options = wrapper.findAll('option')
expect($options.length).toBe(3)
expect($options.at(0).text()).toBe('one')
expect($options.at(1).text()).toBe('two')
expect($options.at(2).text()).toBe('three')
expect($options.at(0).attributes('value')).toBe('1')
expect($options.at(1).attributes('value')).toBe('2')
expect($options.at(2).attributes('value')).toBe('3')
expect($options.at(0).element.matches('[disabled]')).toBe(false)
expect($options.at(1).element.matches('[disabled]')).toBe(true)
expect($options.at(2).element.matches('[disabled]')).toBe(false)
wrapper.destroy()
})
it('has option elements from options legacy object format', async () => {
const spyWarn = jest.spyOn(console, 'warn').mockImplementationOnce(() => {})
const wrapper = mount(BFormSelectOptionGroup, {
propsData: {
label: 'foo',
options: { one: 1, two: { value: 2, text: 'Two' }, three: 'three' }
}
})
expect(wrapper.element.tagName).toBe('OPTGROUP')
expect(wrapper.attributes('label')).toBeDefined()
expect(wrapper.attributes('label')).toEqual('foo')
const $options = wrapper.findAll('option')
expect($options.length).toBe(3)
expect($options.at(0).text()).toBe('1')
expect($options.at(1).text()).toBe('Two')
expect($options.at(2).text()).toBe('three')
expect($options.at(0).attributes('value')).toBe('one')
expect($options.at(1).attributes('value')).toBe('2')
expect($options.at(2).attributes('value')).toBe('three')
expect(spyWarn).toHaveBeenCalledWith(
'[BootstrapVue warn]: BFormSelectOptionGroup - Setting prop "options" to an object is deprecated. Use the array format instead.'
)
wrapper.destroy()
})
it('has option elements from default slot', async () => {
const wrapper = mount(BFormSelectOptionGroup, {
propsData: {
label: 'foo'
},
slots: {
default: [
'<option value="1">one</option>',
'<option value="2">two</option>',
'<option value="3">three</option>'
]
}
})
expect(wrapper.element.tagName).toBe('OPTGROUP')
expect(wrapper.attributes('label')).toBeDefined()
expect(wrapper.attributes('label')).toEqual('foo')
const $options = wrapper.findAll('option')
expect($options.length).toBe(3)
expect($options.at(0).text()).toBe('one')
expect($options.at(1).text()).toBe('two')
expect($options.at(2).text()).toBe('three')
expect($options.at(0).attributes('value')).toBe('1')
expect($options.at(1).attributes('value')).toBe('2')
expect($options.at(2).attributes('value')).toBe('3')
wrapper.destroy()
})
})