import React from 'react'; import { mount, render } from 'enzyme'; import Alert from '..'; import Button from '../../button'; import Tooltip from '../../tooltip'; import Popconfirm from '../../popconfirm'; import rtlTest from '../../../tests/shared/rtlTest'; import { sleep } from '../../../tests/utils'; const { ErrorBoundary } = Alert; describe('Alert', () => { rtlTest(Alert); beforeAll(() => { jest.useFakeTimers(); }); afterAll(() => { jest.useRealTimers(); }); it('could be closed', () => { const onClose = jest.fn(); const wrapper = mount( , ); wrapper.find('.ant-alert-close-icon').simulate('click'); jest.runAllTimers(); expect(onClose).toHaveBeenCalled(); }); describe('action of Alert', () => { it('custom action', () => { const wrapper = render( UNDO } closable />, ); expect(wrapper).toMatchSnapshot(); }); }); describe('data and aria props', () => { it('sets data attributes on input', () => { const wrapper = mount(); const input = wrapper.find('.ant-alert').getDOMNode(); expect(input.getAttribute('data-test')).toBe('test-id'); expect(input.getAttribute('data-id')).toBe('12345'); }); it('sets aria attributes on input', () => { const wrapper = mount(); const input = wrapper.find('.ant-alert').getDOMNode(); expect(input.getAttribute('aria-describedby')).toBe('some-label'); }); it('sets role attribute on input', () => { const wrapper = mount(); const input = wrapper.find('.ant-alert').getDOMNode(); expect(input.getAttribute('role')).toBe('status'); }); }); const testIt = process.env.REACT === '15' ? it.skip : it; testIt('ErrorBoundary', () => { // @ts-expect-error // eslint-disable-next-line react/jsx-no-undef const ThrowError = () => ; const wrapper = mount( , ); // eslint-disable-next-line jest/no-standalone-expect expect(wrapper.render()).toMatchSnapshot(); }); it('could be used with Tooltip', async () => { const ref = React.createRef(); jest.useRealTimers(); const wrapper = mount( , ); wrapper.find('.ant-alert').simulate('mouseenter'); await sleep(0); expect(ref.current.getPopupDomNode()).toBeTruthy(); jest.useFakeTimers(); }); it('could be used with Popconfirm', async () => { const ref = React.createRef(); jest.useRealTimers(); const wrapper = mount( , ); wrapper.find('.ant-alert').simulate('click'); await sleep(0); expect(ref.current.getPopupDomNode()).toBeTruthy(); jest.useFakeTimers(); }); it('could accept none react element icon', () => { const wrapper = mount(); expect(wrapper).toMatchRenderedSnapshot(); }); });