|
| 1 | +/* eslint-disable max-classes-per-file */ |
| 2 | +import { act, cleanup, fireEvent, render } from '@testing-library/react'; |
| 3 | +import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook'; |
| 4 | +import React from 'react'; |
| 5 | +import Trigger from '../src'; |
| 6 | +import { awaitFakeTimer, placementAlignMap } from './util'; |
| 7 | + |
| 8 | +jest.mock('../src/Popup', () => { |
| 9 | + const OriPopup = jest.requireActual('../src/Popup').default; |
| 10 | + |
| 11 | + return React.forwardRef((props, ref) => { |
| 12 | + console.log(2333); |
| 13 | + return <OriPopup {...props} ref={ref} />; |
| 14 | + }); |
| 15 | +}); |
| 16 | + |
| 17 | +describe('Trigger.Basic', () => { |
| 18 | + beforeAll(() => { |
| 19 | + spyElementPrototypes(HTMLElement, { |
| 20 | + offsetParent: { |
| 21 | + get: () => document.body, |
| 22 | + }, |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + beforeEach(() => { |
| 27 | + jest.useFakeTimers(); |
| 28 | + }); |
| 29 | + |
| 30 | + afterEach(() => { |
| 31 | + cleanup(); |
| 32 | + jest.useRealTimers(); |
| 33 | + }); |
| 34 | + |
| 35 | + function trigger(dom, selector, method = 'click') { |
| 36 | + fireEvent[method](dom.querySelector(selector)); |
| 37 | + act(() => jest.runAllTimers()); |
| 38 | + } |
| 39 | + |
| 40 | + describe('Performance', () => { |
| 41 | + it('not create Popup when !open', () => { |
| 42 | + const { container } = render( |
| 43 | + <Trigger |
| 44 | + action={['click']} |
| 45 | + popupAlign={placementAlignMap.left} |
| 46 | + popup={<strong className="x-content">tooltip2</strong>} |
| 47 | + > |
| 48 | + <div className="target">click</div> |
| 49 | + </Trigger>, |
| 50 | + ); |
| 51 | + |
| 52 | + // trigger(container, '.target'); |
| 53 | + |
| 54 | + // const popupDomNode = document.querySelector('.rc-trigger-popup'); |
| 55 | + // expect(popupDomNode.parentNode.parentNode).toBeInstanceOf( |
| 56 | + // HTMLBodyElement, |
| 57 | + // ); |
| 58 | + }); |
| 59 | + }); |
| 60 | +}); |
0 commit comments