Skip to content

Commit 4d881ac

Browse files
committed
test: add popconfirm test
1 parent ed80df3 commit 4d881ac

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Popconfirm should show overlay when trigger is clicked 1`] = `
4+
<div class="ant-popover-content">
5+
<div class="ant-popover-arrow"></div>
6+
<div class="ant-popover-inner">
7+
<div class="ant-popover-inner-content">
8+
<div class="ant-popover-message">
9+
<i class="anticon anticon-exclamation-circle"></i>
10+
<div class="ant-popover-message-title">code</div>
11+
</div>
12+
<div class="ant-popover-buttons">
13+
<button type="button" class="ant-btn ant-btn-default ant-btn-sm"><span>Cancel</span></button>
14+
<button type="button" class="ant-btn ant-btn-primary ant-btn-sm"><span>OK</span></button>
15+
</div>
16+
</div>
17+
</div>
18+
</div>
19+
`;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { mount } from '@vue/test-utils'
2+
import { asyncExpect } from '@/tests/utils'
3+
import Popconfirm from '..'
4+
function $$ (className) {
5+
return document.body.querySelectorAll(className)
6+
}
7+
describe('Popconfirm', () => {
8+
it('should popup Popconfirm dialog', async () => {
9+
const onVisibleChange = jest.fn()
10+
11+
const wrapper = mount(
12+
{
13+
render () {
14+
return <Popconfirm
15+
title={<span class='popconfirm-test'>Are you sure delete this task?</span>}
16+
okText='Yes'
17+
cancelText='No'
18+
mouseEnterDelay={0}
19+
mouseLeaveDelay={0}
20+
onVisibleChange={onVisibleChange}
21+
>
22+
<span>Delete</span>
23+
</Popconfirm>
24+
},
25+
}, { sync: false, attachToDocument: true })
26+
let triggerNode = null
27+
await asyncExpect(() => {
28+
triggerNode = wrapper.findAll('span').at(0)
29+
triggerNode.trigger('click')
30+
})
31+
await asyncExpect(() => {
32+
expect(onVisibleChange).toBeCalledWith(true)
33+
expect($$('.popconfirm-test').length).toBe(1)
34+
triggerNode.trigger('click')
35+
}, 1000)
36+
await asyncExpect(() => {
37+
expect(onVisibleChange).toBeCalledWith(false)
38+
})
39+
})
40+
41+
it('should show overlay when trigger is clicked', async () => {
42+
const popconfirm = mount({
43+
render () {
44+
return <Popconfirm ref='popconfirm' title='code'>
45+
<span>show me your code</span>
46+
</Popconfirm>
47+
},
48+
}, { sync: false })
49+
50+
await asyncExpect(() => {
51+
expect(popconfirm.vm.$refs.popconfirm.getPopupDomNode()).toBe(null)
52+
53+
popconfirm.find('span').trigger('click')
54+
}, 1000)
55+
await asyncExpect(() => {
56+
const popup = popconfirm.vm.$refs.popconfirm.getPopupDomNode()
57+
expect(popup).not.toBe(null)
58+
expect(popup.className).toContain('ant-popover-placement-top')
59+
expect(popup.innerHTML).toMatchSnapshot()
60+
}, 1000)
61+
})
62+
})

0 commit comments

Comments
 (0)