Skip to content

Commit

Permalink
test: add tests for multiple select.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenesius committed Feb 20, 2024
1 parent 907b3fe commit 900ac31
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/integrations/inputs/input-select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,66 @@ describe("Input Select Testing", () => {
await app.vm.$nextTick();
expect(input.element.getAttribute('tabindex')).toBe("none")
})

test("Multiple attr should show first selected item as title", async () => {
const wrap = defaultMount(defineSelectComponent({
multiple: true,
options: defaultOptions
}))
const form = (wrap.vm as any).form;
form.setValues({
[name]: [defaultOptions[0].value]
})
await wrap.vm.$nextTick();
expect(wrap.text()).toBe(defaultOptions[0].label);
})
test("Multiple attr should show first selected item + N as title if was selected more then one", async () => {
const wrap = defaultMount(defineSelectComponent({
multiple: true,
options: defaultOptions
}))
const form = (wrap.vm as any).form;
form.setValues({
[name]: defaultOptions.map(i => i.value)
})
await wrap.vm.$nextTick();
expect(wrap.text()).toBe(defaultOptions[0].label + ' + ' + (defaultOptions.length - 1));
})

test("Multiple attr should show selected items", async () => {
const wrap = defaultMount(defineSelectComponent({
multiple: true,
options: defaultOptions
}))
const form = (wrap.vm as any).form as Form;
form.setValues({
[name]: [defaultOptions[1].value]
})
currentItem = wrap.find('.container-input-select-current')
expect(currentItem.exists()).toBe(true);
await currentItem.trigger('click');

expect(wrap.findAll('.input-select-option-list-item_active').map(item => item.text())).toEqual([defaultOptions[1].label])
})
test("Selecting items should update value(multiple attr", async () => {
const wrap = defaultMount(defineSelectComponent({
multiple: true,
options: defaultOptions
}))
const form = (wrap.vm as any).form as Form;
currentItem = wrap.find('.container-input-select-current')
await currentItem.trigger('click');

await wrap.findAll('.input-select-option-list-item').reduce((acc, item) => {
return acc.then(() => item.trigger('click'))
}, Promise.resolve())

expect(form.getValueByName(name)).toEqual(defaultOptions.map(item => item.value))

await wrap.findAll('.input-select-option-list-item').reduce((acc, item) => {
return acc.then(() => item.trigger('click'))
}, Promise.resolve())

expect(form.getValueByName(name)).toEqual([])
})
})

0 comments on commit 900ac31

Please sign in to comment.