import { clear } from 'jest-date-mock'; import { BASE_CLASS_PREFIX } from '../../../semi-foundation/base/constants'; import Popconfirm from '../index'; import { Button } from '../../index'; import { genAfterEach, genBeforeEach, mount, sleep } from '../../_test_/utils'; const wrapCls = `${BASE_CLASS_PREFIX}-popconfirm`; const wrapSelector = `.${BASE_CLASS_PREFIX}-popover .${wrapCls}`; const triggerCls = 'trigger'; describe(`Popconfirm`, () => { beforeEach(() => { clear(); genBeforeEach()(); }); afterEach(genAfterEach()); it(`test appearance`, async () => { const elem = mount( ); // check if popconfirm hid or not expect(document.querySelectorAll(wrapSelector).length === 0).toBeTruthy(); const triggerElem = document.querySelector(`.${triggerCls}`); triggerElem.click(); // check if popconfirm showed or not expect(document.querySelectorAll(wrapSelector).length > 0).toBeTruthy(); }); it(`test disabled appearance`, async () => { const elem = mount( ); // check if popconfirm hid or not expect(document.querySelectorAll(wrapSelector).length === 0).toBeTruthy(); }); it(`test controlled appearance`, async () => { const props = { visible: true }; const toggleShow = sinon.spy(() => { props.visible = !props.visible; elem.setProps(props); }); const elem = mount( ); // check if popconfirm hid or not expect(document.querySelectorAll(wrapSelector).length > 0).toBeTruthy(); // click button and hide popconfirm const triggerBtn = document.querySelector(`.${triggerCls}`); triggerBtn.click(); await sleep(200); expect(toggleShow.called).toBeTruthy(); expect(elem.prop('visible')).toBeFalsy(); }); it(`test buttons`, async () => { const onCancel = sinon.spy(); const onConfirm = sinon.spy(); const elem = mount( ); // check if popconfirm showed or not expect(document.querySelectorAll(wrapSelector).length > 0).toBeTruthy(); // click cancel button and check if hid and trigger onCancel const buttons = document.querySelectorAll(`.${BASE_CLASS_PREFIX}-popconfirm-footer button`); const cancelButton = buttons[0]; cancelButton.click(); expect(onCancel.called).toBeTruthy(); expect(elem.state('visible')).toBeFalsy(); // click confirm button and check if showd and trigger onConfirm const confirmButton = buttons[1]; elem.setState({ visible: true }); confirmButton.click(); expect(onConfirm.called).toBeTruthy(); expect(elem.state('visible')).toBeFalsy(); }); });