|
| 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