@@ -476,16 +476,44 @@ describe('rc-drawer-menu', () => {
476476 unmount ( ) ;
477477 } ) ;
478478
479- it ( 'should support resizable' , ( ) => {
479+ it ( 'should support resizable horizontal ' , ( ) => {
480480 const { unmount } = render (
481- < Drawer resizable open placement = "left" width = { 200 } /> ,
481+ < div
482+ id = "container"
483+ style = { { width : '400px' , height : '400px' , position : 'relative' } }
484+ >
485+ < Drawer
486+ getContainer = { false }
487+ resizable
488+ open
489+ placement = "left"
490+ width = { 200 }
491+ />
492+ </ div > ,
482493 ) ;
483494
484- // Mock getBoundingClientRect for the content wrapper to simulate real DOM dimensions
495+ // Mock getBoundingClientRect for the container and content wrapper
496+ const container = document . querySelector ( '#container' ) as HTMLElement ;
485497 const contentWrapper = document . querySelector (
486498 '.rc-drawer-content-wrapper' ,
487499 ) as HTMLElement ;
488- const mockGetBoundingClientRect = jest . fn (
500+
501+ const mockContainerGetBoundingClientRect = jest . fn (
502+ ( ) =>
503+ ( {
504+ width : 400 ,
505+ height : 400 ,
506+ top : 0 ,
507+ left : 0 ,
508+ bottom : 400 ,
509+ right : 400 ,
510+ x : 0 ,
511+ y : 0 ,
512+ toJSON : ( ) => ( { } ) ,
513+ } ) as DOMRect ,
514+ ) ;
515+
516+ const mockWrapperGetBoundingClientRect = jest . fn (
489517 ( ) =>
490518 ( {
491519 width : 200 ,
@@ -499,7 +527,9 @@ describe('rc-drawer-menu', () => {
499527 toJSON : ( ) => ( { } ) ,
500528 } ) as DOMRect ,
501529 ) ;
502- contentWrapper . getBoundingClientRect = mockGetBoundingClientRect ;
530+
531+ container . getBoundingClientRect = mockContainerGetBoundingClientRect ;
532+ contentWrapper . getBoundingClientRect = mockWrapperGetBoundingClientRect ;
503533
504534 const dragger = document . querySelector ( '.rc-drawer-resizable-dragger' ) ;
505535 expect ( dragger ) . toBeTruthy ( ) ;
@@ -512,6 +542,110 @@ describe('rc-drawer-menu', () => {
512542 expect ( document . querySelector ( '.rc-drawer-content-wrapper' ) ) . toHaveStyle ( {
513543 width : '100px' ,
514544 } ) ;
545+
546+ unmount ( ) ;
547+ } ) ;
548+
549+ it ( 'should respect minSize and maxSize constraints' , ( ) => {
550+ const { unmount } = render (
551+ < div style = { { width : '500px' , height : '400px' , position : 'relative' } } >
552+ < Drawer
553+ getContainer = { false }
554+ resizable
555+ open
556+ placement = "left"
557+ width = { 200 }
558+ />
559+ </ div > ,
560+ ) ;
561+
562+ // Helper to create mock getBoundingClientRect
563+ const createMockRect = ( width : number ) : ( ( ) => DOMRect ) =>
564+ jest . fn (
565+ ( ) =>
566+ ( {
567+ width,
568+ height : 400 ,
569+ top : 0 ,
570+ left : 0 ,
571+ bottom : 400 ,
572+ right : width ,
573+ x : 0 ,
574+ y : 0 ,
575+ toJSON : ( ) => ( { } ) ,
576+ } ) as DOMRect ,
577+ ) ;
578+
579+ // Mock wrapper (for useDrag) and its parent (for calculateMaxSize)
580+ const contentWrapper = document . querySelector (
581+ '.rc-drawer-content-wrapper' ,
582+ ) as HTMLElement ;
583+ const wrapperParent = contentWrapper . parentElement as HTMLElement ;
584+
585+ contentWrapper . getBoundingClientRect = createMockRect ( 200 ) ;
586+ if ( wrapperParent ) {
587+ wrapperParent . getBoundingClientRect = createMockRect ( 500 ) ;
588+ }
589+
590+ const dragger = document . querySelector ( '.rc-drawer-resizable-dragger' ) ;
591+ expect ( dragger ) . toBeTruthy ( ) ;
592+
593+ // Test minSize constraint (minSize = 0)
594+ fireEvent . mouseDown ( dragger , { clientX : 200 } ) ;
595+ fireEvent . mouseMove ( document , { clientX : - 100 } ) ;
596+ fireEvent . mouseUp ( document , { clientX : - 100 } ) ;
597+
598+ expect ( document . querySelector ( '.rc-drawer-content-wrapper' ) ) . toHaveStyle ( {
599+ width : '0px' ,
600+ } ) ;
601+
602+ // Test maxSize constraint (maxSize = 500px from parent container)
603+ fireEvent . mouseDown ( dragger , { clientX : 200 } ) ;
604+ fireEvent . mouseMove ( document , { clientX : 800 } ) ;
605+ fireEvent . mouseUp ( document , { clientX : 800 } ) ;
606+
607+ expect ( document . querySelector ( '.rc-drawer-content-wrapper' ) ) . toHaveStyle ( {
608+ width : '500px' ,
609+ } ) ;
610+
611+ unmount ( ) ;
612+ } ) ;
613+
614+ it ( 'should support resizable vertical' , ( ) => {
615+ const { unmount } = render (
616+ < Drawer resizable open placement = "top" height = { 200 } /> ,
617+ ) ;
618+
619+ // Mock getBoundingClientRect for the content wrapper to simulate real DOM dimensions
620+ const contentWrapper = document . querySelector (
621+ '.rc-drawer-content-wrapper' ,
622+ ) as HTMLElement ;
623+ const mockGetBoundingClientRect = jest . fn (
624+ ( ) =>
625+ ( {
626+ width : 200 ,
627+ height : 400 ,
628+ top : 0 ,
629+ left : 0 ,
630+ bottom : 400 ,
631+ right : 200 ,
632+ x : 0 ,
633+ y : 0 ,
634+ toJSON : ( ) => ( { } ) ,
635+ } ) as DOMRect ,
636+ ) ;
637+ contentWrapper . getBoundingClientRect = mockGetBoundingClientRect ;
638+
639+ const dragger = document . querySelector ( '.rc-drawer-resizable-dragger' ) ;
640+ expect ( dragger ) . toBeTruthy ( ) ;
641+
642+ fireEvent . mouseDown ( dragger , { clientY : 200 } ) ;
643+ fireEvent . mouseMove ( document , { clientX : 0 , clientY : 100 } ) ;
644+ fireEvent . mouseUp ( document , { clientX : 0 , clientY : 100 } ) ;
645+
646+ expect ( document . querySelector ( '.rc-drawer-content-wrapper' ) ) . toHaveStyle ( {
647+ height : '100px' ,
648+ } ) ;
515649 unmount ( ) ;
516650 } ) ;
517651} ) ;
0 commit comments