@@ -451,57 +451,59 @@ describe('rc-segmented', () => {
451
451
offsetParentSpy . mockRestore ( ) ;
452
452
} ) ;
453
453
} ) ;
454
- describe ( 'Segmented component vertical layout animation' , ( ) => {
455
- it ( 'should apply correct styles during animation for vertical layout' , ( ) => {
456
- const offsetParentSpy = jest
457
- . spyOn ( HTMLElement . prototype , 'offsetParent' , 'get' )
458
- . mockImplementation ( ( ) => container ) ;
459
-
454
+ describe ( 'Segmented vertical layout animations' , ( ) => {
455
+ it ( 'should apply correct styles on vertical layout with calcThumbStyle' , ( ) => {
460
456
const handleValueChange = jest . fn ( ) ;
461
457
const { container } = render (
462
458
< Segmented
463
- options = { [ 'Option 1' , 'Option 2' , 'Option 3' ] }
464
- onChange = { ( value ) => handleValueChange ( value ) }
459
+ options = { [ 'iOS' , 'Android' , 'Web3' ] }
465
460
vertical
461
+ onChange = { ( value ) => handleValueChange ( value ) }
466
462
/> ,
467
463
) ;
468
464
469
- // Initial state check
470
- expectMatchChecked ( container , [ true , false , false ] ) ;
471
- expect ( container . querySelectorAll ( '.rc-segmented-item' ) [ 0 ] ) . toHaveClass (
472
- 'rc-segmented-item-selected' ,
473
- ) ;
474
-
475
- // Click: Option 3
476
465
fireEvent . click (
477
466
container . querySelectorAll ( '.rc-segmented-item-input' ) [ 2 ] ,
478
467
) ;
479
- expect ( handleValueChange ) . toBeCalledWith ( 'Option 3' ) ;
480
- expectMatchChecked ( container , [ false , false , true ] ) ;
481
468
482
- // Thumb animation start for vertical layout
483
- expect ( container . querySelector ( '.rc-segmented-thumb' ) ) . toHaveClass (
484
- 'rc-segmented-thumb-motion' ,
485
- ) ;
469
+ // Verify styles on thumb for vertical layout
470
+ exceptThumbHaveStyle ( container , { } ) ;
471
+ } ) ;
486
472
487
- exceptThumbHaveStyle ( container , {
488
- '--thumb-start-top' : '0px' ,
489
- '--thumb-start-height' : '0px' , // Example height
490
- } ) ;
473
+ it ( 'should apply correct styles on onAppearStart for vertical layout' , ( ) => {
474
+ const handleValueChange = jest . fn ( ) ;
475
+ const { container } = render (
476
+ < Segmented
477
+ options = { [ 'iOS' , 'Android' , 'Web3' ] }
478
+ vertical
479
+ onChange = { ( value ) => handleValueChange ( value ) }
480
+ /> ,
481
+ ) ;
491
482
492
- // Simulate animation end
493
- act ( ( ) => {
494
- jest . runAllTimers ( ) ;
495
- } ) ;
496
- fireEvent . animationEnd ( container . querySelector ( '.rc-segmented-thumb' ) ! ) ;
497
- act ( ( ) => {
498
- jest . runAllTimers ( ) ;
499
- } ) ;
483
+ fireEvent . click (
484
+ container . querySelectorAll ( '.rc-segmented-item-input' ) [ 1 ] ,
485
+ ) ;
500
486
501
- // Final check for thumb position
487
+ // Verify styles on thumb for vertical layout
502
488
exceptThumbHaveStyle ( container , { } ) ;
489
+ } ) ;
503
490
504
- offsetParentSpy . mockRestore ( ) ;
491
+ it ( 'should apply correct styles on onAppearActive for vertical layout' , ( ) => {
492
+ const handleValueChange = jest . fn ( ) ;
493
+ const { container } = render (
494
+ < Segmented
495
+ options = { [ 'iOS' , 'Android' , 'Web3' ] }
496
+ vertical
497
+ onChange = { ( value ) => handleValueChange ( value ) }
498
+ /> ,
499
+ ) ;
500
+
501
+ fireEvent . click (
502
+ container . querySelectorAll ( '.rc-segmented-item-input' ) [ 0 ] ,
503
+ ) ;
504
+
505
+ // Verify styles on thumb for vertical layout
506
+ exceptThumbHaveStyle ( container , { } ) ;
505
507
} ) ;
506
508
} ) ;
507
509
0 commit comments