forked from riophae/vue-treeselect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchInput.spec.js
62 lines (55 loc) · 1.65 KB
/
SearchInput.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { mount } from '@vue/test-utils'
import { findInput, typeSearchText } from './shared'
import Treeselect from '@src/components/Treeselect'
describe('Search Input', () => {
it('should disable auto complete', () => {
const wrapper = mount(Treeselect, {
propsData: {
options: [],
},
})
const input = findInput(wrapper)
expect(input.element.getAttribute('autocomplete')).toBe('off')
})
it('should be unable to focus when disabled=true', () => {
const wrapper = mount(Treeselect, {
propsData: {
options: [],
autoFocus: false,
searchable: true,
disabled: true,
},
})
expect(wrapper.vm.trigger.isFocused).toBe(false)
wrapper.vm.focusInput()
expect(wrapper.vm.trigger.isFocused).toBe(false)
})
it('when multiple=true, input should fit the width of user-input text', async () => {
const wrapper = mount(Treeselect, {
propsData: {
options: [],
multiple: true,
searchable: true,
},
attachToDocument: true,
sync: false,
})
const input = findInput(wrapper)
const fullText = 'hello world'
let i = 0
let prevWidth = input.element.offsetWidth
expect(prevWidth).toBeGreaterThan(0)
while (i < fullText.length) {
await typeSearchText(wrapper, fullText.slice(0, i += 3))
const width = input.element.offsetWidth
expect(width).toBeGreaterThan(prevWidth)
prevWidth = width
}
while (i > 0) {
await typeSearchText(wrapper, fullText.slice(0, i -= 3))
const width = input.element.offsetWidth
expect(width).toBeLessThan(prevWidth)
prevWidth = width
}
})
})