Skip to content

Commit 602bffb

Browse files
author
Eleftherios Pegiadis
committed
Add test cases for the filterOptions prop
1 parent 10d1897 commit 602bffb

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

test/unit/specs/Select.spec.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,15 @@ describe('Select.vue', () => {
295295
expect(vm.$refs.select.filteredOptions).toEqual(['bar','baz'])
296296
})
297297

298+
it('should not filter the array of strings if filterOptions is false', () => {
299+
const vm = new Vue({
300+
template: `<div><v-select ref="select" :filter-options="false" :options="['foo','bar','baz']" v-model="value"></v-select></div>`,
301+
data: {value: 'foo'}
302+
}).$mount()
303+
vm.$refs.select.search = 'ba'
304+
expect(vm.$refs.select.filteredOptions).toEqual(['foo','bar','baz'])
305+
})
306+
298307
it('should filter without case-sensitivity', () => {
299308
const vm = new Vue({
300309
template: `<div><v-select ref="select" :options="['Foo','Bar','Baz']" v-model="value"></v-select></div>`,
@@ -872,6 +881,21 @@ describe('Select.vue', () => {
872881
expect(vm.$children[0].mutableOptions).toEqual(['one', 'two', 'three'])
873882
})
874883

884+
it('should add a freshly created option/tag to the options list when pushTags is true and filterOptions is false', () => {
885+
const vm = new Vue({
886+
template: '<div><v-select :options="options" push-tags :value="value" :filter-options="false" :multiple="true" :taggable="true"></v-select></div>',
887+
components: {vSelect},
888+
data: {
889+
value: ['one'],
890+
options: ['one', 'two']
891+
}
892+
}).$mount()
893+
894+
searchSubmit(vm, 'three')
895+
expect(vm.$children[0].mutableOptions).toEqual(['one', 'two', 'three'])
896+
expect(vm.$children[0].filteredOptions).toEqual(['one', 'two', 'three'])
897+
})
898+
875899
it('wont add a freshly created option/tag to the options list when pushTags is false', () => {
876900
const vm = new Vue({
877901
template: '<div><v-select :options="options" :value="value" :multiple="true" :taggable="true"></v-select></div>',
@@ -886,6 +910,21 @@ describe('Select.vue', () => {
886910
expect(vm.$children[0].mutableOptions).toEqual(['one', 'two'])
887911
})
888912

913+
it('wont add a freshly created option/tag to the options list when pushTags is false and filterOptions is false', () => {
914+
const vm = new Vue({
915+
template: '<div><v-select :options="options" :value="value" :multiple="true" :filter-options="false" :taggable="true"></v-select></div>',
916+
components: {vSelect},
917+
data: {
918+
value: ['one'],
919+
options: ['one', 'two']
920+
}
921+
}).$mount()
922+
923+
searchSubmit(vm, 'three')
924+
expect(vm.$children[0].mutableOptions).toEqual(['one', 'two'])
925+
expect(vm.$children[0].filteredOptions).toEqual(['one', 'two'])
926+
})
927+
889928
it('should select an existing option if the search string matches a string from options', (done) => {
890929
let two = 'two'
891930
const vm = new Vue({
@@ -927,6 +966,28 @@ describe('Select.vue', () => {
927966
})
928967
})
929968

969+
it('should select an existing option if the search string matches an objects label from options when filter-options is false', (done) => {
970+
let two = {label: 'two'}
971+
const vm = new Vue({
972+
template: '<div><v-select :options="options" taggable :filter-options="false"></v-select></div>',
973+
data: {
974+
options: [{label: 'one'}, two]
975+
}
976+
}).$mount()
977+
978+
vm.$children[0].search = 'two'
979+
980+
Vue.nextTick(() => {
981+
searchSubmit(vm)
982+
// This needs to be wrapped in nextTick() twice so that filteredOptions can
983+
// calculate after setting the search text, and move the typeAheadPointer index to 0.
984+
Vue.nextTick(() => {
985+
expect(vm.$children[0].mutableValue.label).toBe(two.label)
986+
done()
987+
})
988+
})
989+
})
990+
930991
it('should not reset the selected value when the options property changes', (done) => {
931992
const vm = new Vue({
932993
template: '<div><v-select :options="options" :value="value" :multiple="true" taggable></v-select></div>',
@@ -943,6 +1004,22 @@ describe('Select.vue', () => {
9431004
})
9441005
})
9451006

1007+
it('should not reset the selected value when the options property changes when filterOptions is false', (done) => {
1008+
const vm = new Vue({
1009+
template: '<div><v-select :options="options" :value="value" :multiple="true" :filter-options="false" taggable></v-select></div>',
1010+
components: {vSelect},
1011+
data: {
1012+
value: [{label: 'one'}],
1013+
options: [{label: 'one'}]
1014+
}
1015+
}).$mount()
1016+
vm.$children[0].mutableOptions = [{label: 'two'}]
1017+
Vue.nextTick(() => {
1018+
expect(vm.$children[0].mutableValue).toEqual([{label: 'one'}])
1019+
done()
1020+
})
1021+
})
1022+
9461023
it('should not allow duplicate tags when using string options', (done) => {
9471024
const vm = new Vue({
9481025
template: `<div><v-select ref="select" taggable multiple></v-select></div>`,

0 commit comments

Comments
 (0)