diff --git a/components/alert/__tests__/index.test.js b/components/alert/__tests__/index.test.js index c943db3f2f..d7680784ef 100644 --- a/components/alert/__tests__/index.test.js +++ b/components/alert/__tests__/index.test.js @@ -1,7 +1,10 @@ import React from 'react'; import { mount } from 'enzyme'; import Alert from '..'; +import Tooltip from '../../tooltip'; +import Popconfirm from '../../popconfirm'; import rtlTest from '../../../tests/shared/rtlTest'; +import { sleep } from '../../../tests/utils'; const { ErrorBoundary } = Alert; @@ -66,4 +69,46 @@ describe('Alert', () => { // eslint-disable-next-line jest/no-standalone-expect expect(wrapper.render()).toMatchSnapshot(); }); + + it('could be used with Tooltip', async () => { + jest.useRealTimers(); + const wrapper = mount( + + + , + ); + wrapper.find('.ant-alert').simulate('mouseenter'); + await sleep(0); + expect( + wrapper + .find(Tooltip) + .instance() + .getPopupDomNode(), + ).toBeTruthy(); + jest.useFakeTimers(); + }); + + it('could be used with Popconfirm', async () => { + jest.useRealTimers(); + const wrapper = mount( + + + , + ); + wrapper.find('.ant-alert').simulate('click'); + await sleep(0); + expect( + wrapper + .find(Popconfirm) + .instance() + .getPopupDomNode(), + ).toBeTruthy(); + jest.useFakeTimers(); + }); }); diff --git a/components/alert/index.tsx b/components/alert/index.tsx index 3584ffcce7..047e6a4fe7 100755 --- a/components/alert/index.tsx +++ b/components/alert/index.tsx @@ -42,6 +42,9 @@ export interface AlertProps { className?: string; banner?: boolean; icon?: React.ReactNode; + onMouseEnter?: React.MouseEventHandler; + onMouseLeave?: React.MouseEventHandler; + onClick?: React.MouseEventHandler; } export interface AlertState { @@ -103,6 +106,9 @@ export default class Alert extends React.Component { className = '', style, icon, + onMouseEnter, + onMouseLeave, + onClick, } = this.props; let { closable, type, showIcon } = this.props; const { closing, closed } = this.state; @@ -173,7 +179,15 @@ export default class Alert extends React.Component { transitionName={`${prefixCls}-slide-up`} onEnd={this.animationEnd} > -
+
{showIcon ? iconNode : null} {message} {description}