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);
|
2022-03-01 14:48:41 +08:00
|
|
|
focusTest(Slider, { testLib: 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
|
|
|
|
2020-07-30 20:59:41 +08:00
|
|
|
it('should show correct placement tooltip when set tooltipPlacement', () => {
|
|
|
|
const wrapper = mount(<Slider vertical defaultValue={30} tooltipPlacement="left" />);
|
|
|
|
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-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
|
|
|
|
2020-10-02 22:15:12 +08:00
|
|
|
it('when step is null, thumb can only be slided to the specific mark', () => {
|
|
|
|
const intentionallyWrongValue = 40;
|
|
|
|
const marks = {
|
|
|
|
0: '0',
|
|
|
|
48: '48',
|
|
|
|
100: '100',
|
|
|
|
};
|
|
|
|
|
|
|
|
const wrapper = mount(
|
|
|
|
<Slider marks={marks} defaultValue={intentionallyWrongValue} step={null} tooltipVisible />,
|
|
|
|
);
|
2022-03-01 14:48:41 +08:00
|
|
|
expect(wrapper.find('.ant-slider-handle').get(0).props).toHaveProperty('aria-valuenow', 48);
|
2020-10-02 22:15:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('when step is not null, thumb can be slided to the multiples of step', () => {
|
|
|
|
const marks = {
|
|
|
|
0: '0',
|
|
|
|
48: '48',
|
|
|
|
100: '100',
|
|
|
|
};
|
|
|
|
|
|
|
|
const wrapper = mount(<Slider marks={marks} defaultValue={49} step={1} tooltipVisible />);
|
2022-03-01 14:48:41 +08:00
|
|
|
expect(wrapper.find('.ant-slider-handle').get(0).props).toHaveProperty('aria-valuenow', 49);
|
2020-10-02 22:15:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('when step is undefined, thumb can be slided to the multiples of step', () => {
|
|
|
|
const marks = {
|
|
|
|
0: '0',
|
|
|
|
48: '48',
|
|
|
|
100: '100',
|
|
|
|
};
|
|
|
|
|
|
|
|
const wrapper = mount(
|
|
|
|
<Slider marks={marks} defaultValue={49} step={undefined} tooltipVisible />,
|
|
|
|
);
|
2022-03-01 14:48:41 +08:00
|
|
|
expect(wrapper.find('.ant-slider-handle').get(0).props).toHaveProperty('aria-valuenow', 49);
|
2020-10-02 22:15:12 +08:00
|
|
|
});
|
|
|
|
|
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 />);
|
|
|
|
});
|
|
|
|
});
|
2020-10-02 22:15:12 +08:00
|
|
|
it('step should not crash with undefined value', () => {
|
|
|
|
[undefined, null].forEach(value => {
|
|
|
|
mount(<Slider step={value} tooltipVisible />);
|
|
|
|
});
|
|
|
|
});
|
2018-03-23 19:19:29 +08:00
|
|
|
});
|