2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-16 09:10:33 +03:00

Merge branch 'master' into 975-dropdown-option-slot-overhaul

# Conflicts:
#	dev/Dev.vue
#	src/components/Select.vue
This commit is contained in:
Jeff
2019-11-11 18:27:58 -08:00
13 changed files with 396 additions and 40 deletions
+74
View File
@@ -0,0 +1,74 @@
import { mountDefault } from '../helpers';
describe('Custom Keydown Handlers', () => {
it('can use the map-keydown prop to trigger custom behaviour', () => {
const onKeyDown = jest.fn();
const Select = mountDefault({
mapKeydown: (defaults, vm) => ({...defaults, 32: onKeyDown}),
});
Select.find({ref: 'search'}).trigger('keydown.space');
expect(onKeyDown.mock.calls.length).toBe(1);
});
it('selectOnKeyCodes should trigger a selection for custom keycodes', () => {
const Select = mountDefault({
selectOnKeyCodes: [32],
});
const spy = jest.spyOn(Select.vm, 'typeAheadSelect');
Select.find({ref: 'search'}).trigger('keydown.space');
expect(spy).toHaveBeenCalledTimes(1);
});
it('even works when combining selectOnKeyCodes with map-keydown', () => {
const onKeyDown = jest.fn();
const Select = mountDefault({
mapKeydown: (defaults, vm) => ({...defaults, 32: onKeyDown}),
selectOnKeyCodes: [9],
});
const spy = jest.spyOn(Select.vm, 'typeAheadSelect');
Select.find({ref: 'search'}).trigger('keydown.space');
expect(onKeyDown.mock.calls.length).toBe(1);
Select.find({ref: 'search'}).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');
Select.find({ref: 'search'}).trigger('compositionstart');
Select.find({ref: 'search'}).trigger('keydown.enter');
expect(spy).toHaveBeenCalledTimes(0);
Select.find({ref: 'search'}).trigger('compositionend');
Select.find({ref: 'search'}).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');
Select.find({ref: 'search'}).trigger('compositionstart');
Select.find({ref: 'search'}).trigger('keydown.tab');
expect(spy).toHaveBeenCalledTimes(0);
Select.find({ref: 'search'}).trigger('compositionend');
Select.find({ref: 'search'}).trigger('keydown.tab');
expect(spy).toHaveBeenCalledTimes(1);
});
});
});
+2 -2
View File
@@ -4,7 +4,7 @@ describe("Selectable prop", () => {
it("should select selectable option if clicked", () => {
const Select = selectWithProps({
options: ["one", "two", "three"],
selectable: (option) => option == "one"
selectable: (option) => option === "one"
});
Select.vm.$data.open = true;
@@ -16,7 +16,7 @@ describe("Selectable prop", () => {
it("should not select not selectable option if clicked", () => {
const Select = selectWithProps({
options: ["one", "two", "three"],
selectable: (option) => option == "one"
selectable: (option) => option === "one"
});
Select.vm.$data.open = true;
+14
View File
@@ -80,6 +80,20 @@ describe("When Tagging Is Enabled", () => {
expect(Select.vm.optionList).toEqual(["one", "two", "three"]);
});
it("should pushTags even if the consumer has defined a createOption callback", () => {
const Select = selectWithProps({
pushTags: true,
taggable: true,
createOption: option => option,
options: ["one", "two"]
});
searchSubmit(Select, "three");
expect(Select.vm.pushedTags).toEqual(["three"]);
expect(Select.vm.optionList).toEqual(["one", "two", "three"]);
});
it("should add a freshly created option/tag to the options list when pushTags is true and filterable is false", () => {
const Select = selectWithProps({
filterable: false,