Skip to content

Commit dc0d6b3

Browse files
HelanaNadyExo1i
andauthored
feat(edit-profile): profile media uploads - [CU-869atccd6] (#78)
Co-authored-by: Youssef Noser <121557650+Exo1i@users.noreply.github.com>
1 parent 423e4a0 commit dc0d6b3

9 files changed

Lines changed: 202 additions & 103 deletions

File tree

src/__tests__/components/ui/sidebar/SidebarAccountSection.test.tsx

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
import { fireEvent, render } from '@testing-library/react-native';
22

33
import SidebarAccountSection from '@/components/sidebar/SidebarAccountSection';
4+
import { useSessionStore } from '@/stores/sessionStore';
45

56
import type { AccountSession } from '@/stores/sessionStore';
67

78
jest.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
/>

src/components/sidebar/SidebarAccountSection.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Feather } from '@expo/vector-icons';
66

77
import AccountAvatarButton from '@/components/ui/AccountAvatarButton';
88
import { useTheme } from '@/hooks/useTheme';
9-
import { type AccountSession } from '@/stores/sessionStore';
9+
import { useSessionStore, type AccountSession } from '@/stores/sessionStore';
1010
import { colors } from '@/utils/colorTheme';
1111
import { formatCount } from '@/utils/formatCount';
1212

@@ -16,26 +16,20 @@ interface UserStats {
1616
}
1717

1818
interface SidebarAccountSectionProps {
19-
currentAccount: AccountSession | null;
2019
userStats: UserStats | null;
2120
otherAccounts: AccountSession[];
22-
activeAccountId: string | null;
2321
onAvatarPress: (accountId: string) => void;
2422
onMorePress: () => void;
2523
}
2624

2725
const SidebarAccountSection = memo(
28-
({
29-
currentAccount,
30-
userStats,
31-
otherAccounts,
32-
activeAccountId,
33-
onAvatarPress,
34-
onMorePress,
35-
}: SidebarAccountSectionProps) => {
26+
({ userStats, otherAccounts, onAvatarPress, onMorePress }: SidebarAccountSectionProps) => {
3627
const { theme } = useTheme();
3728
const currentColors = colors[theme];
3829

30+
const { accounts, activeAccountId } = useSessionStore();
31+
const currentAccount = accounts.find((a) => a.id === activeAccountId) || null;
32+
3933
return (
4034
<View
4135
style={[

src/navigation/app/CustomDrawerContent.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,8 @@ export default function CustomDrawerContent(props: DrawerContentComponentProps)
103103
style={{ backgroundColor: currentColors.background }}
104104
>
105105
<SidebarAccountSection
106-
currentAccount={activeAccount}
107106
userStats={userStats}
108107
otherAccounts={accounts}
109-
activeAccountId={activeAccountId}
110108
onAvatarPress={handleAvatarPress}
111109
onMorePress={openAccountSwitcher}
112110
/>

0 commit comments

Comments
 (0)