2020-10-03 19:07:02 +08:00
|
|
|
import { nextTick } from 'vue'
|
2021-08-24 13:36:48 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
|
|
|
import { sleep } from '@element-plus/test-utils'
|
2021-03-24 22:54:35 +08:00
|
|
|
import { EVENT_CODE } from '@element-plus/utils/aria'
|
2021-11-12 14:27:51 +08:00
|
|
|
import { CircleClose, ArrowUp, CaretTop } from '@element-plus/icons'
|
2020-10-03 19:07:02 +08:00
|
|
|
import Select from '../src/select.vue'
|
2021-03-04 20:57:43 +08:00
|
|
|
import Group from '../src/option-group.vue'
|
2020-10-03 19:07:02 +08:00
|
|
|
import Option from '../src/option.vue'
|
|
|
|
|
2021-01-31 18:47:52 +08:00
|
|
|
jest.useFakeTimers()
|
|
|
|
|
2020-10-03 19:07:02 +08:00
|
|
|
interface SelectProps {
|
|
|
|
filterMethod?: any
|
|
|
|
remoteMethod?: any
|
|
|
|
multiple?: boolean
|
|
|
|
clearable?: boolean
|
|
|
|
filterable?: boolean
|
|
|
|
allowCreate?: boolean
|
|
|
|
remote?: boolean
|
|
|
|
collapseTags?: boolean
|
|
|
|
automaticDropdown?: boolean
|
|
|
|
multipleLimit?: number
|
|
|
|
popperClass?: string
|
2021-07-24 11:41:23 +08:00
|
|
|
defaultFirstOption?: boolean
|
2021-10-30 21:34:19 +08:00
|
|
|
fitInputWidth?: boolean
|
2020-10-03 19:07:02 +08:00
|
|
|
}
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
const _mount = (template: string, data: any = () => ({}), otherObj?) =>
|
|
|
|
mount(
|
|
|
|
{
|
|
|
|
components: {
|
|
|
|
'el-select': Select,
|
|
|
|
'el-option': Option,
|
|
|
|
'el-group-option': Group,
|
|
|
|
},
|
|
|
|
template,
|
|
|
|
data,
|
|
|
|
...otherObj,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
attachTo: 'body',
|
|
|
|
}
|
|
|
|
)
|
2020-10-03 19:07:02 +08:00
|
|
|
|
|
|
|
function getOptions(): HTMLElement[] {
|
2021-09-04 19:29:28 +08:00
|
|
|
return Array.from(
|
|
|
|
document.querySelectorAll<HTMLElement>(
|
|
|
|
'body > div:last-child .el-select-dropdown__item'
|
|
|
|
)
|
|
|
|
)
|
2020-10-03 19:07:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const getSelectVm = (configs: SelectProps = {}, options?) => {
|
2021-09-04 19:29:28 +08:00
|
|
|
;[
|
|
|
|
'multiple',
|
|
|
|
'clearable',
|
|
|
|
'defaultFirstOption',
|
|
|
|
'filterable',
|
|
|
|
'allowCreate',
|
|
|
|
'remote',
|
|
|
|
'collapseTags',
|
|
|
|
'automaticDropdown',
|
2021-10-30 21:34:19 +08:00
|
|
|
'fitInputWidth',
|
2021-09-04 19:29:28 +08:00
|
|
|
].forEach((config) => {
|
2020-10-03 19:07:02 +08:00
|
|
|
configs[config] = configs[config] || false
|
|
|
|
})
|
|
|
|
configs.multipleLimit = configs.multipleLimit || 0
|
|
|
|
if (!options) {
|
2021-09-04 19:29:28 +08:00
|
|
|
options = [
|
|
|
|
{
|
|
|
|
value: '选项1',
|
|
|
|
label: '黄金糕',
|
|
|
|
disabled: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项2',
|
|
|
|
label: '双皮奶',
|
|
|
|
disabled: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项3',
|
|
|
|
label: '蚵仔煎',
|
|
|
|
disabled: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项4',
|
|
|
|
label: '龙须面',
|
|
|
|
disabled: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项5',
|
|
|
|
label: '北京烤鸭',
|
|
|
|
disabled: false,
|
|
|
|
},
|
|
|
|
]
|
2020-10-03 19:07:02 +08:00
|
|
|
}
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
return _mount(
|
|
|
|
`
|
2020-10-03 19:07:02 +08:00
|
|
|
<el-select
|
|
|
|
ref="select"
|
|
|
|
v-model="value"
|
|
|
|
:multiple="multiple"
|
|
|
|
:multiple-limit="multipleLimit"
|
|
|
|
:popper-class="popperClass"
|
|
|
|
:clearable="clearable"
|
2021-07-24 11:41:23 +08:00
|
|
|
:default-first-option="defaultFirstOption"
|
2020-10-03 19:07:02 +08:00
|
|
|
:filterable="filterable"
|
|
|
|
:collapse-tags="collapseTags"
|
|
|
|
:allow-create="allowCreate"
|
|
|
|
:filterMethod="filterMethod"
|
|
|
|
:remote="remote"
|
|
|
|
:loading="loading"
|
|
|
|
:remoteMethod="remoteMethod"
|
2021-10-30 21:34:19 +08:00
|
|
|
:automatic-dropdown="automaticDropdown"
|
|
|
|
:fit-input-width="fitInputWidth">
|
2020-10-03 19:07:02 +08:00
|
|
|
<el-option
|
|
|
|
v-for="item in options"
|
|
|
|
:label="item.label"
|
|
|
|
:key="item.value"
|
|
|
|
:disabled="item.disabled"
|
|
|
|
:value="item.value">
|
|
|
|
</el-option>
|
|
|
|
</el-select>
|
2021-09-04 19:29:28 +08:00
|
|
|
`,
|
|
|
|
() => ({
|
|
|
|
options,
|
|
|
|
multiple: configs.multiple,
|
|
|
|
multipleLimit: configs.multipleLimit,
|
|
|
|
clearable: configs.clearable,
|
|
|
|
defaultFirstOption: configs.defaultFirstOption,
|
|
|
|
filterable: configs.filterable,
|
|
|
|
collapseTags: configs.collapseTags,
|
|
|
|
allowCreate: configs.allowCreate,
|
|
|
|
popperClass: configs.popperClass,
|
|
|
|
automaticDropdown: configs.automaticDropdown,
|
2021-10-30 21:34:19 +08:00
|
|
|
fitInputWidth: configs.fitInputWidth,
|
2021-09-04 19:29:28 +08:00
|
|
|
loading: false,
|
|
|
|
filterMethod: configs.filterMethod,
|
|
|
|
remote: configs.remote,
|
|
|
|
remoteMethod: configs.remoteMethod,
|
|
|
|
value: configs.multiple ? [] : '',
|
|
|
|
})
|
|
|
|
)
|
2020-10-03 19:07:02 +08:00
|
|
|
}
|
|
|
|
|
2021-07-14 15:01:00 +08:00
|
|
|
const getGroupSelectVm = (configs: SelectProps = {}, options?) => {
|
2021-09-04 19:29:28 +08:00
|
|
|
;[
|
|
|
|
'multiple',
|
|
|
|
'clearable',
|
|
|
|
'filterable',
|
|
|
|
'allowCreate',
|
|
|
|
'remote',
|
|
|
|
'collapseTags',
|
|
|
|
'automaticDropdown',
|
2021-10-30 21:34:19 +08:00
|
|
|
'fitInputWidth',
|
2021-09-04 19:29:28 +08:00
|
|
|
].forEach((config) => {
|
2021-07-14 15:01:00 +08:00
|
|
|
configs[config] = configs[config] || false
|
|
|
|
})
|
|
|
|
configs.multipleLimit = configs.multipleLimit || 0
|
|
|
|
if (!options) {
|
2021-09-04 19:29:28 +08:00
|
|
|
options = [
|
|
|
|
{
|
|
|
|
label: 'Australia',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
value: 'Sydney',
|
|
|
|
label: 'Sydney',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'Melbourne',
|
|
|
|
label: 'Melbourne',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'China',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
value: 'Shanghai',
|
|
|
|
label: 'Shanghai',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'Shenzhen',
|
|
|
|
label: 'Shenzhen',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'Guangzhou',
|
|
|
|
label: 'Guangzhou',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'Dalian',
|
|
|
|
label: 'Dalian',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'India',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
value: 'Mumbai',
|
|
|
|
label: 'Mumbai',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'Delhi',
|
|
|
|
label: 'Delhi',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'Bangalore',
|
|
|
|
label: 'Bangalore',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Indonesia',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
value: 'Bandung',
|
|
|
|
label: 'Bandung',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'Jakarta',
|
|
|
|
label: 'Jakarta',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]
|
2021-07-14 15:01:00 +08:00
|
|
|
}
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
return _mount(
|
|
|
|
`
|
2021-07-14 15:01:00 +08:00
|
|
|
<el-select
|
|
|
|
ref="select"
|
|
|
|
v-model="value"
|
|
|
|
:multiple="multiple"
|
|
|
|
:multiple-limit="multipleLimit"
|
|
|
|
:popper-class="popperClass"
|
|
|
|
:clearable="clearable"
|
|
|
|
:filterable="filterable"
|
|
|
|
:collapse-tags="collapseTags"
|
|
|
|
:allow-create="allowCreate"
|
|
|
|
:filterMethod="filterMethod"
|
|
|
|
:remote="remote"
|
|
|
|
:loading="loading"
|
|
|
|
:remoteMethod="remoteMethod"
|
2021-10-30 21:34:19 +08:00
|
|
|
:automatic-dropdown="automaticDropdown"
|
|
|
|
:fit-input-width="fitInputWidth">
|
2021-07-14 15:01:00 +08:00
|
|
|
<el-group-option
|
|
|
|
v-for="group in options"
|
|
|
|
:key="group.label"
|
|
|
|
:label="group.label">
|
|
|
|
<el-option
|
|
|
|
v-for="item in group.options"
|
|
|
|
:key="item.value"
|
|
|
|
:label="item.label"
|
|
|
|
:value="item.value"/>
|
|
|
|
</el-group-option>
|
|
|
|
</el-select>
|
|
|
|
<script>
|
|
|
|
import ElOptionGroup from './option-group'
|
|
|
|
export default {
|
|
|
|
components: { ElOptionGroup }
|
|
|
|
}
|
2021-09-04 19:29:28 +08:00
|
|
|
</script>`,
|
|
|
|
() => ({
|
|
|
|
options,
|
|
|
|
multiple: configs.multiple,
|
|
|
|
multipleLimit: configs.multipleLimit,
|
|
|
|
clearable: configs.clearable,
|
|
|
|
filterable: configs.filterable,
|
|
|
|
collapseTags: configs.collapseTags,
|
|
|
|
allowCreate: configs.allowCreate,
|
|
|
|
popperClass: configs.popperClass,
|
|
|
|
automaticDropdown: configs.automaticDropdown,
|
2021-10-30 21:34:19 +08:00
|
|
|
fitInputWidth: configs.fitInputWidth,
|
2021-09-04 19:29:28 +08:00
|
|
|
loading: false,
|
|
|
|
filterMethod: configs.filterMethod,
|
|
|
|
remote: configs.remote,
|
|
|
|
remoteMethod: configs.remoteMethod,
|
|
|
|
value: configs.multiple ? [] : '',
|
|
|
|
})
|
|
|
|
)
|
2021-07-14 15:01:00 +08:00
|
|
|
}
|
|
|
|
|
2020-10-03 19:07:02 +08:00
|
|
|
describe('Select', () => {
|
2020-12-04 13:39:01 +08:00
|
|
|
afterEach(() => {
|
|
|
|
document.body.innerHTML = ''
|
|
|
|
})
|
2021-03-11 20:32:36 +08:00
|
|
|
|
2020-10-03 19:07:02 +08:00
|
|
|
test('create', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(`<el-select v-model="value"></el-select>`, () => ({
|
|
|
|
value: '',
|
|
|
|
}))
|
2020-10-03 19:07:02 +08:00
|
|
|
expect(wrapper.classes()).toContain('el-select')
|
|
|
|
expect(wrapper.find('.el-input__inner').element.placeholder).toBe('Select')
|
|
|
|
const select = wrapper.findComponent({ name: 'ElSelect' })
|
|
|
|
wrapper.trigger('click')
|
|
|
|
expect((select.vm as any).visible).toBe(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('options rendered correctly', () => {
|
|
|
|
const wrapper = getSelectVm()
|
2021-09-04 19:29:28 +08:00
|
|
|
const options = wrapper.element.querySelectorAll(
|
|
|
|
'.el-select-dropdown__item'
|
|
|
|
)
|
2020-10-03 19:07:02 +08:00
|
|
|
const result = [].every.call(options, (option, index) => {
|
|
|
|
const text = option.querySelector('span').textContent
|
|
|
|
const vm = wrapper.vm as any
|
|
|
|
return text === vm.options[index].label
|
|
|
|
})
|
|
|
|
expect(result).toBe(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('custom dropdown class', () => {
|
|
|
|
const wrapper = getSelectVm({ popperClass: 'custom-dropdown' })
|
|
|
|
const dropdown = wrapper.findComponent({ name: 'ElSelectDropdown' })
|
|
|
|
expect(dropdown.classes()).toContain('custom-dropdown')
|
|
|
|
})
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
test('default value', async () => {
|
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
2020-10-03 19:07:02 +08:00
|
|
|
<el-select v-model="value">
|
|
|
|
<el-option
|
|
|
|
v-for="item in options"
|
|
|
|
:label="item.label"
|
|
|
|
:key="item.value"
|
|
|
|
:value="item.value">
|
|
|
|
</el-option>
|
|
|
|
</el-select>
|
|
|
|
`,
|
2021-09-04 19:29:28 +08:00
|
|
|
() => ({
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
value: '选项1',
|
|
|
|
label: '黄金糕',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项2',
|
|
|
|
label: '双皮奶',
|
|
|
|
},
|
|
|
|
],
|
2020-10-03 19:07:02 +08:00
|
|
|
value: '选项2',
|
2021-09-04 19:29:28 +08:00
|
|
|
})
|
|
|
|
)
|
2020-10-03 19:07:02 +08:00
|
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(wrapper.find('.el-input__inner').element.value).toBe('双皮奶')
|
|
|
|
})
|
|
|
|
|
2021-02-27 16:03:06 +08:00
|
|
|
test('sync set value and options', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
2021-02-27 16:03:06 +08:00
|
|
|
<el-select v-model="value">
|
|
|
|
<el-option
|
|
|
|
v-for="item in options"
|
|
|
|
:label="item.label"
|
|
|
|
:key="item.value"
|
|
|
|
:value="item.value">
|
|
|
|
</el-option>
|
|
|
|
</el-select>
|
|
|
|
`,
|
2021-09-04 19:29:28 +08:00
|
|
|
() => ({
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
value: '选项1',
|
|
|
|
label: '黄金糕',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项2',
|
|
|
|
label: '双皮奶',
|
|
|
|
},
|
|
|
|
],
|
2021-02-27 16:03:06 +08:00
|
|
|
value: '选项2',
|
2021-09-04 19:29:28 +08:00
|
|
|
})
|
|
|
|
)
|
2021-02-27 16:03:06 +08:00
|
|
|
const vm = wrapper.vm as any
|
2021-09-04 19:29:28 +08:00
|
|
|
vm.options = [
|
|
|
|
{
|
|
|
|
value: '选项1',
|
|
|
|
label: '黄金糕',
|
|
|
|
},
|
|
|
|
]
|
2021-02-27 16:03:06 +08:00
|
|
|
vm.value = '选项1'
|
|
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(wrapper.find('.el-input__inner').element.value).toBe('黄金糕')
|
|
|
|
})
|
|
|
|
|
2020-10-03 19:07:02 +08:00
|
|
|
test('single select', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
2020-10-03 19:07:02 +08:00
|
|
|
<el-select v-model="value" @change="handleChange">
|
|
|
|
<el-option
|
|
|
|
v-for="item in options"
|
|
|
|
:label="item.label"
|
|
|
|
:key="item.value"
|
|
|
|
:value="item.value">
|
|
|
|
<p>{{item.label}} {{item.value}}</p>
|
|
|
|
</el-option>
|
|
|
|
</el-select>
|
|
|
|
`,
|
2021-09-04 19:29:28 +08:00
|
|
|
() => ({
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
value: '选项1',
|
|
|
|
label: '黄金糕',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项2',
|
|
|
|
label: '双皮奶',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项3',
|
|
|
|
label: '蚵仔煎',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项4',
|
|
|
|
label: '龙须面',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项5',
|
|
|
|
label: '北京烤鸭',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
value: '',
|
|
|
|
count: 0,
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
methods: {
|
|
|
|
handleChange() {
|
|
|
|
this.count++
|
|
|
|
},
|
2020-10-03 19:07:02 +08:00
|
|
|
},
|
2021-09-04 19:29:28 +08:00
|
|
|
}
|
|
|
|
)
|
2020-10-03 19:07:02 +08:00
|
|
|
|
|
|
|
await wrapper.find('.select-trigger').trigger('click')
|
|
|
|
const options = getOptions()
|
|
|
|
const vm = wrapper.vm as any
|
|
|
|
expect(vm.value).toBe('')
|
2020-12-31 15:55:51 +08:00
|
|
|
expect(wrapper.find('.el-input__inner').element.value).toBe('')
|
2020-10-03 19:07:02 +08:00
|
|
|
options[2].click()
|
|
|
|
await nextTick()
|
|
|
|
expect(vm.value).toBe('选项3')
|
2020-12-31 15:55:51 +08:00
|
|
|
expect(wrapper.find('.el-input__inner').element.value).toBe('蚵仔煎')
|
2020-10-03 19:07:02 +08:00
|
|
|
expect(vm.count).toBe(1)
|
|
|
|
options[4].click()
|
2020-12-31 15:55:51 +08:00
|
|
|
await nextTick()
|
2020-10-03 19:07:02 +08:00
|
|
|
expect(vm.value).toBe('选项5')
|
2020-12-31 15:55:51 +08:00
|
|
|
expect(wrapper.find('.el-input__inner').element.value).toBe('北京烤鸭')
|
2020-10-03 19:07:02 +08:00
|
|
|
expect(vm.count).toBe(2)
|
|
|
|
})
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
test('disabled option', async () => {
|
2020-10-03 19:07:02 +08:00
|
|
|
const wrapper = getSelectVm()
|
|
|
|
const vm = wrapper.vm as any
|
|
|
|
wrapper.find('.select-trigger').trigger('click')
|
|
|
|
vm.options[1].disabled = true
|
|
|
|
await nextTick()
|
|
|
|
const options = getOptions()
|
|
|
|
expect(options[1].className).toContain('is-disabled')
|
|
|
|
options[1].click()
|
|
|
|
await nextTick()
|
|
|
|
expect(vm.value).toBe('')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('disabled select', () => {
|
|
|
|
const wrapper = _mount(`<el-select disabled></el-select>`)
|
|
|
|
expect(wrapper.find('.el-input').classes()).toContain('is-disabled')
|
|
|
|
})
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
test('visible event', async () => {
|
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
2020-10-03 19:07:02 +08:00
|
|
|
<el-select v-model="value" @visible-change="handleVisibleChange">
|
|
|
|
<el-option
|
|
|
|
v-for="item in options"
|
|
|
|
:label="item.label"
|
|
|
|
:key="item.value"
|
|
|
|
:value="item.value">
|
|
|
|
</el-option>
|
|
|
|
</el-select>`,
|
2021-09-04 19:29:28 +08:00
|
|
|
() => ({
|
|
|
|
options: [],
|
|
|
|
value: '',
|
|
|
|
visible: '',
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
methods: {
|
|
|
|
handleVisibleChange(val) {
|
|
|
|
this.visible = val
|
|
|
|
},
|
2020-10-03 19:07:02 +08:00
|
|
|
},
|
2021-09-04 19:29:28 +08:00
|
|
|
}
|
|
|
|
)
|
2020-10-03 19:07:02 +08:00
|
|
|
const select = wrapper.findComponent({ name: 'ElSelect' })
|
|
|
|
const vm = wrapper.vm as any
|
|
|
|
const selectVm = select.vm as any
|
|
|
|
selectVm.visible = true
|
|
|
|
await selectVm.$nextTick()
|
|
|
|
expect(vm.visible).toBe(true)
|
|
|
|
})
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
test('keyboard operations', async () => {
|
2020-10-03 19:07:02 +08:00
|
|
|
const wrapper = getSelectVm()
|
|
|
|
const select = wrapper.findComponent({ name: 'ElSelect' })
|
|
|
|
const vm = select.vm as any
|
|
|
|
let i = 8
|
|
|
|
while (i--) {
|
|
|
|
vm.navigateOptions('next')
|
|
|
|
}
|
|
|
|
vm.navigateOptions('prev')
|
2021-07-13 09:42:13 +08:00
|
|
|
vm.navigateOptions('prev')
|
|
|
|
vm.navigateOptions('prev')
|
2020-10-03 19:07:02 +08:00
|
|
|
await vm.$nextTick()
|
2021-07-13 09:42:13 +08:00
|
|
|
expect(vm.hoverIndex).toBe(3)
|
2020-10-03 19:07:02 +08:00
|
|
|
vm.selectOption()
|
|
|
|
await vm.$nextTick()
|
2021-07-13 09:42:13 +08:00
|
|
|
expect((wrapper.vm as any).value).toBe('选项4')
|
|
|
|
vm.toggleMenu()
|
|
|
|
const timer = sleep(300)
|
|
|
|
jest.runAllTimers()
|
|
|
|
await timer
|
|
|
|
vm.toggleMenu()
|
|
|
|
await vm.$nextTick
|
|
|
|
expect(vm.hoverIndex).toBe(3)
|
2020-10-03 19:07:02 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('clearable', async () => {
|
|
|
|
const wrapper = getSelectVm({ clearable: true })
|
|
|
|
const select = wrapper.findComponent({ name: 'ElSelect' })
|
|
|
|
const vm = wrapper.vm as any
|
|
|
|
const selectVm = select.vm as any
|
|
|
|
vm.value = '选项1'
|
|
|
|
await vm.$nextTick()
|
|
|
|
selectVm.inputHovering = true
|
|
|
|
await selectVm.$nextTick()
|
2021-10-27 23:17:13 +08:00
|
|
|
const iconClear = wrapper.findComponent(CircleClose)
|
2020-10-03 19:07:02 +08:00
|
|
|
expect(iconClear.exists()).toBe(true)
|
|
|
|
await iconClear.trigger('click')
|
|
|
|
expect(vm.value).toBe('')
|
|
|
|
})
|
|
|
|
|
2021-11-12 14:27:51 +08:00
|
|
|
test('suffix icon', async () => {
|
|
|
|
const wrapper = _mount(`<el-select></el-select>`)
|
|
|
|
let suffixIcon = wrapper.findComponent(ArrowUp)
|
|
|
|
expect(suffixIcon.exists()).toBe(true)
|
|
|
|
await wrapper.setProps({ suffixIcon: CaretTop })
|
|
|
|
suffixIcon = wrapper.findComponent(CaretTop)
|
|
|
|
expect(suffixIcon.exists()).toBe(true)
|
|
|
|
})
|
|
|
|
|
2021-10-30 21:34:19 +08:00
|
|
|
test('fitInputWidth', async () => {
|
|
|
|
const wrapper = getSelectVm({ fitInputWidth: true })
|
|
|
|
const selectWrapper = wrapper.findComponent({ name: 'ElSelect' })
|
|
|
|
const selectDom = selectWrapper.element
|
|
|
|
const selectRect = {
|
|
|
|
height: 40,
|
|
|
|
width: 221,
|
|
|
|
x: 44,
|
|
|
|
y: 8,
|
|
|
|
top: 8,
|
|
|
|
}
|
|
|
|
const mockSelectWidth = jest
|
|
|
|
.spyOn(selectDom, 'getBoundingClientRect')
|
|
|
|
.mockReturnValue(selectRect as DOMRect)
|
|
|
|
const dropdown = wrapper.findComponent({ name: 'ElSelectDropdown' })
|
|
|
|
dropdown.vm.minWidth = `${
|
|
|
|
selectWrapper.element.getBoundingClientRect().width
|
|
|
|
}px`
|
|
|
|
await nextTick()
|
|
|
|
expect(dropdown.element.style.width).toBe('221px')
|
|
|
|
mockSelectWidth.mockRestore()
|
|
|
|
})
|
|
|
|
|
2021-07-24 11:41:23 +08:00
|
|
|
test('check default first option', async () => {
|
|
|
|
const wrapper = getSelectVm({
|
|
|
|
filterable: true,
|
|
|
|
defaultFirstOption: true,
|
|
|
|
})
|
|
|
|
const select = wrapper.findComponent({ name: 'ElSelect' })
|
|
|
|
const selectVm = select.vm as any
|
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.element.focus()
|
|
|
|
|
|
|
|
expect(selectVm.hoverIndex).toBe(0)
|
|
|
|
selectVm.navigateOptions('next')
|
|
|
|
expect(selectVm.hoverIndex).toBe(1)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('check default first option when the very first option is disabled', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const demoOptions = [
|
|
|
|
{
|
|
|
|
value: 'HTML',
|
|
|
|
label: 'HTML',
|
|
|
|
disabled: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'CSS',
|
|
|
|
label: 'CSS',
|
|
|
|
disabled: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'JavaScript',
|
|
|
|
label: 'JavaScript',
|
|
|
|
disabled: false,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
const wrapper = getSelectVm(
|
|
|
|
{
|
|
|
|
filterable: true,
|
|
|
|
defaultFirstOption: true,
|
|
|
|
},
|
|
|
|
demoOptions
|
|
|
|
)
|
2021-07-24 11:41:23 +08:00
|
|
|
const select = wrapper.findComponent({ name: 'ElSelect' })
|
|
|
|
const selectVm = select.vm as any
|
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.element.focus()
|
|
|
|
|
|
|
|
expect(selectVm.hoverIndex).toBe(1) // index 0 was skipped
|
|
|
|
selectVm.navigateOptions('next')
|
|
|
|
expect(selectVm.hoverIndex).toBe(2)
|
|
|
|
selectVm.navigateOptions('next')
|
|
|
|
expect(selectVm.hoverIndex).toBe(1) // index 0 was skipped
|
|
|
|
})
|
|
|
|
|
2020-10-03 19:07:02 +08:00
|
|
|
test('allow create', async () => {
|
|
|
|
const wrapper = getSelectVm({ filterable: true, allowCreate: true })
|
|
|
|
const select = wrapper.findComponent({ name: 'ElSelect' })
|
|
|
|
const selectVm = select.vm as any
|
|
|
|
const input = wrapper.find('input')
|
2020-12-04 13:39:01 +08:00
|
|
|
input.element.focus()
|
2020-10-03 19:07:02 +08:00
|
|
|
selectVm.selectedLabel = 'new'
|
|
|
|
selectVm.debouncedOnInputChange()
|
2020-12-04 13:39:01 +08:00
|
|
|
await nextTick()
|
2020-10-04 18:51:24 +08:00
|
|
|
const options = [...getOptions()]
|
2021-09-04 19:29:28 +08:00
|
|
|
const target = options.filter((option) => option.textContent === 'new')
|
2020-10-04 18:51:24 +08:00
|
|
|
target[0].click()
|
2020-10-03 19:07:02 +08:00
|
|
|
expect((wrapper.vm as any).value).toBe('new')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('multiple select', async () => {
|
|
|
|
const wrapper = getSelectVm({ multiple: true })
|
|
|
|
await wrapper.find('.select-trigger').trigger('click')
|
|
|
|
const options = getOptions()
|
|
|
|
const vm = wrapper.vm as any
|
|
|
|
vm.value = ['选项1']
|
|
|
|
vm.$nextTick()
|
|
|
|
options[1].click()
|
|
|
|
await nextTick()
|
|
|
|
options[3].click()
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
vm.value.indexOf('选项2') > -1 && vm.value.indexOf('选项4') > -1
|
|
|
|
).toBe(true)
|
2020-10-03 19:07:02 +08:00
|
|
|
const tagCloseIcons = wrapper.findAll('.el-tag__close')
|
|
|
|
await tagCloseIcons[0].trigger('click')
|
|
|
|
expect(vm.value.indexOf('选项1')).toBe(-1)
|
|
|
|
})
|
|
|
|
|
2020-12-17 16:51:59 +08:00
|
|
|
test('multiple select when content overflow', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
2020-12-17 16:51:59 +08:00
|
|
|
<el-select v-model="selectedList" multiple placeholder="请选择">
|
|
|
|
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
|
|
|
|
</el-option>
|
|
|
|
</el-select>
|
|
|
|
`,
|
2021-09-04 19:29:28 +08:00
|
|
|
() => ({
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
value: '选项1',
|
|
|
|
label:
|
|
|
|
'黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项2',
|
|
|
|
label:
|
|
|
|
'双皮奶双皮奶双皮奶双皮奶双皮奶双皮奶双皮奶双皮奶双皮奶双皮奶双皮奶双皮奶双皮奶',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项3',
|
|
|
|
label: '蚵仔煎蚵仔煎蚵仔煎蚵仔煎蚵仔煎蚵仔煎',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项4',
|
|
|
|
label: '龙须面',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项5',
|
|
|
|
label: '北京烤鸭',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
selectedList: [],
|
|
|
|
})
|
|
|
|
)
|
2020-12-17 16:51:59 +08:00
|
|
|
await wrapper.find('.select-trigger').trigger('click')
|
|
|
|
const options = getOptions()
|
|
|
|
const selectWrapper = wrapper.findComponent(Select)
|
|
|
|
const inputWrapper = selectWrapper.findComponent({ ref: 'reference' })
|
|
|
|
const inputDom = inputWrapper.element
|
|
|
|
const inputRect = {
|
|
|
|
height: 40,
|
|
|
|
width: 221,
|
2021-09-04 19:29:28 +08:00
|
|
|
x: 44,
|
|
|
|
y: 8,
|
|
|
|
top: 8,
|
2020-12-17 16:51:59 +08:00
|
|
|
}
|
2021-09-04 19:29:28 +08:00
|
|
|
const mockInputWidth = jest
|
|
|
|
.spyOn(inputDom, 'getBoundingClientRect')
|
|
|
|
.mockReturnValue(inputRect as DOMRect)
|
2020-12-17 16:51:59 +08:00
|
|
|
selectWrapper.vm.handleResize()
|
|
|
|
options[0].click()
|
|
|
|
await nextTick()
|
|
|
|
options[1].click()
|
|
|
|
await nextTick()
|
|
|
|
options[2].click()
|
|
|
|
await nextTick()
|
|
|
|
const tagWrappers = wrapper.findAll('.el-select__tags-text')
|
2021-09-04 19:29:28 +08:00
|
|
|
for (let i = 0; i < tagWrappers.length; i++) {
|
2020-12-17 16:51:59 +08:00
|
|
|
const tagWrapperDom = tagWrappers[i].element
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
parseInt(tagWrapperDom.style.maxWidth) === inputRect.width - 75
|
|
|
|
).toBe(true)
|
2020-12-17 16:51:59 +08:00
|
|
|
}
|
|
|
|
mockInputWidth.mockRestore()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('multiple select with collapseTags when content overflow', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
2020-12-17 16:51:59 +08:00
|
|
|
<el-select v-model="selectedList" multiple collapseTags placeholder="请选择">
|
|
|
|
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
|
|
|
|
</el-option>
|
|
|
|
</el-select>
|
|
|
|
`,
|
2021-09-04 19:29:28 +08:00
|
|
|
() => ({
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
value: '选项1',
|
|
|
|
label:
|
|
|
|
'黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕黄金糕',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项2',
|
|
|
|
label:
|
|
|
|
'双皮奶双皮奶双皮奶双皮奶双皮奶双皮奶双皮奶双皮奶双皮奶双皮奶双皮奶双皮奶双皮奶',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项3',
|
|
|
|
label: '蚵仔煎蚵仔煎蚵仔煎蚵仔煎蚵仔煎蚵仔煎',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项4',
|
|
|
|
label: '龙须面',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项5',
|
|
|
|
label: '北京烤鸭',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
selectedList: [],
|
|
|
|
})
|
|
|
|
)
|
2020-12-17 16:51:59 +08:00
|
|
|
await wrapper.find('.select-trigger').trigger('click')
|
|
|
|
const options = getOptions()
|
|
|
|
const selectWrapper = wrapper.findComponent(Select)
|
|
|
|
const inputWrapper = selectWrapper.findComponent({ ref: 'reference' })
|
|
|
|
const inputDom = inputWrapper.element
|
|
|
|
const inputRect = {
|
|
|
|
height: 40,
|
|
|
|
width: 221,
|
2021-09-04 19:29:28 +08:00
|
|
|
x: 44,
|
|
|
|
y: 8,
|
|
|
|
top: 8,
|
2020-12-17 16:51:59 +08:00
|
|
|
}
|
2021-09-04 19:29:28 +08:00
|
|
|
const mockInputWidth = jest
|
|
|
|
.spyOn(inputDom, 'getBoundingClientRect')
|
|
|
|
.mockReturnValue(inputRect as DOMRect)
|
2020-12-17 16:51:59 +08:00
|
|
|
selectWrapper.vm.handleResize()
|
|
|
|
options[0].click()
|
|
|
|
await nextTick()
|
|
|
|
options[1].click()
|
|
|
|
await nextTick()
|
|
|
|
options[2].click()
|
|
|
|
await nextTick()
|
|
|
|
const tagWrappers = wrapper.findAll('.el-select__tags-text')
|
|
|
|
const tagWrapperDom = tagWrappers[0].element
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
parseInt(tagWrapperDom.style.maxWidth) === inputRect.width - 123
|
|
|
|
).toBe(true)
|
2020-12-17 16:51:59 +08:00
|
|
|
mockInputWidth.mockRestore()
|
|
|
|
})
|
|
|
|
|
2020-10-03 19:07:02 +08:00
|
|
|
test('multiple remove-tag', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
2020-10-03 19:07:02 +08:00
|
|
|
<el-select v-model="value" multiple @remove-tag="handleRemoveTag">
|
|
|
|
<el-option
|
|
|
|
v-for="item in options"
|
|
|
|
:label="item.label"
|
|
|
|
:key="item.value"
|
|
|
|
:value="item.value">
|
|
|
|
<p>{{item.label}} {{item.value}}</p>
|
|
|
|
</el-option>
|
|
|
|
</el-select>
|
|
|
|
`,
|
2021-09-04 19:29:28 +08:00
|
|
|
() => ({
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
value: '选项1',
|
|
|
|
label: '黄金糕',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项2',
|
|
|
|
label: '双皮奶',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项3',
|
|
|
|
label: '蚵仔煎',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项4',
|
|
|
|
label: '龙须面',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项5',
|
|
|
|
label: '北京烤鸭',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
value: ['选项1', '选项2'],
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
methods: {
|
|
|
|
handleRemoveTag() {
|
|
|
|
// pass
|
|
|
|
},
|
2020-10-03 19:07:02 +08:00
|
|
|
},
|
2021-09-04 19:29:28 +08:00
|
|
|
}
|
|
|
|
)
|
2020-10-03 19:07:02 +08:00
|
|
|
|
|
|
|
const vm = wrapper.vm as any
|
|
|
|
await vm.$nextTick()
|
|
|
|
expect(vm.value.length).toBe(2)
|
|
|
|
const tagCloseIcons = wrapper.findAll('.el-tag__close')
|
|
|
|
await tagCloseIcons[1].trigger('click')
|
|
|
|
expect(vm.value.length).toBe(1)
|
|
|
|
await tagCloseIcons[0].trigger('click')
|
|
|
|
expect(vm.value.length).toBe(0)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('multiple limit', async () => {
|
|
|
|
const wrapper = getSelectVm({ multiple: true, multipleLimit: 1 })
|
|
|
|
const vm = wrapper.vm as any
|
|
|
|
await wrapper.find('.select-trigger').trigger('click')
|
|
|
|
const options = getOptions()
|
|
|
|
options[1].click()
|
|
|
|
await nextTick()
|
|
|
|
expect(vm.value.indexOf('选项2') > -1).toBe(true)
|
|
|
|
options[3].click()
|
|
|
|
await nextTick()
|
|
|
|
expect(vm.value.indexOf('选项4')).toBe(-1)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('event:focus & blur', async () => {
|
|
|
|
const handleFocus = jest.fn()
|
|
|
|
const handleBlur = jest.fn()
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-select
|
2020-10-03 19:07:02 +08:00
|
|
|
@focus="handleFocus"
|
2021-09-04 19:29:28 +08:00
|
|
|
@blur="handleBlur" />`,
|
|
|
|
() => ({
|
|
|
|
handleFocus,
|
|
|
|
handleBlur,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
const select = wrapper.findComponent({ name: 'ElSelect' })
|
2021-02-26 20:58:05 +08:00
|
|
|
const input = select.find('input')
|
|
|
|
|
|
|
|
expect(input.exists()).toBe(true)
|
|
|
|
await input.trigger('focus')
|
|
|
|
expect(handleFocus).toHaveBeenCalled()
|
|
|
|
await input.trigger('blur')
|
|
|
|
expect(handleBlur).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('event:focus & blur for multile & filterable select', async () => {
|
|
|
|
const handleFocus = jest.fn()
|
|
|
|
const handleBlur = jest.fn()
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
2021-02-26 20:58:05 +08:00
|
|
|
<el-select
|
|
|
|
@focus="handleFocus"
|
|
|
|
@blur="handleBlur"
|
|
|
|
multiple
|
|
|
|
filterable
|
2021-09-04 19:29:28 +08:00
|
|
|
/>`,
|
|
|
|
() => ({
|
|
|
|
handleFocus,
|
|
|
|
handleBlur,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
const select = wrapper.findComponent({ name: 'ElSelect' })
|
2020-10-03 19:07:02 +08:00
|
|
|
const input = select.find('input')
|
|
|
|
|
|
|
|
expect(input.exists()).toBe(true)
|
|
|
|
await input.trigger('focus')
|
|
|
|
expect(handleFocus).toHaveBeenCalled()
|
|
|
|
await input.trigger('blur')
|
|
|
|
expect(handleBlur).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should not open popper when automatic-dropdown not set', async () => {
|
|
|
|
const wrapper = getSelectVm()
|
|
|
|
const select = wrapper.findComponent({ name: 'ElSelect' })
|
2021-09-04 19:29:28 +08:00
|
|
|
await select
|
|
|
|
.findComponent({ ref: 'reference' })
|
2020-10-03 19:07:02 +08:00
|
|
|
.find('input')
|
|
|
|
.element.focus()
|
|
|
|
expect((select.vm as any).visible).toBe(false)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should open popper when automatic-dropdown is set', async () => {
|
|
|
|
const wrapper = getSelectVm({ automaticDropdown: true })
|
|
|
|
const select = wrapper.findComponent({ name: 'ElSelect' })
|
2021-09-04 19:29:28 +08:00
|
|
|
await select
|
|
|
|
.findComponent({ ref: 'reference' })
|
|
|
|
.find('input')
|
|
|
|
.trigger('focus')
|
2020-10-03 19:07:02 +08:00
|
|
|
expect((select.vm as any).visible).toBe(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('only emit change on user input', async () => {
|
|
|
|
let callCount = 0
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
2020-10-03 19:07:02 +08:00
|
|
|
<el-select v-model="value" @change="change" ref="select">
|
|
|
|
<el-option label="1" value="1" />
|
|
|
|
<el-option label="2" value="2" />
|
|
|
|
<el-option label="3" value="3" />
|
|
|
|
</el-select>`,
|
2021-09-04 19:29:28 +08:00
|
|
|
() => ({
|
|
|
|
value: '1',
|
|
|
|
change: () => ++callCount,
|
|
|
|
})
|
|
|
|
)
|
2020-10-03 19:07:02 +08:00
|
|
|
|
|
|
|
expect(callCount).toBe(0)
|
|
|
|
await wrapper.find('.select-trigger').trigger('click')
|
|
|
|
const options = getOptions()
|
|
|
|
options[2].click()
|
|
|
|
expect(callCount).toBe(1)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('render slot `empty`', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
2020-10-03 19:07:02 +08:00
|
|
|
<el-select v-model="value">
|
2020-11-29 18:50:46 +08:00
|
|
|
<template #empty>
|
|
|
|
<div class="empty-slot">EmptySlot</div>
|
|
|
|
</template>
|
2020-10-03 19:07:02 +08:00
|
|
|
</el-select>`,
|
2021-09-04 19:29:28 +08:00
|
|
|
() => ({
|
|
|
|
value: '1',
|
|
|
|
})
|
|
|
|
)
|
2020-10-03 19:07:02 +08:00
|
|
|
await wrapper.find('.select-trigger').trigger('click')
|
|
|
|
expect(document.querySelector('.empty-slot').textContent).toBe('EmptySlot')
|
|
|
|
})
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
test('should set placeholder to label of selected option when filterable is true and multiple is false', async () => {
|
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
2020-10-03 19:07:02 +08:00
|
|
|
<el-select ref="select" v-model="value" filterable>
|
|
|
|
<el-option label="test" value="test" />
|
|
|
|
</el-select>`,
|
2021-09-04 19:29:28 +08:00
|
|
|
() => ({ value: 'test' })
|
|
|
|
)
|
2020-10-03 19:07:02 +08:00
|
|
|
const vm = wrapper.vm as any
|
|
|
|
await wrapper.trigger('click')
|
|
|
|
const selectVm = wrapper.findComponent({ name: 'ElSelect' }).vm as any
|
|
|
|
expect(selectVm.visible).toBe(true)
|
|
|
|
expect(wrapper.find('.el-input__inner').element.placeholder).toBe('test')
|
|
|
|
expect(vm.value).toBe('test')
|
|
|
|
})
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
test('default value is null or undefined', async () => {
|
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
2020-10-03 19:07:02 +08:00
|
|
|
<el-select v-model="value">
|
|
|
|
<el-option
|
|
|
|
v-for="item in options"
|
|
|
|
:label="item.label"
|
|
|
|
:key="item.value"
|
|
|
|
:value="item.value">
|
|
|
|
</el-option>
|
|
|
|
</el-select>`,
|
2021-09-04 19:29:28 +08:00
|
|
|
() => ({
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
value: '选项1',
|
|
|
|
label: '黄金糕',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '选项2',
|
|
|
|
label: '双皮奶',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
value: undefined,
|
|
|
|
})
|
|
|
|
)
|
2020-10-03 19:07:02 +08:00
|
|
|
const vm = wrapper.vm as any
|
|
|
|
vm.value = null
|
|
|
|
await vm.$nextTick()
|
|
|
|
expect(wrapper.find('.el-input__inner').element.value).toBe('')
|
|
|
|
vm.value = '选项1'
|
|
|
|
await vm.$nextTick()
|
|
|
|
expect(wrapper.find('.el-input__inner').element.value).toBe('黄金糕')
|
|
|
|
})
|
2021-01-07 20:26:26 +08:00
|
|
|
|
|
|
|
test('emptyText error show', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
2021-01-07 20:26:26 +08:00
|
|
|
<el-select :model-value="value" filterable placeholder="Select">
|
|
|
|
<el-option
|
|
|
|
v-for="item in options"
|
|
|
|
:key="item.value"
|
|
|
|
:label="item.label"
|
|
|
|
:value="item.value">
|
|
|
|
</el-option>
|
|
|
|
</el-select>`,
|
2021-09-04 19:29:28 +08:00
|
|
|
() => ({
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
value: 'Option1',
|
|
|
|
label: 'Option1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'Option2',
|
|
|
|
label: 'Option2',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'Option3',
|
|
|
|
label: 'Option3',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'Option4',
|
|
|
|
label: 'Option4',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'Option5',
|
|
|
|
label: 'Option5',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
value: 'test',
|
|
|
|
})
|
|
|
|
)
|
2021-01-07 20:26:26 +08:00
|
|
|
const select = wrapper.findComponent({ name: 'ElSelect' })
|
|
|
|
select.trigger('click')
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
!!document.querySelector('.el-select__popper').style.display
|
|
|
|
).toBeFalsy()
|
2021-01-07 20:26:26 +08:00
|
|
|
expect(wrapper.findAll('.el-select-dropdown__empty').length).toBe(0)
|
|
|
|
})
|
2021-01-31 18:47:52 +08:00
|
|
|
|
|
|
|
test('multiple select with remote load', async () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
template: `
|
|
|
|
<el-select
|
|
|
|
v-model="value"
|
|
|
|
multiple
|
|
|
|
filterable
|
|
|
|
remote
|
|
|
|
reserve-keyword
|
|
|
|
placeholder="请输入关键词"
|
|
|
|
:remote-method="remoteMethod"
|
|
|
|
:loading="loading"
|
|
|
|
>
|
|
|
|
<el-option
|
|
|
|
v-for="item in options"
|
|
|
|
:key="item.value"
|
|
|
|
:label="item.label"
|
|
|
|
:value="item"
|
|
|
|
/>
|
|
|
|
</el-select>`,
|
|
|
|
components: { ElSelect: Select, ElOption: Option },
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
options: [],
|
|
|
|
value: [],
|
|
|
|
list: [],
|
|
|
|
loading: false,
|
2021-09-04 19:29:28 +08:00
|
|
|
states: [
|
|
|
|
'Alabama',
|
|
|
|
'Alaska',
|
|
|
|
'Arizona',
|
|
|
|
'Arkansas',
|
|
|
|
'California',
|
|
|
|
'Colorado',
|
|
|
|
'Connecticut',
|
|
|
|
'Delaware',
|
|
|
|
'Florida',
|
|
|
|
'Georgia',
|
|
|
|
'Hawaii',
|
|
|
|
'Idaho',
|
|
|
|
'Illinois',
|
|
|
|
'Indiana',
|
|
|
|
'Iowa',
|
|
|
|
'Kansas',
|
|
|
|
'Kentucky',
|
|
|
|
'Louisiana',
|
|
|
|
'Maine',
|
|
|
|
'Maryland',
|
|
|
|
'Massachusetts',
|
|
|
|
'Michigan',
|
|
|
|
'Minnesota',
|
|
|
|
'Mississippi',
|
|
|
|
'Missouri',
|
|
|
|
'Montana',
|
|
|
|
'Nebraska',
|
|
|
|
'Nevada',
|
|
|
|
'New Hampshire',
|
|
|
|
'New Jersey',
|
|
|
|
'New Mexico',
|
|
|
|
'New York',
|
|
|
|
'North Carolina',
|
|
|
|
'North Dakota',
|
|
|
|
'Ohio',
|
|
|
|
'Oklahoma',
|
|
|
|
'Oregon',
|
|
|
|
'Pennsylvania',
|
|
|
|
'Rhode Island',
|
|
|
|
'South Carolina',
|
|
|
|
'South Dakota',
|
|
|
|
'Tennessee',
|
|
|
|
'Texas',
|
|
|
|
'Utah',
|
|
|
|
'Vermont',
|
|
|
|
'Virginia',
|
|
|
|
'Washington',
|
|
|
|
'West Virginia',
|
|
|
|
'Wisconsin',
|
|
|
|
'Wyoming',
|
|
|
|
],
|
2021-01-31 18:47:52 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
2021-09-04 19:29:28 +08:00
|
|
|
this.list = this.states.map((item) => {
|
2021-01-31 18:47:52 +08:00
|
|
|
return { value: `value:${item}`, label: `label:${item}` }
|
|
|
|
})
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
remoteMethod(query) {
|
|
|
|
if (query !== '') {
|
|
|
|
this.loading = true
|
|
|
|
setTimeout(() => {
|
|
|
|
this.loading = false
|
2021-09-04 19:29:28 +08:00
|
|
|
this.options = this.list.filter((item) => {
|
|
|
|
return (
|
|
|
|
item.label.toLowerCase().indexOf(query.toLowerCase()) > -1
|
|
|
|
)
|
2021-01-31 18:47:52 +08:00
|
|
|
})
|
|
|
|
}, 200)
|
|
|
|
} else {
|
|
|
|
this.options = []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
const select = wrapper.findComponent({ name: 'ElSelect' }).vm
|
|
|
|
select.debouncedQueryChange({
|
|
|
|
target: {
|
|
|
|
value: '',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
select.debouncedQueryChange({
|
|
|
|
target: {
|
|
|
|
value: 'a',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
jest.runAllTimers()
|
|
|
|
await nextTick()
|
|
|
|
let options = getOptions()
|
|
|
|
options[0].click()
|
|
|
|
await nextTick()
|
|
|
|
select.debouncedQueryChange({
|
|
|
|
target: {
|
|
|
|
value: 'n',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
jest.runAllTimers()
|
|
|
|
await nextTick()
|
|
|
|
options = getOptions()
|
|
|
|
options[5].click()
|
|
|
|
await nextTick()
|
|
|
|
expect(select.selected.length === 2).toBeTruthy()
|
|
|
|
expect(select.selected[0].currentLabel !== '').toBeTruthy()
|
|
|
|
expect(select.selected[1].currentLabel !== '').toBeTruthy()
|
|
|
|
})
|
2021-03-04 20:57:43 +08:00
|
|
|
|
|
|
|
test('disabled group', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
2021-03-04 20:57:43 +08:00
|
|
|
<el-select v-model="value">
|
|
|
|
<el-group-option
|
|
|
|
v-for="group in options"
|
|
|
|
:key="group.label"
|
|
|
|
:label="group.label"
|
|
|
|
:disabled="group.disabled">
|
|
|
|
<el-option
|
|
|
|
v-for="item in group.options"
|
|
|
|
:key="item.value"
|
|
|
|
:label="item.label"
|
|
|
|
:value="item.value">
|
|
|
|
</el-option>
|
|
|
|
</el-group-option>
|
|
|
|
</el-select>`,
|
2021-09-04 19:29:28 +08:00
|
|
|
() => ({
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
label: 'Popular cities',
|
|
|
|
options: [
|
|
|
|
{ value: 'Shanghai', label: 'Shanghai' },
|
|
|
|
{ value: 'Beijing', label: 'Beijing' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'City name',
|
|
|
|
options: [
|
|
|
|
{ value: 'Chengdu', label: 'Chengdu' },
|
|
|
|
{ value: 'Shenzhen', label: 'Shenzhen' },
|
|
|
|
{ value: 'Guangzhou', label: 'Guangzhou' },
|
|
|
|
{ value: 'Dalian', label: 'Dalian' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
value: '',
|
|
|
|
})
|
|
|
|
)
|
2021-03-04 20:57:43 +08:00
|
|
|
|
|
|
|
const vm = wrapper.vm as any
|
|
|
|
wrapper.find('.select-trigger').trigger('click')
|
|
|
|
await nextTick()
|
|
|
|
vm.options[1].disabled = true
|
|
|
|
await nextTick()
|
|
|
|
const options = getOptions()
|
|
|
|
expect(options[0].className).not.toContain('is-disabled')
|
|
|
|
expect(options[2].className).toContain('is-disabled')
|
|
|
|
options[0].click()
|
|
|
|
await nextTick()
|
|
|
|
expect(vm.value).toBe('Shanghai')
|
|
|
|
options[2].click()
|
|
|
|
await nextTick()
|
|
|
|
expect(vm.value).toBe('Shanghai')
|
|
|
|
})
|
2021-03-11 20:32:36 +08:00
|
|
|
|
|
|
|
test('tag of disabled option is not closable', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
2021-03-11 20:32:36 +08:00
|
|
|
<el-select v-model="vendors" multiple :collapse-tags="isCollapsed" :clearable="isClearable" placeholder="Select Business Unit">
|
|
|
|
<el-option
|
|
|
|
v-for="(vendor, index) in options"
|
|
|
|
:key="index"
|
|
|
|
:value="index + 1"
|
|
|
|
:label="vendor.name"
|
|
|
|
:disabled="vendor.isDisabled"
|
|
|
|
>
|
|
|
|
</el-option>
|
2021-09-04 19:29:28 +08:00
|
|
|
</el-select>`,
|
|
|
|
() => ({
|
|
|
|
vendors: [2, 3, 4],
|
|
|
|
isCollapsed: false,
|
|
|
|
isClearable: false,
|
|
|
|
options: [
|
|
|
|
{ name: 'Test 1', isDisabled: false },
|
|
|
|
{ name: 'Test 2', isDisabled: true },
|
|
|
|
{ name: 'Test 3', isDisabled: false },
|
|
|
|
{ name: 'Test 4', isDisabled: true },
|
|
|
|
],
|
|
|
|
})
|
|
|
|
)
|
2021-03-11 20:32:36 +08:00
|
|
|
const vm = wrapper.vm as any
|
|
|
|
await vm.$nextTick()
|
|
|
|
const selectVm = wrapper.findComponent({ name: 'ElSelect' }).vm as any
|
|
|
|
expect(wrapper.findAll('.el-tag').length).toBe(3)
|
|
|
|
const tagCloseIcons = wrapper.findAll('.el-tag__close')
|
|
|
|
expect(tagCloseIcons.length).toBe(1)
|
|
|
|
await tagCloseIcons[0].trigger('click')
|
|
|
|
expect(wrapper.findAll('.el-tag__close').length).toBe(0)
|
|
|
|
expect(wrapper.findAll('.el-tag').length).toBe(2)
|
|
|
|
|
|
|
|
//test if is clearable
|
|
|
|
vm.isClearable = true
|
|
|
|
vm.vendors = [2, 3, 4]
|
|
|
|
await vm.$nextTick()
|
|
|
|
selectVm.inputHovering = true
|
|
|
|
await selectVm.$nextTick()
|
2021-10-27 23:17:13 +08:00
|
|
|
const iconClear = wrapper.findComponent(CircleClose)
|
2021-03-11 20:32:36 +08:00
|
|
|
expect(wrapper.findAll('.el-tag').length).toBe(3)
|
|
|
|
await iconClear.trigger('click')
|
|
|
|
expect(wrapper.findAll('.el-tag').length).toBe(2)
|
|
|
|
|
|
|
|
// test for collapse select
|
|
|
|
vm.vendors = [1, 2, 4]
|
|
|
|
vm.isCollapsed = true
|
|
|
|
vm.isClearable = false
|
|
|
|
await vm.$nextTick()
|
|
|
|
expect(wrapper.findAll('.el-tag').length).toBe(2)
|
|
|
|
await wrapper.find('.el-tag__close').trigger('click')
|
|
|
|
expect(wrapper.findAll('.el-tag').length).toBe(2)
|
|
|
|
expect(wrapper.findAll('.el-tag__close').length).toBe(0)
|
|
|
|
|
|
|
|
// test for collapse select if is clearable
|
|
|
|
vm.vendors = [1, 2, 4]
|
|
|
|
vm.isCollapsed = true
|
|
|
|
vm.isClearable = true
|
|
|
|
await vm.$nextTick()
|
|
|
|
expect(wrapper.findAll('.el-tag__close').length).toBe(1)
|
|
|
|
await wrapper.find('.el-tag__close').trigger('click')
|
|
|
|
expect(wrapper.findAll('.el-tag').length).toBe(2)
|
|
|
|
expect(wrapper.findAll('.el-tag__close').length).toBe(0)
|
|
|
|
})
|
2021-03-16 21:41:08 +08:00
|
|
|
|
|
|
|
test('modelValue should be deep reactive in multiple mode', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
2021-03-16 21:41:08 +08:00
|
|
|
<el-select v-model="modelValue" multiple>
|
|
|
|
<el-option
|
|
|
|
v-for="option in options"
|
|
|
|
:key="option.value"
|
|
|
|
:value="option.value"
|
|
|
|
:label="option.label"
|
|
|
|
>
|
|
|
|
</el-option>
|
2021-09-04 19:29:28 +08:00
|
|
|
</el-select>`,
|
|
|
|
() => ({
|
|
|
|
modelValue: [1],
|
|
|
|
options: [
|
|
|
|
{ label: 'Test 1', value: 1 },
|
|
|
|
{ label: 'Test 2', value: 2 },
|
|
|
|
{ label: 'Test 3', value: 3 },
|
|
|
|
{ label: 'Test 4', value: 4 },
|
|
|
|
],
|
|
|
|
})
|
|
|
|
)
|
2021-03-16 21:41:08 +08:00
|
|
|
const vm = wrapper.vm as any
|
|
|
|
await vm.$nextTick()
|
|
|
|
expect(wrapper.findAll('.el-tag').length).toBe(1)
|
|
|
|
|
|
|
|
vm.modelValue.splice(0, 1)
|
|
|
|
|
|
|
|
await vm.$nextTick()
|
|
|
|
expect(wrapper.findAll('.el-tag').length).toBe(0)
|
|
|
|
})
|
2021-03-24 22:54:35 +08:00
|
|
|
|
|
|
|
test('should reset placeholder after clear when both multiple and filterable are true', async () => {
|
|
|
|
const placeholder = 'placeholder'
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
2021-03-24 22:54:35 +08:00
|
|
|
<el-select v-model="modelValue" multiple filterable placeholder=${placeholder}>
|
|
|
|
<el-option label="1" value="1" />
|
2021-09-04 19:29:28 +08:00
|
|
|
</el-select>`,
|
|
|
|
() => ({
|
|
|
|
modelValue: ['1'],
|
|
|
|
})
|
|
|
|
)
|
2021-03-24 22:54:35 +08:00
|
|
|
const vm = wrapper.vm as any
|
|
|
|
await vm.$nextTick()
|
|
|
|
|
|
|
|
const innerInput = wrapper.find('.el-input__inner')
|
|
|
|
const innerInputEl = innerInput.element as HTMLInputElement
|
|
|
|
expect(innerInputEl.placeholder).toBe('')
|
|
|
|
|
|
|
|
const tagCloseIcon = wrapper.find('.el-tag__close')
|
|
|
|
await tagCloseIcon.trigger('click')
|
|
|
|
expect(innerInputEl.placeholder).toBe(placeholder)
|
|
|
|
|
|
|
|
const selectInput = wrapper.find('.el-select__input')
|
|
|
|
const selectInputEl = selectInput.element as HTMLInputElement
|
|
|
|
selectInputEl.value = 'a'
|
|
|
|
selectInput.trigger('input')
|
|
|
|
await vm.$nextTick()
|
2021-10-06 06:39:01 +08:00
|
|
|
|
|
|
|
const timer = sleep(300)
|
|
|
|
jest.runAllTimers()
|
|
|
|
await timer
|
|
|
|
|
2021-03-24 22:54:35 +08:00
|
|
|
expect(innerInputEl.placeholder).toBe('')
|
|
|
|
|
|
|
|
selectInput.trigger('keydown', {
|
|
|
|
key: EVENT_CODE.backspace,
|
|
|
|
})
|
|
|
|
await vm.$nextTick()
|
|
|
|
expect(innerInputEl.placeholder).toBe(placeholder)
|
|
|
|
})
|
2021-04-06 16:21:40 +08:00
|
|
|
|
2021-04-11 20:58:58 +08:00
|
|
|
describe('should show all options when open select dropdown', () => {
|
|
|
|
async function testShowOptions({ filterable, multiple }: SelectProps = {}) {
|
|
|
|
const wrapper = getSelectVm({ filterable, multiple })
|
|
|
|
const options = wrapper.findAllComponents({ name: 'ElOption' })
|
|
|
|
|
|
|
|
await wrapper.find('.select-trigger').trigger('click')
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(options.every((option) => option.vm.visible)).toBe(true)
|
2021-04-11 20:58:58 +08:00
|
|
|
|
|
|
|
await options[1].trigger('click')
|
|
|
|
await wrapper.find('.select-trigger').trigger('click')
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(options.every((option) => option.vm.visible)).toBe(true)
|
2021-04-11 20:58:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
test('both filterable and multiple are false', async () => {
|
|
|
|
await testShowOptions()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('filterable is true and multiple is false', async () => {
|
|
|
|
await testShowOptions({ filterable: true })
|
|
|
|
})
|
|
|
|
|
|
|
|
test('filterable is false and multiple is true', async () => {
|
|
|
|
await testShowOptions({ multiple: true })
|
|
|
|
})
|
|
|
|
|
|
|
|
test('both filterable and multiple are true', async () => {
|
|
|
|
await testShowOptions({ filterable: true, multiple: true })
|
|
|
|
})
|
2021-07-14 15:01:00 +08:00
|
|
|
|
|
|
|
test('filterable is true with grouping', async () => {
|
|
|
|
const wrapper = getGroupSelectVm({ filterable: true })
|
|
|
|
await wrapper.find('.select-trigger').trigger('click')
|
|
|
|
const vm = wrapper.findComponent(Select).vm
|
|
|
|
const event = { target: { value: 'sh' } }
|
|
|
|
vm.debouncedQueryChange(event)
|
|
|
|
await nextTick
|
|
|
|
const groups = wrapper.findAllComponents(Group)
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
groups.filter((group) => {
|
|
|
|
const vm = group.vm as any
|
|
|
|
return vm.visible
|
|
|
|
}).length
|
|
|
|
).toBe(1)
|
2021-07-14 15:01:00 +08:00
|
|
|
})
|
2021-04-11 20:58:58 +08:00
|
|
|
})
|
|
|
|
|
2021-04-06 16:21:40 +08:00
|
|
|
describe('after search', () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
async function testAfterSearch({
|
|
|
|
multiple,
|
|
|
|
filterMethod,
|
|
|
|
remote,
|
|
|
|
remoteMethod,
|
|
|
|
}: SelectProps) {
|
|
|
|
const wrapper = getSelectVm({
|
|
|
|
filterable: true,
|
|
|
|
multiple,
|
|
|
|
filterMethod,
|
|
|
|
remote,
|
|
|
|
remoteMethod,
|
|
|
|
})
|
2021-04-06 16:21:40 +08:00
|
|
|
const method = remote ? remoteMethod : filterMethod
|
|
|
|
const firstInputLetter = 'a'
|
|
|
|
const secondInputLetter = 'aa'
|
|
|
|
|
|
|
|
const vm = wrapper.vm as any
|
|
|
|
await vm.$nextTick()
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
const input = wrapper.find(
|
|
|
|
multiple ? '.el-select__input' : '.el-input__inner'
|
|
|
|
)
|
2021-04-06 16:21:40 +08:00
|
|
|
const inputEl = input.element as HTMLInputElement
|
|
|
|
await input.trigger('click')
|
|
|
|
inputEl.value = firstInputLetter
|
|
|
|
await input.trigger('input')
|
|
|
|
expect(method).toBeCalled()
|
|
|
|
expect(method.mock.calls[0][0]).toBe(firstInputLetter)
|
|
|
|
|
|
|
|
inputEl.value = secondInputLetter
|
|
|
|
await input.trigger('input')
|
|
|
|
expect(method).toBeCalledTimes(2)
|
|
|
|
expect(method.mock.calls[1][0]).toBe(secondInputLetter)
|
|
|
|
}
|
|
|
|
|
|
|
|
test('should call filter method', async () => {
|
|
|
|
const filterMethod = jest.fn()
|
|
|
|
await testAfterSearch({ filterMethod })
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should call filter method in multiple mode', async () => {
|
|
|
|
const filterMethod = jest.fn()
|
|
|
|
await testAfterSearch({ multiple: true, filterMethod })
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should call remote method', async () => {
|
|
|
|
const remoteMethod = jest.fn()
|
|
|
|
await testAfterSearch({ remote: true, remoteMethod })
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should call remote method in multiple mode', async () => {
|
|
|
|
const remoteMethod = jest.fn()
|
|
|
|
await testAfterSearch({ multiple: true, remote: true, remoteMethod })
|
|
|
|
})
|
|
|
|
})
|
2020-10-03 19:07:02 +08:00
|
|
|
})
|