28 lines
2.0 KiB
TypeScript
28 lines
2.0 KiB
TypeScript
// Issue#6·F3:ScSelect auto>5 搜索阈值(sub2api Select searchable='auto' 契约)
|
|
import { describe, expect, it } from 'vitest'
|
|
import { mount } from '@vue/test-utils'
|
|
import ScSelect from '@/components/ScSelect.vue'
|
|
|
|
const opts = (n: number) => Array.from({ length: n }, (_, i) => ({ value: i, label: `选项${i}` }))
|
|
|
|
describe('ScSelect auto 阈值', () => {
|
|
it('options>5 → filterable 生效(trigger 内可输入)', () => {
|
|
const w = mount(ScSelect, { props: { modelValue: '', options: opts(6) }, global: { stubs: { 'el-select': { template: '<div><slot/><input v-if="filterable" data-testid="f" /></div>', props: ['filterable','modelValue'] } } } })
|
|
expect(w.find('[data-testid="f"]').exists()).toBe(true)
|
|
})
|
|
it('options≤5 → 无 filterable', () => {
|
|
const w = mount(ScSelect, { props: { modelValue: '', options: opts(5) }, global: { stubs: { 'el-select': { template: '<div><slot/><input v-if="filterable" data-testid="f" /></div>', props: ['filterable','modelValue'] } } } })
|
|
expect(w.find('[data-testid="f"]').exists()).toBe(false)
|
|
})
|
|
it('searchable=false 关闭 auto;filterable 显式覆盖', () => {
|
|
const off = mount(ScSelect, { props: { modelValue: '', options: opts(9), searchable: false }, global: { stubs: { 'el-select': { template: '<div><input v-if="filterable" data-testid="f" /></div>', props: ['filterable'] } } } })
|
|
expect(off.find('[data-testid="f"]').exists()).toBe(false)
|
|
const on = mount(ScSelect, { props: { modelValue: '', options: opts(2), filterable: true }, global: { stubs: { 'el-select': { template: '<div><input v-if="filterable" data-testid="f" /></div>', props: ['filterable'] } } } })
|
|
expect(on.find('[data-testid="f"]').exists()).toBe(true)
|
|
})
|
|
it('options 渲染到默认 slot(el-option 数=传入数)', () => {
|
|
const w = mount(ScSelect, { props: { modelValue: '', options: opts(4) }, global: { stubs: { 'el-select': { template: '<div><slot /></div>', props: ['modelValue'] }, 'el-option': { template: '<div class="opt" />' } } } })
|
|
expect(w.findAll('.opt').length).toBe(4)
|
|
})
|
|
})
|