@@ -25,6 +25,7 @@ import {
25
25
useNavigationModalDismiss ,
26
26
useNavigationScreenPop ,
27
27
useNavigationBottomTabSelect ,
28
+ useNavigationBottomTabPress ,
28
29
useNavigationBottomTabLongPress ,
29
30
useNavigationButtonPress ,
30
31
useNavigationSearchBarUpdate ,
@@ -770,6 +771,68 @@ describe('useNavigationBottomTabSelect', () => {
770
771
} )
771
772
} )
772
773
774
+ describe ( 'useNavigationBottomTabPress' , ( ) => {
775
+ let triggerEvent : ( event : BottomTabLongPressedEvent ) => void
776
+ let mockRemoveSubscription : ( ) => void
777
+ let mockHandler : ( ) => void
778
+
779
+ beforeEach ( ( ) => {
780
+ mockHandler = jest . fn ( ( ) => { } )
781
+ mockRemoveSubscription = jest . fn ( )
782
+
783
+ Navigation . events = jest . fn ( ) . mockReturnValue ( {
784
+ registerBottomTabPressedListener : jest . fn ( callback => {
785
+ triggerEvent = callback
786
+
787
+ return { remove : mockRemoveSubscription }
788
+ } ) ,
789
+ } )
790
+ } )
791
+
792
+ it ( 'should remove the event listener on unmount' , ( ) => {
793
+ const { result, unmount } = renderHook ( ( ) => {
794
+ useNavigationBottomTabPress ( ( ) => { } )
795
+ } )
796
+
797
+ unmount ( )
798
+
799
+ expect ( mockRemoveSubscription ) . toBeCalledTimes ( 1 )
800
+
801
+ expect ( result . current ) . toBeUndefined ( )
802
+ expect ( result . error ) . toBeUndefined ( )
803
+ } )
804
+
805
+ it ( 'should never call the handler if no event was triggered' , ( ) => {
806
+ const { result } = renderHook ( ( ) => {
807
+ useNavigationBottomTabPress ( ( ) => { } )
808
+ } )
809
+
810
+ expect ( mockHandler ) . toBeCalledTimes ( 0 )
811
+
812
+ expect ( result . current ) . toBeUndefined ( )
813
+ expect ( result . error ) . toBeUndefined ( )
814
+ } )
815
+
816
+ it ( 'should call handler twice' , ( ) => {
817
+ const { result } = renderHook ( ( ) => {
818
+ useNavigationBottomTabPress ( mockHandler )
819
+ } )
820
+
821
+ const event1 = { selectedTabIndex : 1 }
822
+ triggerEvent ( event1 )
823
+
824
+ const event2 = { selectedTabIndex : 1 }
825
+ triggerEvent ( event2 )
826
+
827
+ expect ( mockHandler ) . toBeCalledTimes ( 2 )
828
+ expect ( mockHandler ) . toHaveBeenNthCalledWith ( 1 , event1 )
829
+ expect ( mockHandler ) . toHaveBeenNthCalledWith ( 2 , event2 )
830
+
831
+ expect ( result . current ) . toBeUndefined ( )
832
+ expect ( result . error ) . toBeUndefined ( )
833
+ } )
834
+ } )
835
+
773
836
describe ( 'useNavigationBottomTabLongPress' , ( ) => {
774
837
let triggerEvent : ( event : BottomTabLongPressedEvent ) => void
775
838
let mockRemoveSubscription : ( ) => void
0 commit comments