2022-01-04 09:15:15 +08:00
|
|
|
import { nextTick, ref } from 'vue'
|
2022-04-19 12:46:57 +08:00
|
|
|
import { afterEach, describe, expect, test } from 'vitest'
|
2020-10-19 13:44:50 +08:00
|
|
|
import makeMount from '@element-plus/test-utils/make-mount'
|
2020-12-03 22:43:18 +08:00
|
|
|
import { rAF } from '@element-plus/test-utils/tick'
|
2021-08-24 13:36:48 +08:00
|
|
|
import Popover from '../src/index.vue'
|
|
|
|
import PopoverDirective, { VPopover } from '../src/directive'
|
2020-10-19 13:44:50 +08:00
|
|
|
|
|
|
|
const AXIOM = 'Rem is the best girl'
|
|
|
|
|
|
|
|
const Comp = {
|
|
|
|
template: `
|
2022-01-04 09:15:15 +08:00
|
|
|
<el-popover ref="popoverRef" title="title" :content="content" virtual-triggering trigger="click" />
|
|
|
|
<div v-popover="popoverRef" id="reference-node">
|
|
|
|
trigger
|
2020-10-19 13:44:50 +08:00
|
|
|
</div>
|
|
|
|
`,
|
|
|
|
components: {
|
|
|
|
[Popover.name]: Popover,
|
|
|
|
},
|
2022-01-04 09:15:15 +08:00
|
|
|
setup() {
|
2020-10-19 13:44:50 +08:00
|
|
|
return {
|
2022-01-04 09:15:15 +08:00
|
|
|
popoverRef: ref(null),
|
2020-10-19 13:44:50 +08:00
|
|
|
content: AXIOM,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const mount = makeMount(Comp, {
|
2021-09-04 19:29:28 +08:00
|
|
|
props: {},
|
2020-10-19 13:44:50 +08:00
|
|
|
global: {
|
|
|
|
directives: {
|
|
|
|
[VPopover]: PopoverDirective,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('v-popover', () => {
|
2022-01-04 09:15:15 +08:00
|
|
|
afterEach(() => {
|
|
|
|
document.body.innerHTML = ''
|
|
|
|
})
|
|
|
|
test('should render correctly', async () => {
|
2020-10-19 13:44:50 +08:00
|
|
|
const wrapper = mount()
|
2022-01-04 09:15:15 +08:00
|
|
|
await nextTick()
|
2020-10-19 13:44:50 +08:00
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(document.body.querySelector('.el-popover').innerHTML).toContain(
|
|
|
|
AXIOM
|
|
|
|
)
|
2020-12-03 22:43:18 +08:00
|
|
|
wrapper.unmount()
|
2020-10-19 13:44:50 +08:00
|
|
|
})
|
|
|
|
|
2022-04-19 12:46:57 +08:00
|
|
|
test('should show popover when reference is mounted', async () => {
|
2020-10-19 13:44:50 +08:00
|
|
|
const wrapper = mount()
|
|
|
|
await nextTick()
|
2022-01-04 09:15:15 +08:00
|
|
|
const refNode = '#reference-node'
|
2020-10-19 13:44:50 +08:00
|
|
|
expect(wrapper.find(refNode).exists()).toBe(true)
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
document.body.querySelector('.el-popover').getAttribute('style')
|
|
|
|
).toContain('display: none')
|
2022-01-11 10:24:48 +08:00
|
|
|
await wrapper.find(refNode).trigger('click', {
|
2022-01-04 09:15:15 +08:00
|
|
|
button: 0,
|
|
|
|
})
|
2020-12-03 22:43:18 +08:00
|
|
|
await nextTick()
|
2022-01-04 09:15:15 +08:00
|
|
|
await rAF()
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
document.body.querySelector('.el-popover').getAttribute('style')
|
|
|
|
).not.toContain('display: none')
|
2020-12-03 22:43:18 +08:00
|
|
|
wrapper.unmount()
|
2020-10-19 13:44:50 +08:00
|
|
|
})
|
|
|
|
})
|