2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-05-26 04:34:04 +03:00
Files
vue-select/tests/unit/Autoscroll.spec.js
T
Jeff Sagal 06177a4d24 feat: Vue 3 Support (#1344)
BREAKING CHANGE: drop vue 2 support
2021-10-19 18:53:22 -07:00

66 lines
1.7 KiB
JavaScript

import pointerScroll from '../../src/mixins/pointerScroll'
import { mountDefault } from '../helpers'
describe('Automatic Scrolling', () => {
let spy
afterEach(() => {
if (spy) spy.mockClear()
})
it('should check if the scroll position needs to be adjusted on up arrow keyUp', async () => {
// Given
spy = jest.spyOn(pointerScroll.methods, 'maybeAdjustScroll')
const Select = mountDefault()
Select.vm.typeAheadPointer = 1
// When
await Select.get('input').trigger('keydown.up')
// Then
expect(spy).toHaveBeenCalled()
})
it('should check if the scroll position needs to be adjusted on down arrow keyUp', async () => {
// Given
spy = jest.spyOn(pointerScroll.methods, 'maybeAdjustScroll')
const Select = mountDefault()
Select.vm.typeAheadPointer = 1
// When
await Select.get('input').trigger('keydown.down')
// Then
expect(spy).toHaveBeenCalled()
})
it('should check if the scroll position needs to be adjusted when filtered options changes', async () => {
// Given
spy = jest.spyOn(pointerScroll.methods, 'maybeAdjustScroll')
const Select = mountDefault()
Select.vm.typeAheadPointer = 1
// When
Select.vm.search = 'two'
await Select.vm.$nextTick()
// Then
expect(spy).toHaveBeenCalled()
})
it('should not adjust scroll position when autoscroll is false', async () => {
// Given
spy = jest.spyOn(pointerScroll.methods, 'maybeAdjustScroll')
const Select = mountDefault({
autoscroll: false,
})
Select.vm.typeAheadPointer = 1
// When
Select.vm.search = 'two'
await Select.vm.$nextTick()
// Then
expect(spy).toHaveBeenCalledTimes(0)
})
})