mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-19 09:50:33 +03:00
feat: add deselectFromDropdown boolean prop (#1033)
This commit is contained in:
@@ -51,6 +51,7 @@ describe('Removing values', () => {
|
||||
it('will not emit input event if value has not changed with backspace', () => {
|
||||
const Select = mountDefault()
|
||||
Select.vm.$data._value = 'one'
|
||||
|
||||
Select.findComponent({ ref: 'search' }).trigger('keydown.backspace')
|
||||
expect(Select.emitted().input.length).toBe(1)
|
||||
|
||||
@@ -59,6 +60,58 @@ describe('Removing values', () => {
|
||||
expect(Select.emitted().input.length).toBe(1)
|
||||
})
|
||||
|
||||
it('should deselect a selected option when clicked and deselectFromDropdown is true', async () => {
|
||||
const Select = selectWithProps({
|
||||
value: 'one',
|
||||
options: ['one', 'two', 'three'],
|
||||
deselectFromDropdown: true,
|
||||
})
|
||||
const deselect = spyOn(Select.vm, 'deselect')
|
||||
|
||||
Select.vm.open = true
|
||||
await Select.vm.$nextTick()
|
||||
|
||||
Select.find('.vs__dropdown-option--selected').trigger('click')
|
||||
await Select.vm.$nextTick()
|
||||
|
||||
expect(deselect).toHaveBeenCalledWith('one')
|
||||
})
|
||||
|
||||
it('should not deselect a selected option when clicked if clearable is false', async () => {
|
||||
const Select = selectWithProps({
|
||||
value: 'one',
|
||||
options: ['one', 'two', 'three'],
|
||||
clearable: false,
|
||||
deselectFromDropdown: true,
|
||||
})
|
||||
const deselect = spyOn(Select.vm, 'deselect')
|
||||
|
||||
Select.vm.open = true
|
||||
await Select.vm.$nextTick()
|
||||
|
||||
Select.find('.vs__dropdown-option--selected').trigger('click')
|
||||
await Select.vm.$nextTick()
|
||||
|
||||
expect(deselect).not.toHaveBeenCalledWith('one')
|
||||
})
|
||||
|
||||
it('should not deselect a selected option when clicked if deselectFromDropdown is false', async () => {
|
||||
const Select = selectWithProps({
|
||||
value: 'one',
|
||||
options: ['one', 'two', 'three'],
|
||||
deselectFromDropdown: false,
|
||||
})
|
||||
const deselect = spyOn(Select.vm, 'deselect')
|
||||
|
||||
Select.vm.open = true
|
||||
await Select.vm.$nextTick()
|
||||
|
||||
Select.find('.vs__dropdown-option--selected').trigger('click')
|
||||
await Select.vm.$nextTick()
|
||||
|
||||
expect(deselect).not.toHaveBeenCalledWith('one')
|
||||
})
|
||||
|
||||
describe('Clear button', () => {
|
||||
it('should be displayed on single select when value is selected', () => {
|
||||
const Select = selectWithProps({
|
||||
|
||||
Reference in New Issue
Block a user