parent
a1cd7c2268
commit
c0a22f5876
@ -0,0 +1,32 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { render } from '@vue/server-test-utils'
|
||||
import Vue from 'vue'
|
||||
import AutoComplete from '..'
|
||||
import focusTest from '../../../tests/shared/focusTest'
|
||||
|
||||
describe('AutoComplete with Custom Input Element Render', () => {
|
||||
focusTest(AutoComplete)
|
||||
function $$ (className) {
|
||||
return document.body.querySelectorAll(className)
|
||||
}
|
||||
it('AutoComplete with custom Input render perfectly', (done) => {
|
||||
const wrapper = mount({
|
||||
render (h) {
|
||||
return <AutoComplete ref='component' dataSource={['12345', '23456', '34567']}>
|
||||
<input />
|
||||
</AutoComplete>
|
||||
},
|
||||
}, { attachToDocument: true, sync: false })
|
||||
expect(wrapper.findAll('input').length).toBe(1)
|
||||
const input = wrapper.find('input')
|
||||
input.element.value = '123'
|
||||
input.trigger('input')
|
||||
Vue.nextTick(() => {
|
||||
const popupComponent = wrapper.find({ name: 'Trigger' }).vm._component
|
||||
expect($$('.ant-select-dropdown-menu-item').length).toBe(3)
|
||||
expect(popupComponent).not.toBe(null)
|
||||
expect(popupComponent).not.toBe(undefined)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
@ -0,0 +1,52 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import Vue from 'vue'
|
||||
export default function focusTest (Component) {
|
||||
describe('focus and blur', () => {
|
||||
beforeAll(() => {
|
||||
jest.useFakeTimers()
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
jest.useRealTimers()
|
||||
})
|
||||
|
||||
it('focus() and onFocus', () => {
|
||||
const handleFocus = jest.fn()
|
||||
const wrapper = mount({
|
||||
render (h) {
|
||||
return <Component ref='component' onFocus={handleFocus} />
|
||||
},
|
||||
}, { attachToDocument: true, sync: false })
|
||||
wrapper.vm.$refs.component.focus()
|
||||
jest.runAllTimers()
|
||||
expect(handleFocus).toBeCalled()
|
||||
})
|
||||
|
||||
it('blur() and onBlur', () => {
|
||||
const handleBlur = jest.fn()
|
||||
const wrapper = mount({
|
||||
render (h) {
|
||||
return <Component ref='component' onBlur={handleBlur} />
|
||||
},
|
||||
}, { attachToDocument: true, sync: false })
|
||||
wrapper.vm.$refs.component.focus()
|
||||
wrapper.vm.$refs.component.blur()
|
||||
jest.runAllTimers()
|
||||
expect(handleBlur).toBeCalled()
|
||||
})
|
||||
|
||||
it('autoFocus', (done) => {
|
||||
jest.useRealTimers()
|
||||
const handleFocus = jest.fn()
|
||||
mount({
|
||||
render (h) {
|
||||
return <Component autoFocus onFocus={handleFocus} />
|
||||
},
|
||||
}, { attachToDocument: true, sync: false })
|
||||
setTimeout(() => {
|
||||
expect(handleFocus).toBeCalled()
|
||||
done()
|
||||
}, 1000)
|
||||
})
|
||||
})
|
||||
}
|
Loading…
Reference in new issue