Skip to content

Commit 2e24936

Browse files
committed
test: add select test
1 parent 2a31e08 commit 2e24936

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { mount } from '@vue/test-utils'
2+
import { asyncExpect } from '@/tests/utils'
3+
import Select from '..'
4+
import focusTest from '../../../tests/shared/focusTest'
5+
6+
describe('Select', () => {
7+
focusTest(Select)
8+
9+
it('should have default notFoundContent', async () => {
10+
const wrapper = mount(Select, {
11+
propsData: {
12+
mode: 'multiple',
13+
},
14+
sync: false,
15+
})
16+
await asyncExpect(() => {
17+
wrapper.find('.ant-select').trigger('click')
18+
})
19+
const dropdownWrapper = mount({
20+
render () {
21+
return wrapper.find({ name: 'Trigger' }).vm.getComponent()
22+
},
23+
}, { sync: false })
24+
25+
await asyncExpect(() => {
26+
expect(dropdownWrapper.findAll({ name: 'MenuItem' }).length).toBe(1)
27+
expect(dropdownWrapper.findAll({ name: 'MenuItem' }).at(0).text()).toBe('Not Found')
28+
})
29+
})
30+
31+
it('should support set notFoundContent to null', async () => {
32+
const wrapper = mount(Select, {
33+
propsData: {
34+
mode: 'multiple',
35+
notFoundContent: null,
36+
},
37+
sync: false,
38+
})
39+
await asyncExpect(() => {
40+
wrapper.find('.ant-select').trigger('click')
41+
})
42+
const dropdownWrapper = mount({
43+
render () {
44+
return wrapper.find({ name: 'Trigger' }).vm.getComponent()
45+
},
46+
}, { sync: false })
47+
await asyncExpect(() => {
48+
expect(dropdownWrapper.findAll({ name: 'MenuItem' }).length).toBe(0)
49+
})
50+
})
51+
52+
it('should not have default notFoundContent when mode is combobox', async () => {
53+
const wrapper = mount(Select, {
54+
propsData: {
55+
mode: 'combobox',
56+
},
57+
sync: false,
58+
})
59+
await asyncExpect(() => {
60+
wrapper.find('.ant-select').trigger('click')
61+
})
62+
63+
const dropdownWrapper = mount({
64+
render () {
65+
return wrapper.find({ name: 'Trigger' }).vm.getComponent()
66+
},
67+
}, { sync: false })
68+
await asyncExpect(() => {
69+
expect(dropdownWrapper.findAll('MenuItem').length).toBe(0)
70+
})
71+
})
72+
73+
it('should not have notFoundContent when mode is combobox and notFoundContent is set', async () => {
74+
const wrapper = mount(Select, {
75+
propsData: {
76+
mode: 'combobox',
77+
notFoundContent: 'not at all',
78+
},
79+
sync: false,
80+
})
81+
await asyncExpect(() => {
82+
wrapper.find('.ant-select').trigger('click')
83+
})
84+
85+
const dropdownWrapper = mount({
86+
render () {
87+
return wrapper.find({ name: 'Trigger' }).vm.getComponent()
88+
},
89+
}, { sync: false })
90+
await asyncExpect(() => {
91+
expect(dropdownWrapper.findAll({ name: 'MenuItem' }).length).toBe(1)
92+
expect(dropdownWrapper.findAll({ name: 'MenuItem' }).at(0).text()).toBe('not at all')
93+
})
94+
})
95+
})

0 commit comments

Comments
 (0)