mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-16 09:10:33 +03:00
+30
-21
@@ -1,69 +1,78 @@
|
||||
import { DOMWrapper } from '@vue/test-utils'
|
||||
import typeAheadPointer from '../../src/mixins/typeAheadPointer'
|
||||
import { mountDefault } from '../helpers'
|
||||
|
||||
describe('Custom Keydown Handlers', () => {
|
||||
it('can use the map-keydown prop to trigger custom behaviour', () => {
|
||||
let spy
|
||||
afterEach(() => {
|
||||
if (spy) spy.mockClear()
|
||||
})
|
||||
|
||||
it('can use the map-keydown prop to trigger custom behaviour', async () => {
|
||||
const onKeyDown = jest.fn()
|
||||
const Select = mountDefault({
|
||||
mapKeydown: (defaults, vm) => ({ ...defaults, 32: onKeyDown }),
|
||||
})
|
||||
|
||||
Select.findComponent({ ref: 'search' }).trigger('keydown.space')
|
||||
await Select.get('input').trigger('keydown.space')
|
||||
|
||||
expect(onKeyDown.mock.calls.length).toBe(1)
|
||||
})
|
||||
|
||||
it('selectOnKeyCodes should trigger a selection for custom keycodes', () => {
|
||||
spy = jest.spyOn(typeAheadPointer.methods, 'typeAheadSelect')
|
||||
|
||||
const Select = mountDefault({
|
||||
selectOnKeyCodes: [32],
|
||||
})
|
||||
|
||||
const spy = jest.spyOn(Select.vm, 'typeAheadSelect')
|
||||
|
||||
Select.findComponent({ ref: 'search' }).trigger('keydown.space')
|
||||
Select.get('input').trigger('keydown.space')
|
||||
|
||||
expect(spy).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('even works when combining selectOnKeyCodes with map-keydown', () => {
|
||||
spy = jest.spyOn(typeAheadPointer.methods, 'typeAheadSelect')
|
||||
|
||||
const onKeyDown = jest.fn()
|
||||
const Select = mountDefault({
|
||||
mapKeydown: (defaults, vm) => ({ ...defaults, 32: onKeyDown }),
|
||||
selectOnKeyCodes: [9],
|
||||
})
|
||||
|
||||
const spy = jest.spyOn(Select.vm, 'typeAheadSelect')
|
||||
|
||||
Select.findComponent({ ref: 'search' }).trigger('keydown.space')
|
||||
Select.get('input').trigger('keydown.space')
|
||||
expect(onKeyDown.mock.calls.length).toBe(1)
|
||||
|
||||
Select.findComponent({ ref: 'search' }).trigger('keydown.tab')
|
||||
Select.get('input').trigger('keydown.tab')
|
||||
expect(spy).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
describe('CompositionEvent support', () => {
|
||||
it('will not select a value with enter if the user is composing', () => {
|
||||
const Select = mountDefault()
|
||||
const spy = jest.spyOn(Select.vm, 'typeAheadSelect')
|
||||
spy = jest.spyOn(typeAheadPointer.methods, 'typeAheadSelect')
|
||||
|
||||
Select.findComponent({ ref: 'search' }).trigger('compositionstart')
|
||||
Select.findComponent({ ref: 'search' }).trigger('keydown.enter')
|
||||
const Select = mountDefault()
|
||||
|
||||
Select.get('input').trigger('compositionstart')
|
||||
Select.get('input').trigger('keydown.enter')
|
||||
expect(spy).toHaveBeenCalledTimes(0)
|
||||
|
||||
Select.findComponent({ ref: 'search' }).trigger('compositionend')
|
||||
Select.findComponent({ ref: 'search' }).trigger('keydown.enter')
|
||||
Select.get('input').trigger('compositionend')
|
||||
Select.get('input').trigger('keydown.enter')
|
||||
expect(spy).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('will not select a value with tab if the user is composing', () => {
|
||||
const Select = mountDefault({ selectOnTab: true })
|
||||
const spy = jest.spyOn(Select.vm, 'typeAheadSelect')
|
||||
spy = jest.spyOn(typeAheadPointer.methods, 'typeAheadSelect')
|
||||
|
||||
Select.findComponent({ ref: 'search' }).trigger('compositionstart')
|
||||
Select.findComponent({ ref: 'search' }).trigger('keydown.tab')
|
||||
const Select = mountDefault({ selectOnTab: true })
|
||||
|
||||
Select.get('input').trigger('compositionstart')
|
||||
Select.get('input').trigger('keydown.tab')
|
||||
expect(spy).toHaveBeenCalledTimes(0)
|
||||
|
||||
Select.findComponent({ ref: 'search' }).trigger('compositionend')
|
||||
Select.findComponent({ ref: 'search' }).trigger('keydown.tab')
|
||||
Select.get('input').trigger('compositionend')
|
||||
Select.get('input').trigger('keydown.tab')
|
||||
expect(spy).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user