2023-02-15 10:21:28 +08:00
|
|
|
import type { TriggerProps } from '@rc-component/trigger';
|
|
|
|
import MockTrigger from '@rc-component/trigger/lib/mock';
|
2023-05-05 20:52:44 +08:00
|
|
|
import React from 'react';
|
2023-02-15 10:21:28 +08:00
|
|
|
import { TriggerMockContext } from '../../shared/demoTestContext';
|
|
|
|
|
|
|
|
let OriginTrigger = jest.requireActual('@rc-component/trigger');
|
|
|
|
OriginTrigger = OriginTrigger.default ?? OriginTrigger;
|
|
|
|
|
|
|
|
const ForwardTrigger = React.forwardRef<any, TriggerProps>((props, ref) => {
|
|
|
|
const context = React.useContext(TriggerMockContext);
|
|
|
|
|
|
|
|
const mergedPopupVisible = context?.popupVisible ?? props.popupVisible;
|
|
|
|
(global as any).triggerProps = props;
|
|
|
|
|
|
|
|
const mergedProps = {
|
|
|
|
...props,
|
|
|
|
ref,
|
|
|
|
popupVisible: mergedPopupVisible as boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (context?.mock === false) {
|
|
|
|
return <OriginTrigger {...mergedProps} />;
|
|
|
|
}
|
|
|
|
return <MockTrigger {...mergedProps} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
export default ForwardTrigger;
|