2022-05-30 09:39:31 +08:00
|
|
|
import { nextTick } from 'vue'
|
2020-10-16 11:14:45 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
2022-04-19 12:46:57 +08:00
|
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
2022-01-04 09:15:15 +08:00
|
|
|
import { rAF } from '@element-plus/test-utils/tick'
|
2022-02-04 14:59:58 +08:00
|
|
|
import { POPPER_CONTAINER_SELECTOR } from '@element-plus/hooks'
|
2022-05-30 09:39:31 +08:00
|
|
|
import Popconfirm from '../src/popconfirm.vue'
|
2021-08-24 13:36:48 +08:00
|
|
|
|
2022-01-04 09:15:15 +08:00
|
|
|
const AXIOM = 'rem is the best girl'
|
2020-10-16 11:14:45 +08:00
|
|
|
const selector = '.el-popper'
|
|
|
|
|
|
|
|
describe('Popconfirm.vue', () => {
|
2022-01-04 09:15:15 +08:00
|
|
|
afterEach(() => {
|
|
|
|
document.body.innerHTML = ''
|
|
|
|
})
|
|
|
|
|
2022-04-19 12:46:57 +08:00
|
|
|
it('render test', async () => {
|
2022-05-30 09:39:31 +08:00
|
|
|
const wrapper = mount(() => (
|
|
|
|
<>
|
|
|
|
<Popconfirm
|
|
|
|
attachTo="body"
|
|
|
|
v-slots={{
|
|
|
|
reference: () => <div class="reference">{AXIOM}</div>,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
))
|
2022-01-04 09:15:15 +08:00
|
|
|
await nextTick()
|
2020-10-16 11:14:45 +08:00
|
|
|
|
2022-01-04 09:15:15 +08:00
|
|
|
expect(document.querySelector(selector)!.getAttribute('style')).toContain(
|
2021-09-04 19:29:28 +08:00
|
|
|
'display: none'
|
|
|
|
)
|
2020-10-16 11:14:45 +08:00
|
|
|
|
2022-05-30 09:39:31 +08:00
|
|
|
await wrapper.find('.reference').trigger('click')
|
2022-01-04 09:15:15 +08:00
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
await rAF()
|
2020-10-16 11:14:45 +08:00
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
2022-01-04 09:15:15 +08:00
|
|
|
document.querySelector(selector)!.getAttribute('style')
|
2021-09-04 19:29:28 +08:00
|
|
|
).not.toContain('display: none')
|
2020-10-16 11:14:45 +08:00
|
|
|
})
|
2022-02-04 14:59:58 +08:00
|
|
|
|
|
|
|
describe('teleported API', () => {
|
|
|
|
it('should mount on popper container', async () => {
|
|
|
|
expect(document.body.innerHTML).toBe('')
|
2022-05-30 09:39:31 +08:00
|
|
|
mount(() => (
|
|
|
|
<>
|
|
|
|
<Popconfirm
|
|
|
|
attachTo="body"
|
|
|
|
v-slots={{
|
|
|
|
reference: () => <div class="reference">{AXIOM}</div>,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
))
|
2022-02-04 14:59:58 +08:00
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
expect(
|
|
|
|
document.body.querySelector(POPPER_CONTAINER_SELECTOR)!.innerHTML
|
|
|
|
).not.toBe('')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not mount on the popper container', async () => {
|
|
|
|
expect(document.body.innerHTML).toBe('')
|
2022-05-30 09:39:31 +08:00
|
|
|
mount(() => (
|
|
|
|
<>
|
|
|
|
<Popconfirm
|
|
|
|
attachTo="body"
|
|
|
|
teleported={false}
|
|
|
|
v-slots={{
|
|
|
|
reference: () => <div class="reference">{AXIOM}</div>,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
))
|
2022-02-04 14:59:58 +08:00
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
expect(
|
|
|
|
document.body.querySelector(POPPER_CONTAINER_SELECTOR)!.innerHTML
|
|
|
|
).toBe('')
|
|
|
|
})
|
|
|
|
})
|
2020-10-16 11:14:45 +08:00
|
|
|
})
|