mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-13 08:32:26 +03:00
feat: merge upstream into beta channel (#1589)
This commit is contained in:
+14
-2
@@ -9,11 +9,23 @@ import Vue from 'vue'
|
||||
* @param Wrapper {Wrapper<Vue>}
|
||||
* @param searchText
|
||||
*/
|
||||
export const searchSubmit = (Wrapper, searchText = false) => {
|
||||
export const searchSubmit = async (Wrapper, searchText = undefined) => {
|
||||
await Wrapper.get('input').trigger('focus')
|
||||
|
||||
if (searchText) {
|
||||
Wrapper.vm.search = searchText
|
||||
await Wrapper.vm.$nextTick()
|
||||
}
|
||||
Wrapper.get('input').trigger('keydown.enter')
|
||||
|
||||
await Wrapper.get('input').trigger('keydown.enter')
|
||||
}
|
||||
|
||||
/**
|
||||
* Focus the search input
|
||||
*/
|
||||
export const searchFocus = async (Wrapper) => {
|
||||
await Wrapper.get('input').trigger('focus')
|
||||
await Wrapper.vm.$nextTick()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,7 @@ describe('Search Slot Scope', () => {
|
||||
/**
|
||||
* @see https://www.w3.org/WAI/PF/aria/states_and_properties#aria-activedescendant
|
||||
*/
|
||||
describe('aria-activedescendant', () => {
|
||||
fdescribe('aria-activedescendant', () => {
|
||||
it('adds the active descendant attribute only when the dropdown is open and there is a typeAheadPointer value', async () => {
|
||||
const Select = mountDefault()
|
||||
|
||||
@@ -21,7 +21,11 @@ describe('Search Slot Scope', () => {
|
||||
})
|
||||
|
||||
it("adds the active descendant attribute when there's a typeahead value and an open dropdown", async () => {
|
||||
const Select = mountDefault()
|
||||
const Select = mountDefault({ modelValue: 'three' }, [
|
||||
'one',
|
||||
'two',
|
||||
'three',
|
||||
])
|
||||
|
||||
Select.vm.open = true
|
||||
Select.vm.typeAheadPointer = 1
|
||||
@@ -29,7 +33,7 @@ describe('Search Slot Scope', () => {
|
||||
|
||||
expect(
|
||||
Select.vm.scope.search.attributes['aria-activedescendant']
|
||||
).toEqual(`vs${Select.vm.uid}__option-1`)
|
||||
).toEqual(`vs${Select.vm.uid}__option-2`)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { searchSubmit, selectTag, selectWithProps } from '../helpers'
|
||||
import { selectTag, selectWithProps } from '../helpers'
|
||||
|
||||
describe('CreateOption When Tagging Is Enabled', () => {
|
||||
it('can select the current search text as a string', async () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { selectWithProps } from '../helpers'
|
||||
import { searchSubmit, selectWithProps } from '../helpers'
|
||||
|
||||
describe('Selectable prop', () => {
|
||||
it('should select selectable option if clicked', async () => {
|
||||
@@ -54,4 +54,19 @@ describe('Selectable prop', () => {
|
||||
|
||||
expect(Select.vm.typeAheadPointer).toEqual(0)
|
||||
})
|
||||
|
||||
it('should not let the user select an unselectable option with return', async () => {
|
||||
const Select = selectWithProps({
|
||||
options: ['one', 'two'],
|
||||
multiple: true,
|
||||
selectable: (option) => option !== 'two',
|
||||
})
|
||||
|
||||
// this sets the typeAheadPointer to 0
|
||||
await searchSubmit(Select, 'one')
|
||||
expect(Select.vm.selectedValue).toEqual(['one'])
|
||||
|
||||
await searchSubmit(Select, 'two')
|
||||
expect(Select.vm.selectedValue).toEqual(['one'])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -218,6 +218,23 @@ describe('VS - Selecting Values', () => {
|
||||
expect(Select.vm.selectedValue).toEqual(options)
|
||||
})
|
||||
|
||||
fit('can select a false boolean option', async () => {
|
||||
const Select = mountDefault({
|
||||
options: [false],
|
||||
})
|
||||
|
||||
expect(Select.vm.isOptionSelected(false)).toBeFalsy()
|
||||
expect(Select.vm.optionExists(false)).toBeTruthy()
|
||||
|
||||
Select.vm.open = true
|
||||
await Select.vm.$nextTick()
|
||||
|
||||
Select.find('.vs__dropdown-option').trigger('click')
|
||||
await Select.vm.$nextTick()
|
||||
|
||||
expect(Select.vm.selectedValue).toEqual([false])
|
||||
})
|
||||
|
||||
describe('input Event', () => {
|
||||
it('will trigger the input event when the selection changes', () => {
|
||||
const Select = shallowMount(VueSelect)
|
||||
|
||||
@@ -165,10 +165,7 @@ describe('When Tagging Is Enabled', () => {
|
||||
options: [{ label: 'one' }, two],
|
||||
})
|
||||
|
||||
Select.vm.search = 'two'
|
||||
await Select.vm.$nextTick()
|
||||
|
||||
searchSubmit(Select)
|
||||
await searchSubmit(Select, 'two')
|
||||
expect(Select.vm.selectedValue).toEqual([two])
|
||||
})
|
||||
|
||||
@@ -180,10 +177,7 @@ describe('When Tagging Is Enabled', () => {
|
||||
options: [{ label: 'one' }, two],
|
||||
})
|
||||
|
||||
Select.vm.search = 'two'
|
||||
await Select.vm.$nextTick()
|
||||
|
||||
searchSubmit(Select)
|
||||
await searchSubmit(Select, 'two')
|
||||
expect(Select.vm.selectedValue).toEqual([two])
|
||||
})
|
||||
|
||||
|
||||
@@ -44,4 +44,37 @@ describe('Moving the Typeahead Pointer', () => {
|
||||
Select.vm.typeAheadDown()
|
||||
expect(Select.vm.typeAheadPointer).toEqual(2)
|
||||
})
|
||||
|
||||
it('will set the pointer to the selected option when opening', async () => {
|
||||
const Select = shallowMount(VueSelect, {
|
||||
propsData: {
|
||||
modelValue: 'three',
|
||||
options: ['one', 'two', 'three'],
|
||||
},
|
||||
})
|
||||
|
||||
Select.get('input').trigger('focus')
|
||||
await Select.vm.$nextTick()
|
||||
|
||||
expect(Select.vm.typeAheadPointer).toEqual(2)
|
||||
})
|
||||
|
||||
it('will set the pointer to the reduced selected option when opening', async () => {
|
||||
const Select = shallowMount(VueSelect, {
|
||||
propsData: {
|
||||
modelValue: 3,
|
||||
reduce: ({ value }) => value,
|
||||
options: [
|
||||
{ label: 'one', value: 1 },
|
||||
{ label: 'two', value: 2 },
|
||||
{ label: 'three', value: 3 },
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
Select.get('input').trigger('focus')
|
||||
await Select.vm.$nextTick()
|
||||
|
||||
expect(Select.vm.typeAheadPointer).toEqual(2)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user