@@ -11,7 +11,7 @@ jest.mock('./styles', () => {
1111
1212 return {
1313 ListItemContainer : ( props ) => (
14- < TouchableOpacity testID = "vault-container" { ... props } >
14+ < TouchableOpacity { ... props } testID = "vault-container" >
1515 { props . children }
1616 </ TouchableOpacity >
1717 ) ,
@@ -29,17 +29,29 @@ jest.mock('./styles', () => {
2929 { props . children }
3030 </ Text >
3131 ) ,
32- ListItemActions : ( props ) => < View testID = "vault-actions" { ...props } />
32+ ListItemActions : ( props ) => < View testID = "vault-actions" { ...props } /> ,
33+ SelectedListItemIconContainer : ( props ) => (
34+ < View testID = "selected-icon-container" { ...props } />
35+ )
3336 }
3437} )
3538
3639jest . mock ( 'pearpass-lib-ui-react-native-components' , ( ) => ( {
3740 BrushIcon : ( ) => 'BrushIcon' ,
41+ CheckIcon : ( ) => 'CheckIcon' ,
3842 DeleteIcon : ( ) => 'DeleteIcon' ,
3943 LockCircleIcon : ( ) => 'LockCircleIcon' ,
4044 ShareIcon : ( ) => 'ShareIcon'
4145} ) )
4246
47+ jest . mock ( 'pearpass-lib-ui-theme-provider/native' , ( ) => ( {
48+ colors : {
49+ primary400 : { mode1 : '#000000' } ,
50+ black : { mode1 : '#000000' } ,
51+ white : { mode1 : '#ffffff' }
52+ }
53+ } ) )
54+
4355describe ( 'ListItem' , ( ) => {
4456 const mockProps = {
4557 name : 'Test Vault' ,
@@ -65,15 +77,13 @@ describe('ListItem', () => {
6577 expect ( mockProps . onPress ) . toHaveBeenCalled ( )
6678 } )
6779
68- it ( 'renders actions when showActions is true' , ( ) => {
69- const { getByTestId } = render (
70- < ListItem { ...mockProps } showActions = { true } />
71- )
80+ it ( 'renders actions when action callbacks are provided' , ( ) => {
81+ const { getByTestId } = render ( < ListItem { ...mockProps } /> )
7282
7383 expect ( getByTestId ( 'vault-actions' ) ) . toBeTruthy ( )
7484 } )
7585
76- it ( 'does not render actions when showActions is false ' , ( ) => {
86+ it ( 'does not render action icons when callbacks are not provided ' , ( ) => {
7787 const mockWithoutActionsProps = {
7888 name : 'Test Vault' ,
7989 date : '2023-01-01' ,
@@ -82,8 +92,31 @@ describe('ListItem', () => {
8292
8393 const { queryByTestId } = render ( < ListItem { ...mockWithoutActionsProps } /> )
8494
85- expect ( queryByTestId ( 'vault-actions' ) ?. props . children [ 0 ] ) . toBeUndefined ( )
86- expect ( queryByTestId ( 'vault-actions' ) ?. props . children [ 1 ] ) . toBeUndefined ( )
87- expect ( queryByTestId ( 'vault-actions' ) ?. props . children [ 2 ] ) . toBeUndefined ( )
95+ const actionsContainer = queryByTestId ( 'vault-actions' )
96+ expect ( actionsContainer ) . toBeTruthy ( )
97+ // When no callbacks are provided, the actions container should have no meaningful children
98+ // React filters out falsy values, so children should be undefined, null, or an array of falsy values
99+ const children = actionsContainer . props . children
100+ const hasNoChildren =
101+ ! children ||
102+ ( Array . isArray ( children ) && children . every ( ( child ) => ! child ) ) ||
103+ children === null
104+ expect ( hasNoChildren ) . toBeTruthy ( )
105+ } )
106+
107+ it ( 'renders CheckIcon when isSelected is true' , ( ) => {
108+ const { getByTestId } = render (
109+ < ListItem { ...mockProps } isSelected = { true } />
110+ )
111+
112+ expect ( getByTestId ( 'selected-icon-container' ) ) . toBeTruthy ( )
113+ } )
114+
115+ it ( 'renders correctly when isLoading is true' , ( ) => {
116+ const { getByTestId } = render ( < ListItem { ...mockProps } isLoading = { true } /> )
117+
118+ // Component should still render name and date when loading
119+ expect ( getByTestId ( 'vault-name' ) . props . children ) . toBe ( 'Test Vault' )
120+ expect ( getByTestId ( 'vault-date' ) ) . toBeTruthy ( )
88121 } )
89122} )
0 commit comments