Skip to content

Commit 84d4b7e

Browse files
committed
tests(1763): Add new func prop for sorting search results
1 parent 94c06e7 commit 84d4b7e

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/unit/Multiselect.spec.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,4 +1824,59 @@ describe('Multiselect.vue', () => {
18241824
expect(wrapper.get('.multiselect__input').attributes('required')).toBeUndefined()
18251825
})
18261826
})
1827+
describe('filteringSortFunc prop', () => {
1828+
const options = [
1829+
{ name: 'Vue.js', language: 'JavaScript' },
1830+
{ name: 'Laravel', language: 'PHP' },
1831+
{ name: 'Rails', language: 'Ruby' },
1832+
{ name: 'Sinatra', language: 'Ruby' },
1833+
{ name: 'Phoenix', language: 'Elixir' }
1834+
]
1835+
1836+
const customLabel = ({ name, language }) => {
1837+
return `${name} — [${language}]`
1838+
}
1839+
1840+
test('should use default sorting when no function is provided', async () => {
1841+
const wrapper = shallowMount(Multiselect, {
1842+
props: {
1843+
modelValue: [],
1844+
options,
1845+
customLabel,
1846+
label: 'name',
1847+
trackBy: 'name'
1848+
},
1849+
data () {
1850+
return {
1851+
search: 'a'
1852+
}
1853+
}
1854+
})
1855+
1856+
expect(wrapper.vm.filteredOptions[0].name).toBe('Rails')
1857+
expect(wrapper.vm.filteredOptions[3].name).toBe('Vue.js')
1858+
})
1859+
test('should use custom sorting when function is provided', async () => {
1860+
const wrapper = shallowMount(Multiselect, {
1861+
props: {
1862+
modelValue: [],
1863+
options,
1864+
customLabel,
1865+
label: 'name',
1866+
trackBy: 'name',
1867+
filteringSortFunc: (a, b) => {
1868+
return a.name.length - b.name.length
1869+
}
1870+
},
1871+
data () {
1872+
return {
1873+
search: 'a'
1874+
}
1875+
}
1876+
})
1877+
expect(wrapper.vm.filteredOptions[0].name).toBe('Rails')
1878+
expect(wrapper.vm.filteredOptions[1].name).toBe('Vue.js')
1879+
expect(wrapper.vm.filteredOptions[2].name).toBe('Laravel')
1880+
})
1881+
})
18271882
})

0 commit comments

Comments
 (0)