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';
|
|
|
|
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-02-13 17:32:07 +08:00
|
|
|
focusTest(Slider);
|
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} />);
|
|
|
|
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 />);
|
2018-12-07 16:17:45 +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 () => {
|
|
|
|
const wrapper = mount(<Slider defaultValue={30} tooltipVisible />);
|
|
|
|
wrapper.find('Tooltip').instance().tooltip.forcePopupAlign = jest.fn();
|
|
|
|
await sleep(0);
|
|
|
|
expect(wrapper.find('Tooltip').instance().tooltip.forcePopupAlign).toHaveBeenCalled();
|
|
|
|
});
|
2018-03-23 19:19:29 +08:00
|
|
|
});
|