1
+ import * as NativeNavigation from '@react-navigation/native' ;
1
2
import { fireEvent , render , screen } from '@testing-library/react-native' ;
2
3
import { SectionList } from 'react-native' ;
3
4
import BaseSelectionList from '@components/SelectionList/BaseSelectionList' ;
@@ -44,8 +45,17 @@ describe('BaseSelectionList', () => {
44
45
) ;
45
46
}
46
47
48
+ it ( 'should not trigger item press if screen is not focused' , ( ) => {
49
+ ( NativeNavigation . useIsFocused as jest . Mock ) . mockReturnValue ( false ) ;
50
+ render ( < BaseListItemRenderer sections = { [ { data : mockSections } ] } /> ) ;
51
+ fireEvent . press ( screen . getByTestId ( `${ CONST . BASE_LIST_ITEM_TEST_ID } 1` ) ) ;
52
+ expect ( onSelectRowMock ) . toHaveBeenCalledTimes ( 0 ) ;
53
+ } ) ;
54
+
47
55
it ( 'should handle item press correctly' , ( ) => {
56
+ ( NativeNavigation . useIsFocused as jest . Mock ) . mockReturnValue ( true ) ;
48
57
render ( < BaseListItemRenderer sections = { [ { data : mockSections } ] } /> ) ;
58
+
49
59
fireEvent . press ( screen . getByTestId ( `${ CONST . BASE_LIST_ITEM_TEST_ID } 1` ) ) ;
50
60
expect ( onSelectRowMock ) . toHaveBeenCalledWith ( {
51
61
...mockSections . at ( 1 ) ,
@@ -54,6 +64,7 @@ describe('BaseSelectionList', () => {
54
64
} ) ;
55
65
56
66
it ( 'should update focused item when sections are updated from BE' , ( ) => {
67
+ ( NativeNavigation . useIsFocused as jest . Mock ) . mockReturnValue ( true ) ;
57
68
const updatedMockSections = mockSections . map ( ( section ) => ( {
58
69
...section ,
59
70
isSelected : section . keyForList === '2' ,
0 commit comments