2022-01-04 09:15:15 +08:00
|
|
|
import { nextTick } from 'vue'
|
2020-08-28 11:44:04 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
2022-01-04 09:15:15 +08:00
|
|
|
import { rAF } from '@element-plus/test-utils/tick'
|
2021-08-24 13:36:48 +08:00
|
|
|
import { EVENT_CODE } from '@element-plus/utils/aria'
|
2022-01-04 09:15:15 +08:00
|
|
|
import { ElTooltip } from '@element-plus/components/tooltip'
|
2020-08-28 11:44:04 +08:00
|
|
|
import Dropdown from '../src/dropdown.vue'
|
|
|
|
import DropdownItem from '../src/dropdown-item.vue'
|
|
|
|
import DropdownMenu from '../src/dropdown-menu.vue'
|
|
|
|
|
|
|
|
const MOUSE_ENTER_EVENT = 'mouseenter'
|
|
|
|
const MOUSE_LEAVE_EVENT = 'mouseleave'
|
2022-01-04 09:15:15 +08:00
|
|
|
const MOUSE_DOWN = 'mousedown'
|
2021-01-25 11:21:31 +08:00
|
|
|
const CONTEXTMENU = 'contextmenu'
|
2020-08-28 11:44:04 +08:00
|
|
|
|
2022-01-04 09:15:15 +08:00
|
|
|
jest.useFakeTimers()
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
const _mount = (template: string, data, otherObj?) =>
|
|
|
|
mount({
|
|
|
|
components: {
|
|
|
|
[Dropdown.name]: Dropdown,
|
|
|
|
[DropdownItem.name]: DropdownItem,
|
|
|
|
[DropdownMenu.name]: DropdownMenu,
|
|
|
|
},
|
|
|
|
template,
|
|
|
|
data,
|
|
|
|
...otherObj,
|
|
|
|
})
|
2020-08-28 11:44:04 +08:00
|
|
|
|
|
|
|
describe('Dropdown', () => {
|
|
|
|
test('create', async () => {
|
2021-09-27 15:25:58 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
|
|
|
<el-dropdown ref="b" placement="right">
|
|
|
|
<span class="el-dropdown-link" ref="a">
|
|
|
|
dropdown<i class="el-icon-arrow-down el-icon--right"></i>
|
|
|
|
</span>
|
|
|
|
<template #dropdown>
|
|
|
|
<el-dropdown-menu>
|
|
|
|
<el-dropdown-item>Apple</el-dropdown-item>
|
|
|
|
<el-dropdown-item>Orange</el-dropdown-item>
|
|
|
|
<el-dropdown-item>Cherry</el-dropdown-item>
|
|
|
|
<el-dropdown-item disabled>Peach</el-dropdown-item>
|
|
|
|
<el-dropdown-item divided>Pear</el-dropdown-item>
|
|
|
|
</el-dropdown-menu>
|
|
|
|
</template>
|
|
|
|
</el-dropdown>
|
|
|
|
`,
|
|
|
|
() => ({})
|
|
|
|
)
|
2022-01-04 09:15:15 +08:00
|
|
|
await nextTick()
|
|
|
|
const content = wrapper.findComponent(ElTooltip).vm as InstanceType<
|
|
|
|
typeof ElTooltip
|
|
|
|
>
|
|
|
|
const triggerElm = wrapper.find('.el-tooltip__trigger')
|
|
|
|
expect(content.open).toBe(false)
|
2020-08-28 11:44:04 +08:00
|
|
|
await triggerElm.trigger(MOUSE_ENTER_EVENT)
|
2022-01-04 09:15:15 +08:00
|
|
|
jest.runAllTimers()
|
|
|
|
await rAF()
|
|
|
|
expect(content.open).toBe(true)
|
2020-08-28 11:44:04 +08:00
|
|
|
await triggerElm.trigger(MOUSE_LEAVE_EVENT)
|
2022-01-04 09:15:15 +08:00
|
|
|
jest.runAllTimers()
|
|
|
|
await rAF()
|
|
|
|
expect(content.open).toBe(false)
|
2020-08-28 11:44:04 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('menu click', async () => {
|
2022-01-04 09:15:15 +08:00
|
|
|
const commandHandler = jest.fn()
|
2020-08-28 11:44:04 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
|
|
|
<el-dropdown ref="b" @command="commandHandler" placement="right">
|
|
|
|
<span class="el-dropdown-link" ref="a">
|
|
|
|
dropdown<i class="el-icon-arrow-down el-icon--right"></i>
|
|
|
|
</span>
|
|
|
|
<template #dropdown>
|
|
|
|
<el-dropdown-menu>
|
|
|
|
<el-dropdown-item command="a">Apple</el-dropdown-item>
|
|
|
|
<el-dropdown-item command="b">Orange</el-dropdown-item>
|
|
|
|
<el-dropdown-item ref="c" :command="myCommandObject">Cherry</el-dropdown-item>
|
|
|
|
<el-dropdown-item command="d">Peach</el-dropdown-item>
|
|
|
|
<el-dropdown-item command="e">Pear</el-dropdown-item>
|
|
|
|
</el-dropdown-menu>
|
|
|
|
</template>
|
|
|
|
</el-dropdown>
|
|
|
|
`,
|
|
|
|
() => ({
|
|
|
|
myCommandObject: { name: 'CommandC' },
|
|
|
|
name: '',
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
methods: {
|
2022-01-04 09:15:15 +08:00
|
|
|
commandHandler,
|
2020-08-28 11:44:04 +08:00
|
|
|
},
|
2021-09-04 19:29:28 +08:00
|
|
|
}
|
2020-08-28 11:44:04 +08:00
|
|
|
)
|
2022-01-04 09:15:15 +08:00
|
|
|
await nextTick()
|
2020-11-04 11:24:36 +08:00
|
|
|
// const content = wrapper.findComponent({ ref: 'b' }).vm as any
|
2022-01-04 09:15:15 +08:00
|
|
|
const triggerElm = wrapper.find('.el-tooltip__trigger')
|
2020-08-28 11:44:04 +08:00
|
|
|
await triggerElm.trigger(MOUSE_ENTER_EVENT)
|
2022-01-04 09:15:15 +08:00
|
|
|
await nextTick()
|
|
|
|
jest.runAllTimers()
|
|
|
|
await rAF()
|
|
|
|
await wrapper
|
|
|
|
.findComponent({ ref: 'c' })
|
|
|
|
.findComponent({
|
|
|
|
name: 'DropdownItemImpl',
|
|
|
|
})
|
|
|
|
.trigger('click')
|
|
|
|
await nextTick()
|
|
|
|
jest.runAllTimers()
|
|
|
|
await rAF()
|
|
|
|
expect(commandHandler).toHaveBeenCalled()
|
2020-08-28 11:44:04 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('trigger', async () => {
|
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
|
|
|
<el-dropdown trigger="click" ref="b" placement="right">
|
|
|
|
<span class="el-dropdown-link" ref="a">
|
|
|
|
dropdown<i class="el-icon-arrow-down el-icon--right"></i>
|
|
|
|
</span>
|
|
|
|
<template #dropdown>
|
|
|
|
<el-dropdown-menu>
|
|
|
|
<el-dropdown-item command="a">Apple</el-dropdown-item>
|
|
|
|
<el-dropdown-item command="b">Orange</el-dropdown-item>
|
|
|
|
<el-dropdown-item ref="c" :command="myCommandObject">Cherry</el-dropdown-item>
|
|
|
|
<el-dropdown-item command="d">Peach</el-dropdown-item>
|
|
|
|
<el-dropdown-item command="e">Pear</el-dropdown-item>
|
|
|
|
</el-dropdown-menu>
|
|
|
|
</template>
|
|
|
|
</el-dropdown>
|
|
|
|
`,
|
|
|
|
() => ({
|
|
|
|
myCommandObject: { name: 'CommandC' },
|
|
|
|
name: '',
|
2021-09-04 19:29:28 +08:00
|
|
|
})
|
2020-08-28 11:44:04 +08:00
|
|
|
)
|
2022-01-04 09:15:15 +08:00
|
|
|
await nextTick()
|
|
|
|
const content = wrapper.findComponent(ElTooltip).vm as InstanceType<
|
|
|
|
typeof ElTooltip
|
|
|
|
>
|
2020-08-28 11:44:04 +08:00
|
|
|
const triggerElm = wrapper.find('.el-dropdown-link')
|
2022-01-04 09:15:15 +08:00
|
|
|
expect(content.open).toBe(false)
|
2020-08-28 11:44:04 +08:00
|
|
|
await triggerElm.trigger(MOUSE_ENTER_EVENT)
|
2022-01-04 09:15:15 +08:00
|
|
|
jest.runAllTimers()
|
|
|
|
await rAF()
|
|
|
|
expect(content.open).toBe(false)
|
|
|
|
await triggerElm.trigger(MOUSE_DOWN, {
|
|
|
|
button: 0,
|
|
|
|
})
|
|
|
|
jest.runAllTimers()
|
|
|
|
await rAF()
|
|
|
|
expect(content.open).toBe(true)
|
2021-01-25 11:21:31 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('trigger contextmenu', async () => {
|
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
|
|
|
<el-dropdown trigger="contextmenu" ref="b" placement="right">
|
|
|
|
<span class="el-dropdown-link" ref="a">
|
|
|
|
dropdown<i class="el-icon-arrow-down el-icon--right"></i>
|
|
|
|
</span>
|
|
|
|
<template #dropdown>
|
|
|
|
<el-dropdown-menu>
|
|
|
|
<el-dropdown-item command="a">Apple</el-dropdown-item>
|
|
|
|
<el-dropdown-item command="b">Orange</el-dropdown-item>
|
|
|
|
<el-dropdown-item ref="c" :command="myCommandObject">Cherry</el-dropdown-item>
|
|
|
|
<el-dropdown-item command="d">Peach</el-dropdown-item>
|
|
|
|
<el-dropdown-item command="e">Pear</el-dropdown-item>
|
|
|
|
</el-dropdown-menu>
|
|
|
|
</template>
|
|
|
|
</el-dropdown>
|
|
|
|
`,
|
|
|
|
() => ({
|
|
|
|
myCommandObject: { name: 'CommandC' },
|
|
|
|
name: '',
|
2021-09-04 19:29:28 +08:00
|
|
|
})
|
2021-01-25 11:21:31 +08:00
|
|
|
)
|
2022-01-04 09:15:15 +08:00
|
|
|
await nextTick()
|
|
|
|
const content = wrapper.findComponent(ElTooltip).vm as InstanceType<
|
|
|
|
typeof ElTooltip
|
|
|
|
>
|
2021-01-25 11:21:31 +08:00
|
|
|
const triggerElm = wrapper.find('.el-dropdown-link')
|
2022-01-04 09:15:15 +08:00
|
|
|
expect(content.open).toBe(false)
|
2021-01-25 11:21:31 +08:00
|
|
|
await triggerElm.trigger(CONTEXTMENU)
|
2022-01-04 09:15:15 +08:00
|
|
|
jest.runAllTimers()
|
|
|
|
await rAF()
|
|
|
|
expect(content.open).toBe(true)
|
2020-08-28 11:44:04 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('split button', async () => {
|
2022-01-04 09:15:15 +08:00
|
|
|
const handleClick = jest.fn()
|
2020-08-28 11:44:04 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
|
|
|
<el-dropdown @click="handleClick" split-button type="primary" ref="b" placement="right">
|
|
|
|
dropdown
|
|
|
|
<template #dropdown>
|
|
|
|
<el-dropdown-menu>
|
|
|
|
<el-dropdown-item command="a">Apple</el-dropdown-item>
|
|
|
|
<el-dropdown-item command="b">Orange</el-dropdown-item>
|
|
|
|
<el-dropdown-item ref="c" :command="myCommandObject">Cherry</el-dropdown-item>
|
|
|
|
<el-dropdown-item command="d">Peach</el-dropdown-item>
|
|
|
|
<el-dropdown-item command="e">Pear</el-dropdown-item>
|
|
|
|
</el-dropdown-menu>
|
|
|
|
</template>
|
|
|
|
</el-dropdown>
|
|
|
|
`,
|
|
|
|
() => ({
|
|
|
|
myCommandObject: { name: 'CommandC' },
|
|
|
|
name: '',
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
methods: {
|
2022-01-04 09:15:15 +08:00
|
|
|
handleClick,
|
2020-08-28 11:44:04 +08:00
|
|
|
},
|
2021-09-04 19:29:28 +08:00
|
|
|
}
|
2020-08-28 11:44:04 +08:00
|
|
|
)
|
2022-01-04 09:15:15 +08:00
|
|
|
await nextTick()
|
|
|
|
const content = wrapper.findComponent(ElTooltip).vm as InstanceType<
|
|
|
|
typeof ElTooltip
|
|
|
|
>
|
2020-08-28 11:44:04 +08:00
|
|
|
const triggerElm = wrapper.find('.el-dropdown__caret-button')
|
|
|
|
const button = wrapper.find('.el-button')
|
2022-01-04 09:15:15 +08:00
|
|
|
expect(content.open).toBe(false)
|
2020-08-28 11:44:04 +08:00
|
|
|
await button.trigger('click')
|
2022-01-04 09:15:15 +08:00
|
|
|
expect(handleClick).toHaveBeenCalled()
|
2020-08-28 11:44:04 +08:00
|
|
|
await triggerElm.trigger(MOUSE_ENTER_EVENT)
|
2022-01-04 09:15:15 +08:00
|
|
|
jest.runAllTimers()
|
|
|
|
await rAF()
|
|
|
|
expect(content.open).toBe(true)
|
2020-08-28 11:44:04 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('hide on click', async () => {
|
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
|
|
|
<el-dropdown ref="b" placement="right" :hide-on-click="false">
|
|
|
|
<span class="el-dropdown-link" ref="a">
|
|
|
|
dropdown<i class="el-icon-arrow-down el-icon--right"></i>
|
|
|
|
</span>
|
|
|
|
<template #dropdown>
|
|
|
|
<el-dropdown-menu>
|
|
|
|
<el-dropdown-item>Apple</el-dropdown-item>
|
|
|
|
<el-dropdown-item>Orange</el-dropdown-item>
|
|
|
|
<el-dropdown-item ref="c">Cherry</el-dropdown-item>
|
|
|
|
<el-dropdown-item disabled>Peach</el-dropdown-item>
|
|
|
|
<el-dropdown-item divided>Pear</el-dropdown-item>
|
|
|
|
</el-dropdown-menu>
|
|
|
|
</template>
|
|
|
|
</el-dropdown>
|
|
|
|
`,
|
2021-09-04 19:29:28 +08:00
|
|
|
() => ({})
|
2020-08-28 11:44:04 +08:00
|
|
|
)
|
2022-01-04 09:15:15 +08:00
|
|
|
await nextTick()
|
|
|
|
const content = wrapper.findComponent(ElTooltip).vm as InstanceType<
|
|
|
|
typeof ElTooltip
|
|
|
|
>
|
|
|
|
expect(content.open).toBe(false)
|
|
|
|
const triggerElm = wrapper.find('.el-tooltip__trigger')
|
2020-08-28 11:44:04 +08:00
|
|
|
await triggerElm.trigger(MOUSE_ENTER_EVENT)
|
2022-01-04 09:15:15 +08:00
|
|
|
jest.runAllTimers()
|
|
|
|
await rAF()
|
|
|
|
expect(content.open).toBe(true)
|
|
|
|
await wrapper
|
|
|
|
.findComponent({ ref: 'c' })
|
|
|
|
.findComponent({
|
|
|
|
name: 'DropdownItemImpl',
|
|
|
|
})
|
|
|
|
.trigger('click')
|
|
|
|
jest.runAllTimers()
|
|
|
|
await rAF()
|
|
|
|
expect(content.open).toBe(true)
|
2020-08-28 11:44:04 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('triggerElm keydown', async () => {
|
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
|
|
|
<el-dropdown ref="b" placement="right" :hide-on-click="false">
|
|
|
|
<span class="el-dropdown-link" ref="a">
|
|
|
|
dropdown<i class="el-icon-arrow-down el-icon--right"></i>
|
|
|
|
</span>
|
|
|
|
<template #dropdown>
|
|
|
|
<el-dropdown-menu>
|
|
|
|
<el-dropdown-item>Apple</el-dropdown-item>
|
|
|
|
<el-dropdown-item>Orange</el-dropdown-item>
|
|
|
|
<el-dropdown-item ref="c">Cherry</el-dropdown-item>
|
|
|
|
<el-dropdown-item disabled>Peach</el-dropdown-item>
|
|
|
|
<el-dropdown-item divided>Pear</el-dropdown-item>
|
|
|
|
</el-dropdown-menu>
|
|
|
|
</template>
|
|
|
|
</el-dropdown>
|
|
|
|
`,
|
2021-09-04 19:29:28 +08:00
|
|
|
() => ({})
|
2020-08-28 11:44:04 +08:00
|
|
|
)
|
2022-01-04 09:15:15 +08:00
|
|
|
await nextTick()
|
|
|
|
const content = wrapper.findComponent(ElTooltip).vm as InstanceType<
|
|
|
|
typeof ElTooltip
|
|
|
|
>
|
|
|
|
const triggerElm = wrapper.find('.el-tooltip__trigger')
|
2020-08-28 11:44:04 +08:00
|
|
|
await triggerElm.trigger(MOUSE_ENTER_EVENT)
|
2022-01-04 09:15:15 +08:00
|
|
|
jest.runAllTimers()
|
|
|
|
await rAF()
|
2020-08-28 11:44:04 +08:00
|
|
|
await triggerElm.trigger('keydown', {
|
2020-09-22 21:01:10 +08:00
|
|
|
code: EVENT_CODE.enter,
|
2020-08-28 11:44:04 +08:00
|
|
|
})
|
2022-01-04 09:15:15 +08:00
|
|
|
jest.runAllTimers()
|
|
|
|
await rAF()
|
|
|
|
expect(content.open).toBe(false)
|
2020-08-28 11:44:04 +08:00
|
|
|
|
|
|
|
await triggerElm.trigger(MOUSE_ENTER_EVENT)
|
2022-01-04 09:15:15 +08:00
|
|
|
jest.runAllTimers()
|
|
|
|
await rAF()
|
2020-08-28 11:44:04 +08:00
|
|
|
await triggerElm.trigger('keydown', {
|
2020-09-22 21:01:10 +08:00
|
|
|
code: EVENT_CODE.tab,
|
2020-08-28 11:44:04 +08:00
|
|
|
})
|
2022-01-04 09:15:15 +08:00
|
|
|
jest.runAllTimers()
|
|
|
|
await rAF()
|
|
|
|
expect(content.open).toBe(true)
|
2020-08-28 11:44:04 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('dropdown menu keydown', async () => {
|
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
|
|
|
<el-dropdown ref="b" placement="right" :hide-on-click="false">
|
|
|
|
<span class="el-dropdown-link" ref="a">
|
|
|
|
dropdown<i class="el-icon-arrow-down el-icon--right"></i>
|
|
|
|
</span>
|
|
|
|
<template #dropdown>
|
|
|
|
<el-dropdown-menu ref="a">
|
|
|
|
<el-dropdown-item ref="d">Apple</el-dropdown-item>
|
|
|
|
<el-dropdown-item>Orange</el-dropdown-item>
|
|
|
|
<el-dropdown-item ref="c">Cherry</el-dropdown-item>
|
|
|
|
<el-dropdown-item disabled>Peach</el-dropdown-item>
|
|
|
|
<el-dropdown-item divided>Pear</el-dropdown-item>
|
|
|
|
</el-dropdown-menu>
|
|
|
|
</template>
|
|
|
|
</el-dropdown>
|
|
|
|
`,
|
2021-09-04 19:29:28 +08:00
|
|
|
() => ({})
|
2020-08-28 11:44:04 +08:00
|
|
|
)
|
2022-01-04 09:15:15 +08:00
|
|
|
await nextTick()
|
2020-08-28 11:44:04 +08:00
|
|
|
const content = wrapper.findComponent({ ref: 'a' })
|
2022-01-04 09:15:15 +08:00
|
|
|
const triggerElm = wrapper.find('.el-tooltip__trigger')
|
2020-08-28 11:44:04 +08:00
|
|
|
await triggerElm.trigger(MOUSE_ENTER_EVENT)
|
2022-01-04 09:15:15 +08:00
|
|
|
jest.runAllTimers()
|
|
|
|
await rAF()
|
2020-08-28 11:44:04 +08:00
|
|
|
await content.trigger('keydown', {
|
2020-09-22 21:01:10 +08:00
|
|
|
code: EVENT_CODE.down,
|
2020-08-28 11:44:04 +08:00
|
|
|
})
|
2022-01-04 09:15:15 +08:00
|
|
|
jest.runAllTimers()
|
|
|
|
await rAF()
|
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.findComponent({ ref: 'd' })
|
|
|
|
.findComponent({
|
|
|
|
name: 'DropdownItemImpl',
|
|
|
|
})
|
|
|
|
.element.getAttribute('tabindex')
|
|
|
|
).toBe('0')
|
2021-02-08 15:14:01 +08:00
|
|
|
})
|
2020-08-28 11:44:04 +08:00
|
|
|
|
2021-02-08 15:14:01 +08:00
|
|
|
test('max height', async () => {
|
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
|
|
|
<el-dropdown ref="b" max-height="60px">
|
|
|
|
<span class="el-dropdown-link" ref="a">
|
|
|
|
dropdown<i class="el-icon-arrow-down el-icon--right"></i>
|
|
|
|
</span>
|
|
|
|
<template #dropdown>
|
|
|
|
<el-dropdown-menu>
|
|
|
|
<el-dropdown-item>Apple</el-dropdown-item>
|
|
|
|
<el-dropdown-item>Orange</el-dropdown-item>
|
|
|
|
<el-dropdown-item>Cherry</el-dropdown-item>
|
|
|
|
<el-dropdown-item disabled>Peach</el-dropdown-item>
|
|
|
|
<el-dropdown-item divided>Pear</el-dropdown-item>
|
|
|
|
</el-dropdown-menu>
|
|
|
|
</template>
|
|
|
|
</el-dropdown>
|
|
|
|
`,
|
2021-09-04 19:29:28 +08:00
|
|
|
() => ({})
|
2021-02-08 15:14:01 +08:00
|
|
|
)
|
2022-01-04 09:15:15 +08:00
|
|
|
await nextTick()
|
|
|
|
const scrollbar = wrapper
|
|
|
|
.findComponent({
|
|
|
|
ref: 'b',
|
|
|
|
})
|
|
|
|
.findComponent({ ref: 'scrollbar' })
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(scrollbar.find('.el-scrollbar__wrap').attributes('style')).toContain(
|
|
|
|
'max-height: 60px;'
|
|
|
|
)
|
2020-08-28 11:44:04 +08:00
|
|
|
})
|
2021-02-08 15:15:27 +08:00
|
|
|
|
|
|
|
test('tooltip debounce', async () => {
|
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
|
|
|
<el-dropdown ref="b">
|
|
|
|
<span class="el-dropdown-link">
|
|
|
|
dropdown<i class="el-icon-arrow-down el-icon--right"></i>
|
|
|
|
</span>
|
|
|
|
<template #dropdown>
|
|
|
|
<el-dropdown-menu>
|
|
|
|
<el-dropdown-item>Apple</el-dropdown-item>
|
|
|
|
<el-dropdown-item>Orange</el-dropdown-item>
|
|
|
|
<el-dropdown-item>Cherry</el-dropdown-item>
|
|
|
|
<el-dropdown-item>Peach</el-dropdown-item>
|
|
|
|
<el-dropdown-item>Pear</el-dropdown-item>
|
|
|
|
</el-dropdown-menu>
|
|
|
|
</template>
|
|
|
|
</el-dropdown>
|
|
|
|
`,
|
2021-09-04 19:29:28 +08:00
|
|
|
() => ({})
|
2021-02-08 15:15:27 +08:00
|
|
|
)
|
2022-01-04 09:15:15 +08:00
|
|
|
const content = wrapper.findComponent(ElTooltip).vm as InstanceType<
|
|
|
|
typeof ElTooltip
|
|
|
|
>
|
|
|
|
const triggerElm = wrapper.find('.el-tooltip__trigger')
|
|
|
|
expect(content.open).toBe(false)
|
2021-02-08 15:15:27 +08:00
|
|
|
await triggerElm.trigger(MOUSE_ENTER_EVENT)
|
|
|
|
await triggerElm.trigger(MOUSE_LEAVE_EVENT)
|
|
|
|
await triggerElm.trigger(MOUSE_ENTER_EVENT)
|
2022-01-04 09:15:15 +08:00
|
|
|
jest.runAllTimers()
|
|
|
|
await rAF()
|
|
|
|
expect(content.open).toBe(true)
|
2021-02-08 15:15:27 +08:00
|
|
|
})
|
2021-12-21 09:44:37 +08:00
|
|
|
|
|
|
|
test('popperClass', async () => {
|
|
|
|
const wrapper = await _mount(
|
|
|
|
`
|
|
|
|
<el-dropdown ref="b" max-height="60px" popper-class="custom-popper-class">
|
|
|
|
<span class="el-dropdown-link" ref="a">
|
|
|
|
dropdown<i class="el-icon-arrow-down el-icon--right"></i>
|
|
|
|
</span>
|
|
|
|
<template #dropdown>
|
|
|
|
<el-dropdown-menu>
|
|
|
|
<el-dropdown-item>Apple</el-dropdown-item>
|
|
|
|
<el-dropdown-item>Orange</el-dropdown-item>
|
|
|
|
<el-dropdown-item>Cherry</el-dropdown-item>
|
|
|
|
<el-dropdown-item disabled>Peach</el-dropdown-item>
|
|
|
|
<el-dropdown-item divided>Pear</el-dropdown-item>
|
|
|
|
</el-dropdown-menu>
|
|
|
|
</template>
|
|
|
|
</el-dropdown>
|
|
|
|
`,
|
|
|
|
() => ({})
|
|
|
|
)
|
2022-01-04 09:15:15 +08:00
|
|
|
|
|
|
|
const popperElement = wrapper.findComponent({
|
|
|
|
name: 'ElPopperContent',
|
|
|
|
}).element
|
2021-12-21 09:44:37 +08:00
|
|
|
|
|
|
|
expect(popperElement.classList.contains('custom-popper-class')).toBe(true)
|
|
|
|
})
|
2020-08-28 11:44:04 +08:00
|
|
|
})
|