2022-12-19 13:31:41 +08:00
|
|
|
import type { TriggerProps } from 'rc-trigger';
|
2023-01-20 11:03:50 +08:00
|
|
|
import MockTrigger from 'rc-trigger/lib/mock';
|
|
|
|
import * as React from 'react';
|
2022-07-25 21:04:43 +08:00
|
|
|
import { TriggerMockContext } from '../shared/demoTestContext';
|
2017-11-11 00:07:03 +08:00
|
|
|
|
2023-01-20 11:03:50 +08:00
|
|
|
let OriginTrigger = jest.requireActual('rc-trigger');
|
|
|
|
OriginTrigger = OriginTrigger.default ?? OriginTrigger;
|
|
|
|
|
2022-12-19 13:31:41 +08:00
|
|
|
const ForwardTrigger = React.forwardRef<any, TriggerProps>((props, ref) => {
|
2023-01-20 11:03:50 +08:00
|
|
|
const context = React.useContext(TriggerMockContext);
|
|
|
|
|
|
|
|
const mergedPopupVisible = context?.popupVisible ?? props.popupVisible;
|
2022-12-19 13:31:41 +08:00
|
|
|
(global as any).triggerProps = props;
|
2023-01-20 11:03:50 +08:00
|
|
|
|
|
|
|
const mergedProps = {
|
|
|
|
...props,
|
|
|
|
ref,
|
|
|
|
popupVisible: mergedPopupVisible as boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (context?.mock === false) {
|
|
|
|
return <OriginTrigger {...mergedProps} />;
|
|
|
|
}
|
|
|
|
return <MockTrigger {...mergedProps} />;
|
2021-12-23 11:51:10 +08:00
|
|
|
});
|
2022-12-19 13:31:41 +08:00
|
|
|
|
|
|
|
export default ForwardTrigger;
|