feat(components): [cascader] add unit test cases

This commit is contained in:
wangxiaoyu
2025-06-12 03:15:07 +08:00
parent b607f0cf0b
commit 8cbb9d44ee

View File

@@ -624,4 +624,40 @@ describe('Cascader.vue', () => {
expect(prefixSlotEl?.textContent).toBe('-=-prefix-=-')
})
})
describe('Cascader - showFirstLevelOnly', () => {
it('should only display first level label after clicking sub-option', async () => {
const wrapper = mount(() => <Cascader options={OPTIONS} topLevelOnly />)
const trigger = wrapper.find(TRIGGER)
await trigger.trigger('click')
;(document.querySelector(NODE) as HTMLElement).click()
await nextTick()
;(document.querySelectorAll(NODE)[1] as HTMLElement).click()
await nextTick()
expect(wrapper.find('input').element.value).toBe('Zhejiang')
})
it('should only display first level labels for multiple selected sub-options', async () => {
const wrapper = mount(() => (
<Cascader options={OPTIONS} topLevelOnly multiple />
))
const trigger = wrapper.find(TRIGGER)
await trigger.trigger('click')
await nextTick()
const firstNode = document.querySelector(NODE) as HTMLElement
expect(firstNode).not.toBeNull()
firstNode.click()
await nextTick()
const secondNode = document.querySelectorAll(NODE)[1] as HTMLElement
expect(secondNode).not.toBeNull()
secondNode.click()
await nextTick()
const thirdNode = document.querySelectorAll(NODE)[2] as HTMLElement
expect(thirdNode).not.toBeNull()
thirdNode.click()
await nextTick()
const inputValue = (wrapper.find('input').element as HTMLInputElement)
.value
expect(inputValue).toBe('Zhejiang')
})
})
})