2018-03-23 19:19:29 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { render, mount } from 'enzyme';
|
|
|
|
import Slider from '..';
|
2020-01-02 19:10:16 +08:00
|
|
|
import ConfigProvider from '../../config-provider';
|
2019-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-01-02 19:10:16 +08:00
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
2020-02-13 17:32:07 +08:00
|
|
|
import focusTest from '../../../tests/shared/focusTest';
|
2020-05-15 10:47:03 +08:00
|
|
|
import SliderTooltip from '../SliderTooltip';
|
2020-02-13 17:32:07 +08:00
|
|
|
import { sleep } from '../../../tests/utils';
|
2018-03-23 19:19:29 +08:00
|
|
|
|
|
|
|
describe('Slider', () => {
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(Slider);
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(Slider);
|
2020-04-22 15:58:57 +08:00
|
|
|
focusTest(Slider, { refFocus: true });
|
2019-08-26 22:53:20 +08:00
|
|
|
|
2018-03-23 19:19:29 +08:00
|
|
|
it('should show tooltip when hovering slider handler', () => {
|
2018-12-07 16:17:45 +08:00
|
|
|
const wrapper = mount(<Slider defaultValue={30} />);
|
2020-04-22 15:58:57 +08:00
|
|
|
wrapper.find('.ant-slider-handle').at(0).simulate('mouseEnter');
|
|
|
|
expect(render(wrapper.find('Trigger').instance().getComponent())).toMatchSnapshot();
|
|
|
|
wrapper.find('.ant-slider-handle').at(0).simulate('mouseLeave');
|
|
|
|
expect(render(wrapper.find('Trigger').instance().getComponent())).toMatchSnapshot();
|
2018-03-23 19:19:29 +08:00
|
|
|
});
|
2018-11-01 11:40:47 +08:00
|
|
|
|
|
|
|
it('when tooltipVisible is true, tooltip should show always, or should never show', () => {
|
|
|
|
let wrapper = mount(<Slider defaultValue={30} tooltipVisible />);
|
2020-04-22 15:58:57 +08:00
|
|
|
expect(wrapper.find('.ant-tooltip-content').at(0).hasClass('ant-tooltip-hidden')).toBe(false);
|
|
|
|
wrapper.find('.ant-slider-handle').at(0).simulate('mouseEnter');
|
|
|
|
expect(wrapper.find('.ant-tooltip-content').at(0).hasClass('ant-tooltip-hidden')).toBe(false);
|
|
|
|
wrapper.find('.ant-slider-handle').at(0).simulate('click');
|
|
|
|
expect(wrapper.find('.ant-tooltip-content').at(0).hasClass('ant-tooltip-hidden')).toBe(false);
|
2018-11-01 11:40:47 +08:00
|
|
|
wrapper = mount(<Slider defaultValue={30} tooltipVisible={false} />);
|
|
|
|
expect(wrapper.find('.ant-tooltip-content').length).toBe(0);
|
|
|
|
});
|
2020-01-02 19:10:16 +08:00
|
|
|
|
|
|
|
it('should render in RTL direction', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<ConfigProvider direction="rtl">
|
|
|
|
<Slider defaultValue={30} tooltipVisible />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
expect(render(wrapper)).toMatchSnapshot();
|
|
|
|
});
|
2020-02-13 17:32:07 +08:00
|
|
|
|
|
|
|
it('should keepAlign by calling forcePopupAlign', async () => {
|
2020-05-15 10:47:03 +08:00
|
|
|
let ref;
|
|
|
|
mount(
|
|
|
|
<SliderTooltip
|
|
|
|
title="30"
|
|
|
|
visible
|
|
|
|
ref={node => {
|
|
|
|
ref = node;
|
|
|
|
}}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
ref.forcePopupAlign = jest.fn();
|
2020-03-20 15:07:47 +08:00
|
|
|
await sleep(20);
|
2020-05-15 10:47:03 +08:00
|
|
|
expect(ref.forcePopupAlign).toHaveBeenCalled();
|
2020-02-13 17:32:07 +08:00
|
|
|
});
|
2020-03-22 11:18:35 +08:00
|
|
|
|
|
|
|
it('tipFormatter should not crash with undefined value', () => {
|
|
|
|
[undefined, null].forEach(value => {
|
|
|
|
mount(<Slider value={value} tooltipVisible />);
|
|
|
|
});
|
|
|
|
});
|
2018-03-23 19:19:29 +08:00
|
|
|
});
|