2022-01-04 09:15:15 +08:00
|
|
|
import { h, nextTick } from 'vue'
|
2020-10-16 11:14:45 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
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'
|
2021-09-19 18:21:23 +08:00
|
|
|
import ElPopconfirm 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'
|
2021-09-04 19:29:28 +08:00
|
|
|
const _mount = (props: any = {}) =>
|
|
|
|
mount(ElPopconfirm, {
|
2022-01-04 09:15:15 +08:00
|
|
|
props: {
|
|
|
|
...props,
|
|
|
|
},
|
2021-09-04 19:29:28 +08:00
|
|
|
slots: {
|
|
|
|
reference: () =>
|
2022-01-04 09:15:15 +08:00
|
|
|
h(
|
|
|
|
'div',
|
|
|
|
{
|
|
|
|
class: 'reference',
|
|
|
|
},
|
|
|
|
[AXIOM]
|
|
|
|
),
|
2021-09-04 19:29:28 +08:00
|
|
|
},
|
|
|
|
attachTo: 'body',
|
|
|
|
})
|
2020-10-16 11:14:45 +08:00
|
|
|
|
|
|
|
describe('Popconfirm.vue', () => {
|
2022-01-04 09:15:15 +08:00
|
|
|
afterEach(() => {
|
|
|
|
document.body.innerHTML = ''
|
|
|
|
})
|
|
|
|
|
2020-10-16 11:14:45 +08:00
|
|
|
test('render test', async () => {
|
|
|
|
const wrapper = _mount()
|
2022-01-04 09:15:15 +08:00
|
|
|
await nextTick()
|
2020-10-16 11:14:45 +08:00
|
|
|
const trigger = wrapper.find('.reference')
|
|
|
|
|
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-01-11 10:24:48 +08:00
|
|
|
await trigger.trigger('click', {
|
2022-01-04 09:15:15 +08:00
|
|
|
button: 0,
|
|
|
|
})
|
|
|
|
|
|
|
|
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('')
|
|
|
|
_mount()
|
|
|
|
|
|
|
|
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('')
|
|
|
|
_mount({ teleported: false })
|
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
expect(
|
|
|
|
document.body.querySelector(POPPER_CONTAINER_SELECTOR)!.innerHTML
|
|
|
|
).toBe('')
|
|
|
|
})
|
|
|
|
})
|
2020-10-16 11:14:45 +08:00
|
|
|
})
|