@ -1,6 +1,5 @@
import React from 'react' ;
import Slider from '..' ;
import type { SliderSingleProps } from '..' ;
import focusTest from '../../../tests/shared/focusTest' ;
import mountTest from '../../../tests/shared/mountTest' ;
import rtlTest from '../../../tests/shared/rtlTest' ;
@ -8,6 +7,7 @@ import { render, fireEvent, act } from '../../../tests/utils';
import ConfigProvider from '../../config-provider' ;
import SliderTooltip from '../SliderTooltip' ;
import type { TooltipProps } from '../../tooltip' ;
import { resetWarned } from '../../_util/warning' ;
function tooltipProps ( ) : TooltipProps {
return ( global as any ) . tooltipProps ;
@ -48,58 +48,35 @@ describe('Slider', () => {
expect ( document . querySelector ( '.ant-tooltip' ) ) . toMatchSnapshot ( ) ;
} ) ;
describe ( 'should show correct placement tooltip when set tooltipPlacement' , ( ) = > {
function test ( name : string , props : Partial < SliderSingleProps > ) {
it ( name , ( ) = > {
const { container } = render ( < Slider vertical defaultValue = { 30 } { ...props } / > ) ;
fireEvent . mouseEnter ( container . querySelector ( '.ant-slider-handle' ) ! ) ;
expect ( tooltipProps ( ) . placement ) . toEqual ( 'left' ) ;
} ) ;
}
it ( 'should show correct placement tooltip when set tooltipPlacement' , ( ) = > {
const { container } = render (
< Slider vertical defaultValue = { 30 } tooltip = { { placement : 'left' } } / > ,
) ;
test ( 'new' , { tooltip : { placement : 'left' } } ) ;
test ( 'legacy' , { tooltipPlacement : 'left' } ) ;
fireEvent . mouseEnter ( container . querySelector ( '.ant-slider-handle' ) ! ) ;
expect ( tooltipProps ( ) . placement ) . toEqual ( 'left' ) ;
} ) ;
describe ( 'when tooltip.open is true, tooltip should show always, or should never show' , ( ) = > {
function test (
name : string ,
showProps : Partial < SliderSingleProps > ,
hideProps : Partial < SliderSingleProps > ,
) {
it ( name , ( ) = > {
const { container , rerender } = render ( < Slider defaultValue = { 30 } { ...showProps } / > ) ;
expect (
container . querySelector ( '.ant-tooltip-content' ) ! . className . includes ( 'ant-tooltip-hidden' ) ,
) . toBeFalsy ( ) ;
fireEvent . mouseEnter ( container . querySelector ( '.ant-slider-handle' ) ! ) ;
expect (
container . querySelector ( '.ant-tooltip-content' ) ! . className . includes ( 'ant-tooltip-hidden' ) ,
) . toBeFalsy ( ) ;
fireEvent . click ( container . querySelector ( '.ant-slider-handle' ) ! ) ;
expect (
container . querySelector ( '.ant-tooltip-content' ) ! . className . includes ( 'ant-tooltip-hidden' ) ,
) . toBeFalsy ( ) ;
// Force hide
rerender ( < Slider defaultValue = { 30 } { ...hideProps } / > ) ;
act ( ( ) = > {
jest . runAllTimers ( ) ;
} ) ;
if ( container . querySelector ( '.ant-zoom-down-leave-active' ) ) {
fireEvent . animationEnd ( container . querySelector ( '.ant-zoom-down-leave-active' ) ! ) ;
}
expect ( container . querySelector ( '.ant-tooltip-hidden' ) ! ) . toBeTruthy ( ) ;
} ) ;
}
test ( 'new' , { tooltip : { open : true } } , { tooltip : { open : false } } ) ;
test ( 'legacy' , { tooltipVisible : true } , { tooltipVisible : false } ) ;
it ( 'when tooltip.open is true, tooltip should show always, or should never show' , ( ) = > {
const { container : container1 } = render ( < Slider defaultValue = { 30 } tooltip = { { open : true } } / > ) ;
expect (
container1 . querySelector ( '.ant-tooltip-content' ) ! . className . includes ( 'ant-tooltip-hidden' ) ,
) . toBeFalsy ( ) ;
fireEvent . mouseEnter ( container1 . querySelector ( '.ant-slider-handle' ) ! ) ;
expect (
container1 . querySelector ( '.ant-tooltip-content' ) ! . className . includes ( 'ant-tooltip-hidden' ) ,
) . toBeFalsy ( ) ;
fireEvent . click ( container1 . querySelector ( '.ant-slider-handle' ) ! ) ;
expect (
container1 . querySelector ( '.ant-tooltip-content' ) ! . className . includes ( 'ant-tooltip-hidden' ) ,
) . toBeFalsy ( ) ;
const { container : container2 } = render (
< Slider defaultValue = { 30 } tooltip = { { open : false } } / > ,
) ;
expect ( container2 . querySelector ( '.ant-tooltip-content' ) ! ) . toBeNull ( ) ;
} ) ;
it ( 'when step is null, thumb can only be slided to the specific mark' , ( ) = > {
@ -185,27 +162,31 @@ describe('Slider', () => {
} ) ;
} ) ;
it ( 'deprecated warning' , ( ) = > {
resetWarned ( ) ;
const TSSlider = Slider as any ;
const errSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) = > { } ) ;
const { rerender } = render ( < Slider tooltipPrefixCls = "xxx" / > ) ;
const { rerender } = render ( < TS Slider tooltipPrefixCls = "xxx" / > ) ;
expect ( errSpy ) . toHaveBeenCalledWith (
'Warning: [antd: Slider] `tooltipPrefixCls` is deprecated which will be removed in next major version , please use `tooltip.prefixCls` instead.' ,
'Warning: [antd: Slider] `tooltipPrefixCls` is removed in v5 , please use `tooltip.prefixCls` instead.' ,
) ;
rerender ( < Slider getTooltipPopupContainer = { ( ) = > document . body } / > ) ;
rerender ( < TS Slider getTooltipPopupContainer = { ( ) = > document . body } / > ) ;
expect ( errSpy ) . toHaveBeenCalledWith (
'Warning: [antd: Slider] `getTooltipPopupContainer` is deprecated which will be removed in next major version , please use `tooltip.getPopupContainer` instead.' ,
'Warning: [antd: Slider] `getTooltipPopupContainer` is removed in v5 , please use `tooltip.getPopupContainer` instead.' ,
) ;
rerender ( < Slider tipFormatter = { v = > v } / > ) ;
rerender ( < TS Slider tipFormatter = { ( v : any ) = > v } / > ) ;
expect ( errSpy ) . toHaveBeenCalledWith (
'Warning: [antd: Slider] `tipFormatter` is deprecated which will be removed in next major version , please use `tooltip.formatter` instead.' ,
'Warning: [antd: Slider] `tipFormatter` is removed in v5 , please use `tooltip.formatter` instead.' ,
) ;
rerender ( < Slider tooltipVisible / > ) ;
rerender ( < TS Slider tooltipVisible / > ) ;
expect ( errSpy ) . toHaveBeenCalledWith (
'Warning: [antd: Slider] `tooltipVisible` is deprecated which will be removed in next major version , please use `tooltip.open` instead.' ,
'Warning: [antd: Slider] `tooltipVisible` is removed in v5 , please use `tooltip.open` instead.' ,
) ;
rerender ( < Slider tooltipPlacement = "left" / > ) ;
rerender ( < TS Slider tooltipPlacement = "left" / > ) ;
expect ( errSpy ) . toHaveBeenCalledWith (
'Warning: [antd: Slider] `tooltipPlacement` is deprecated which will be removed in next major version , please use `tooltip.placement` instead.' ,
'Warning: [antd: Slider] `tooltipPlacement` is removed in v5 , please use `tooltip.placement` instead.' ,
) ;
errSpy . mockRestore ( ) ;