@@ -567,4 +567,86 @@ describe('rc-segmented', () => {
567
567
) ;
568
568
expectMatchChecked ( container , [ true , false , false ] ) ;
569
569
} ) ;
570
+ it ( 'should render vertical segmented and handle thumb animations correctly' , ( ) => {
571
+ const offsetParentSpy = jest
572
+ . spyOn ( HTMLElement . prototype , 'offsetParent' , 'get' )
573
+ . mockImplementation ( ( ) => {
574
+ return container ;
575
+ } ) ;
576
+ const handleValueChange = jest . fn ( ) ;
577
+ const { container, asFragment } = render (
578
+ < Segmented
579
+ options = { [ 'iOS' , 'Android' , 'Web' ] }
580
+ vertical
581
+ onChange = { ( value ) => handleValueChange ( value ) }
582
+ /> ,
583
+ ) ;
584
+
585
+ // Snapshot test
586
+ expect ( asFragment ( ) . firstChild ) . toMatchSnapshot ( ) ;
587
+ expect ( container . querySelector ( '.rc-segmented' ) ) . toHaveClass (
588
+ 'rc-segmented-vertical' ,
589
+ ) ;
590
+ expectMatchChecked ( container , [ true , false , false ] ) ;
591
+
592
+ // Click: Web
593
+ fireEvent . click ( container . querySelectorAll ( '.rc-segmented-item-input' ) [ 2 ] ) ;
594
+ expect ( handleValueChange ) . toBeCalledWith ( 'Web' ) ;
595
+ expectMatchChecked ( container , [ false , false , true ] ) ;
596
+
597
+ // Thumb should appear at `iOS`
598
+ exceptThumbHaveStyle ( container , {
599
+ '--thumb-start-top' : '0px' ,
600
+ '--thumb-start-height' : '0px' ,
601
+ } ) ;
602
+
603
+ // Motion => active
604
+ act ( ( ) => {
605
+ jest . runAllTimers ( ) ;
606
+ } ) ;
607
+
608
+ // Motion enter end
609
+ fireEvent . animationEnd ( container . querySelector ( '.rc-segmented-thumb' ) ! ) ;
610
+ act ( ( ) => {
611
+ jest . runAllTimers ( ) ;
612
+ } ) ;
613
+
614
+ // Thumb should disappear
615
+ expect ( container . querySelector ( '.rc-segmented-thumb' ) ) . toBeFalsy ( ) ;
616
+
617
+ // Click: Android
618
+ fireEvent . click ( container . querySelectorAll ( '.rc-segmented-item-input' ) [ 1 ] ) ;
619
+ expect ( handleValueChange ) . toBeCalledWith ( 'Android' ) ;
620
+ expectMatchChecked ( container , [ false , true , false ] ) ;
621
+
622
+ // Thumb should move
623
+ expect ( container . querySelector ( '.rc-segmented-thumb' ) ) . toHaveClass (
624
+ 'rc-segmented-thumb-motion' ,
625
+ ) ;
626
+
627
+ // Thumb appeared at `Web`
628
+ exceptThumbHaveStyle ( container , {
629
+ '--thumb-start-top' : '0px' ,
630
+ '--thumb-start-height' : '0px' ,
631
+ } ) ;
632
+
633
+ // Motion appear end
634
+ act ( ( ) => {
635
+ jest . runAllTimers ( ) ;
636
+ } ) ;
637
+ exceptThumbHaveStyle ( container , {
638
+ '--thumb-active-top' : '0px' ,
639
+ '--thumb-active-height' : '0px' ,
640
+ } ) ;
641
+
642
+ fireEvent . animationEnd ( container . querySelector ( '.rc-segmented-thumb' ) ! ) ;
643
+ act ( ( ) => {
644
+ jest . runAllTimers ( ) ;
645
+ } ) ;
646
+
647
+ // Thumb should disappear
648
+ expect ( container . querySelector ( '.rc-segmented-thumb' ) ) . toBeFalsy ( ) ;
649
+
650
+ offsetParentSpy . mockRestore ( ) ;
651
+ } ) ;
570
652
} ) ;
0 commit comments