11import { act , createEvent , fireEvent , render } from '@testing-library/react' ;
2- import moment , { Moment } from 'moment' ;
2+ import type { Moment } from 'moment' ;
3+ import moment from 'moment' ;
34import KeyCode from 'rc-util/lib/KeyCode' ;
45import { spyElementPrototypes } from 'rc-util/lib/test/domHook' ;
56import React from 'react' ;
@@ -18,6 +19,7 @@ import {
1819 openPicker ,
1920 selectCell ,
2021} from './util/commonUtil' ;
22+ import type { RangePickerProps } from '../src/RangePicker' ;
2123
2224describe ( 'Picker.Range' , ( ) => {
2325 function matchValues ( container : HTMLElement , value1 : string , value2 : string ) {
@@ -331,15 +333,32 @@ describe('Picker.Range', () => {
331333 } ) ;
332334 } ) ;
333335
334- describe ( 'ranges' , ( ) => {
335- it ( 'work' , ( ) => {
336+ function testRangePickerPresetRange ( propsType : 'ranges' | 'presets' ) {
337+
338+ const genProps = ( ranges : Record < string , any > ) => {
339+ const props : Partial < RangePickerProps < Moment > > = { } ;
340+ if ( propsType === 'ranges' ) {
341+ // ranges is deprecated, but the case needs to be retained for a while
342+ props . ranges = ranges ;
343+ } else if ( propsType === 'presets' ) {
344+ props . presets = [ ] ;
345+ Object . entries ( ranges ) . forEach ( ( [ label , value ] ) => {
346+ props . presets . push ( { label, value } ) ;
347+ } )
348+ }
349+ return props as RangePickerProps < Moment > ;
350+ }
351+
352+ it ( `${ propsType } work` , ( ) => {
336353 const onChange = jest . fn ( ) ;
337354 const { container } = render (
338355 < MomentRangePicker
339- ranges = { {
340- test : [ getMoment ( '1989-11-28' ) , getMoment ( '1990-09-03' ) ] ,
341- func : ( ) => [ getMoment ( '2000-01-01' ) , getMoment ( '2010-11-11' ) ] ,
342- } }
356+ { ...genProps (
357+ {
358+ test : [ getMoment ( '1989-11-28' ) , getMoment ( '1990-09-03' ) ] ,
359+ func : ( ) => [ getMoment ( '2000-01-01' ) , getMoment ( '2010-11-11' ) ] ,
360+ }
361+ ) }
343362 onChange = { onChange }
344363 /> ,
345364 ) ;
@@ -371,12 +390,14 @@ describe('Picker.Range', () => {
371390 expect ( isOpen ( ) ) . toBeFalsy ( ) ;
372391 } ) ;
373392
374- it ( ' hover className' , ( ) => {
393+ it ( ` ${ propsType } hover className` , ( ) => {
375394 const { container } = render (
376395 < MomentRangePicker
377- ranges = { {
378- now : [ getMoment ( '1990-09-11' ) , getMoment ( '1990-09-13' ) ] ,
379- } }
396+ { ...genProps (
397+ {
398+ now : [ getMoment ( '1990-09-11' ) , getMoment ( '1990-09-13' ) ] ,
399+ }
400+ ) }
380401 /> ,
381402 ) ;
382403
@@ -391,6 +412,12 @@ describe('Picker.Range', () => {
391412 expect ( findCell ( 12 ) ) . not . toHaveClass ( 'rc-picker-cell-in-range' ) ;
392413 expect ( findCell ( 13 ) ) . not . toHaveClass ( 'rc-picker-cell-range-end' ) ;
393414 } ) ;
415+
416+ }
417+
418+ describe ( 'ranges or presets' , ( ) => {
419+ testRangePickerPresetRange ( 'ranges' ) ;
420+ testRangePickerPresetRange ( 'presets' ) ;
394421 } ) ;
395422
396423 it ( 'placeholder' , ( ) => {
0 commit comments