2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-05-23 03:54:04 +03:00
Files
vue-select/tests/unit/Autoscroll.spec.js
T
Jeff Sagal 2eb39087fd feat: add autoscroll boolean prop (#1160)
* feat: add autoscroll boolean prop

Fixes #449

* refactor: update autoscroll implementation

Closes #1028
Closes #910

* refactor: only call maybeAdjustScroll in the watcher

* docs: upgrade vuepress
2020-04-12 15:44:52 -07:00

62 lines
1.6 KiB
JavaScript

import { mountDefault } from "../helpers";
describe("Automatic Scrolling", () => {
it("should check if the scroll position needs to be adjusted on up arrow keyUp", async () => {
// Given
const Select = mountDefault();
const spy = jest.spyOn(Select.vm, "maybeAdjustScroll");
Select.vm.typeAheadPointer = 1;
// When
Select.find({ ref: "search" }).trigger("keydown.up");
await Select.vm.$nextTick();
// Then
expect(spy).toHaveBeenCalled();
});
it("should check if the scroll position needs to be adjusted on down arrow keyUp", async () => {
// Given
const Select = mountDefault();
const spy = jest.spyOn(Select.vm, "maybeAdjustScroll");
Select.vm.typeAheadPointer = 1;
// When
Select.find({ ref: "search" }).trigger("keydown.down");
await Select.vm.$nextTick();
// Then
expect(spy).toHaveBeenCalled();
});
it("should check if the scroll position needs to be adjusted when filtered options changes", async () => {
// Given
const Select = mountDefault();
const spy = jest.spyOn(Select.vm, "maybeAdjustScroll");
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
const Select = mountDefault({
autoscroll: false
});
const spy = jest.spyOn(Select.vm, "maybeAdjustScroll");
Select.vm.typeAheadPointer = 1;
// When
Select.vm.search = "two";
await Select.vm.$nextTick();
// Then
expect(spy).toHaveBeenCalledTimes(0);
});
});