2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-07 07:12:23 +03:00

- fix variable reference (showLoading should have been mutableLoading) in ajax mixin and specs

- add `search` event fired at same time as callback
This commit is contained in:
Jeff Sagal
2017-03-16 15:38:40 -07:00
parent 5470adbbd6
commit 546418da1f
2 changed files with 52 additions and 8 deletions
+5 -4
View File
@@ -33,9 +33,10 @@ module.exports = {
* invoke the onSearch callback.
*/
search() {
if (this.search.length > 0 && this.onSearch) {
if (this.search.length > 0) {
this.onSearch(this.search, this.toggleLoading)
}
this.$emit('search', this.search, this.toggleLoading)
}
},
},
@@ -49,9 +50,9 @@ module.exports = {
*/
toggleLoading(toggle = null) {
if (toggle == null) {
return this.showLoading = !this.showLoading
return this.mutableLoading = !this.mutableLoading
}
return this.showLoading = toggle
return this.mutableLoading = toggle
}
}
}
+47 -4
View File
@@ -931,10 +931,10 @@ describe('Select.vue', () => {
}).$mount()
vm.$refs.select.toggleLoading()
expect(vm.$refs.select.showLoading).toEqual(true)
expect(vm.$refs.select.mutableLoading).toEqual(true)
vm.$refs.select.toggleLoading(true)
expect(vm.$refs.select.showLoading).toEqual(true)
expect(vm.$refs.select.mutableLoading).toEqual(true)
})
it('should trigger the onSearch callback when the search text changes', (done) => {
@@ -980,6 +980,49 @@ describe('Select.vue', () => {
})
})
it('should trigger the search event when the search text changes', (done) => {
const vm = new Vue({
template: '<div><v-select ref="select" @search="foo"></v-select></div>',
data: {
called: false
},
methods: {
foo(val) {
this.called = val
}
}
}).$mount()
vm.$refs.select.search = 'foo'
Vue.nextTick(() => {
expect(vm.called).toEqual('foo')
done()
})
})
it('should not trigger the search event if the search text is empty', (done) => {
const vm = new Vue({
template: '<div><v-select ref="select" search="foo" @search="foo"></v-select></div>',
data: { called: false },
methods: {
foo(val) {
this.called = ! this.called
}
}
}).$mount()
vm.$refs.select.search = 'foo'
Vue.nextTick(() => {
expect(vm.called).toBe(true)
vm.$refs.select.search = ''
Vue.nextTick(() => {
expect(vm.called).toBe(true)
done()
})
})
})
it('can set loading to false from the onSearch callback', (done) => {
const vm = new Vue({
template: '<div><v-select loading ref="select" :on-search="foo"></v-select></div>',
@@ -992,7 +1035,7 @@ describe('Select.vue', () => {
vm.$refs.select.search = 'foo'
Vue.nextTick(() => {
expect(vm.$refs.select.showLoading).toEqual(false)
expect(vm.$refs.select.mutableLoading).toEqual(false)
done()
})
})
@@ -1011,7 +1054,7 @@ describe('Select.vue', () => {
select.onSearch(select.search, select.toggleLoading)
Vue.nextTick(() => {
expect(vm.$refs.select.showLoading).toEqual(true)
expect(vm.$refs.select.mutableLoading).toEqual(true)
done()
})
})