11import { fireEvent , render } from '@testing-library/react-native' ;
22
33import SidebarAccountSection from '@/components/sidebar/SidebarAccountSection' ;
4+ import { useSessionStore } from '@/stores/sessionStore' ;
45
56import type { AccountSession } from '@/stores/sessionStore' ;
67
78jest . mock ( '@/hooks/useTheme' , ( ) => ( {
89 useTheme : ( ) => ( { theme : 'light' } ) ,
910} ) ) ;
1011
11- describe ( 'SidebarAccountSection' , ( ) => {
12- const mockCurrentAccount : AccountSession = {
13- id : '1' ,
14- username : 'johndoe' ,
15- displayName : 'John Doe' ,
16- avatarUrl : 'https://example.com/avatar.jpg' ,
17- tokens : { accessToken : 'token123' , refreshToken : 'refresh123' } ,
18- lastUsedAt : Date . now ( ) ,
19- } ;
12+ jest . mock ( '@/stores/sessionStore' , ( ) => ( {
13+ useSessionStore : jest . fn ( ) ,
14+ } ) ) ;
2015
16+ describe ( 'SidebarAccountSection' , ( ) => {
2117 const mockOtherAccounts : AccountSession [ ] = [
2218 {
2319 id : '1' ,
@@ -55,15 +51,18 @@ describe('SidebarAccountSection', () => {
5551
5652 beforeEach ( ( ) => {
5753 jest . clearAllMocks ( ) ;
54+ // Setup the store mock
55+ ( useSessionStore as unknown as jest . Mock ) . mockReturnValue ( {
56+ accounts : mockOtherAccounts ,
57+ activeAccountId : '1' ,
58+ } ) ;
5859 } ) ;
5960
6061 it ( 'renders current account information' , ( ) => {
6162 const { getByText } = render (
6263 < SidebarAccountSection
63- currentAccount = { mockCurrentAccount }
6464 userStats = { mockUserStats }
6565 otherAccounts = { mockOtherAccounts }
66- activeAccountId = "1"
6766 onAvatarPress = { mockOnAvatarPress }
6867 onMorePress = { mockOnMorePress }
6968 />
@@ -76,10 +75,8 @@ describe('SidebarAccountSection', () => {
7675 it ( 'renders follower and following stats' , ( ) => {
7776 const { getByText } = render (
7877 < SidebarAccountSection
79- currentAccount = { mockCurrentAccount }
8078 userStats = { mockUserStats }
8179 otherAccounts = { mockOtherAccounts }
82- activeAccountId = "1"
8380 onAvatarPress = { mockOnAvatarPress }
8481 onMorePress = { mockOnMorePress }
8582 />
@@ -99,10 +96,8 @@ describe('SidebarAccountSection', () => {
9996
10097 const { getByText } = render (
10198 < SidebarAccountSection
102- currentAccount = { mockCurrentAccount }
10399 userStats = { largeStats }
104100 otherAccounts = { mockOtherAccounts }
105- activeAccountId = "1"
106101 onAvatarPress = { mockOnAvatarPress }
107102 onMorePress = { mockOnMorePress }
108103 />
@@ -115,10 +110,8 @@ describe('SidebarAccountSection', () => {
115110 it ( 'renders up to 3 account avatars' , ( ) => {
116111 const { getByTestId } = render (
117112 < SidebarAccountSection
118- currentAccount = { mockCurrentAccount }
119113 userStats = { mockUserStats }
120114 otherAccounts = { mockOtherAccounts }
121- activeAccountId = "1"
122115 onAvatarPress = { mockOnAvatarPress }
123116 onMorePress = { mockOnMorePress }
124117 />
@@ -132,10 +125,8 @@ describe('SidebarAccountSection', () => {
132125 it ( 'calls onAvatarPress when avatar is pressed' , ( ) => {
133126 const { getByTestId } = render (
134127 < SidebarAccountSection
135- currentAccount = { mockCurrentAccount }
136128 userStats = { mockUserStats }
137129 otherAccounts = { mockOtherAccounts }
138- activeAccountId = "1"
139130 onAvatarPress = { mockOnAvatarPress }
140131 onMorePress = { mockOnMorePress }
141132 />
@@ -148,10 +139,8 @@ describe('SidebarAccountSection', () => {
148139 it ( 'calls onMorePress when more button is pressed' , ( ) => {
149140 const { getByTestId } = render (
150141 < SidebarAccountSection
151- currentAccount = { mockCurrentAccount }
152142 userStats = { mockUserStats }
153143 otherAccounts = { mockOtherAccounts }
154- activeAccountId = "1"
155144 onAvatarPress = { mockOnAvatarPress }
156145 onMorePress = { mockOnMorePress }
157146 />
@@ -164,10 +153,8 @@ describe('SidebarAccountSection', () => {
164153 it ( 'does not render stats when userStats is null' , ( ) => {
165154 const { queryByText } = render (
166155 < SidebarAccountSection
167- currentAccount = { mockCurrentAccount }
168156 userStats = { null }
169157 otherAccounts = { mockOtherAccounts }
170- activeAccountId = "1"
171158 onAvatarPress = { mockOnAvatarPress }
172159 onMorePress = { mockOnMorePress }
173160 />
@@ -178,12 +165,15 @@ describe('SidebarAccountSection', () => {
178165 } ) ;
179166
180167 it ( 'renders correctly when currentAccount is null' , ( ) => {
168+ ( useSessionStore as unknown as jest . Mock ) . mockReturnValue ( {
169+ accounts : mockOtherAccounts ,
170+ activeAccountId : null ,
171+ } ) ;
172+
181173 const { queryByText } = render (
182174 < SidebarAccountSection
183- currentAccount = { null }
184175 userStats = { null }
185176 otherAccounts = { mockOtherAccounts }
186- activeAccountId = { null }
187177 onAvatarPress = { mockOnAvatarPress }
188178 onMorePress = { mockOnMorePress }
189179 />
@@ -196,10 +186,8 @@ describe('SidebarAccountSection', () => {
196186 it ( 'has proper accessibility attributes' , ( ) => {
197187 const { getByTestId } = render (
198188 < SidebarAccountSection
199- currentAccount = { mockCurrentAccount }
200189 userStats = { mockUserStats }
201190 otherAccounts = { mockOtherAccounts }
202- activeAccountId = "1"
203191 onAvatarPress = { mockOnAvatarPress }
204192 onMorePress = { mockOnMorePress }
205193 />
0 commit comments