|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import { spyElementPrototype } from 'rc-util/lib/test/domHook';
|
|
|
|
import Tooltip from '..';
|
|
|
|
import Button from '../../button';
|
|
|
|
import Switch from '../../switch';
|
|
|
|
import Checkbox from '../../checkbox';
|
|
|
|
import DatePicker from '../../date-picker';
|
|
|
|
import Input from '../../input';
|
|
|
|
import Group from '../../input/Group';
|
|
|
|
import { sleep } from '../../../tests/utils';
|
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
|
|
|
|
|
|
|
describe('Tooltip', () => {
|
|
|
|
mountTest(Tooltip);
|
|
|
|
rtlTest(Tooltip);
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
spyElementPrototype(HTMLElement, 'offsetParent', {
|
|
|
|
get: () => ({}),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('check `onVisibleChange` arguments', () => {
|
|
|
|
const onVisibleChange = jest.fn();
|
|
|
|
const ref = React.createRef();
|
|
|
|
|
|
|
|
const wrapper = mount(
|
|
|
|
<Tooltip
|
|
|
|
title=""
|
|
|
|
mouseEnterDelay={0}
|
|
|
|
mouseLeaveDelay={0}
|
|
|
|
onVisibleChange={onVisibleChange}
|
|
|
|
ref={ref}
|
|
|
|
>
|
|
|
|
<div id="hello">Hello world!</div>
|
|
|
|
</Tooltip>,
|
|
|
|
);
|
|
|
|
|
|
|
|
// `title` is empty.
|
|
|
|
const div = wrapper.find('#hello').at(0);
|
|
|
|
div.simulate('mouseenter');
|
|
|
|
expect(onVisibleChange).not.toHaveBeenCalled();
|
|
|
|
expect(ref.current.props.visible).toBe(false);
|
|
|
|
|
|
|
|
div.simulate('mouseleave');
|
|
|
|
expect(onVisibleChange).not.toHaveBeenCalled();
|
|
|
|
expect(ref.current.props.visible).toBe(false);
|
|
|
|
|
|
|
|
// update `title` value.
|
|
|
|
wrapper.setProps({ title: 'Have a nice day!' });
|
|
|
|
wrapper.find('#hello').simulate('mouseenter');
|
|
|
|
expect(onVisibleChange).toHaveBeenLastCalledWith(true);
|
|
|
|
expect(ref.current.props.visible).toBe(true);
|
|
|
|
|
|
|
|
wrapper.find('#hello').simulate('mouseleave');
|
|
|
|
expect(onVisibleChange).toHaveBeenLastCalledWith(false);
|
|
|
|
expect(ref.current.props.visible).toBe(false);
|
|
|
|
|
|
|
|
// add `visible` props.
|
|
|
|
wrapper.setProps({ visible: false });
|
|
|
|
wrapper.find('#hello').simulate('mouseenter'); |