Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/components/__tests__/user-table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,19 @@ describe('UserTable component', () => {
expect(screen.getByText('1 user')).toBeInTheDocument()
expect(screen.getByText('user1')).toBeInTheDocument()
})

it('should filter out users with undefined username', () => {
const usersWithUndefined: User[] = [
{ username: 'user1', profileUrl: 'https://instagram.com/user1' },
{ username: undefined as any, profileUrl: 'https://instagram.com/user2' },
{ username: 'user3', profileUrl: 'https://instagram.com/user3' }
]

render(<UserTable title="Test Users" users={usersWithUndefined} />)

// Should only show valid users
expect(screen.getByText('user1')).toBeInTheDocument()
expect(screen.getByText('user3')).toBeInTheDocument()
expect(screen.queryByText('undefined')).not.toBeInTheDocument()
})
})
12 changes: 9 additions & 3 deletions src/components/import-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ const parseFollowers = (json: FileContent): User[] => {
// New structure from user
if (Array.isArray(json)) {
return json.flatMap(item =>
(item.string_list_data || []).map(d => ({ username: d.value, profileUrl: d.href }))
(item.string_list_data || [])
.filter(d => d?.value)
.map(d => ({ username: d.value, profileUrl: d.href || '' }))
);
}
// Original structure
if (json.relationships_followers) {
return (json.relationships_followers || []).flatMap(item =>
(item.string_list_data || []).map(d => ({ username: d.value, profileUrl: d.href }))
(item.string_list_data || [])
.filter(d => d?.value)
.map(d => ({ username: d.value, profileUrl: d.href || '' }))
);
}
throw new Error("Invalid followers file format. Expected an array or an object with 'relationships_followers' key.");
Expand All @@ -63,7 +67,9 @@ const parseFollowers = (json: FileContent): User[] => {
const parseFollowing = (json: InstagramData): User[] => {
if (!json.relationships_following) throw new Error("Invalid following file format. Expected 'relationships_following' key.");
return (json.relationships_following || []).flatMap(item =>
(item.string_list_data || []).map(d => ({ username: d.value, profileUrl: d.href }))
(item.string_list_data || [])
.filter(d => d?.value)
.map(d => ({ username: d.value, profileUrl: d.href || '' }))
);
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/user-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function UserTable({ title, users }: UserTableProps) {
};

const filteredAndSortedUsers = users
.filter(user => user.username.toLowerCase().includes(searchTerm.toLowerCase()))
.filter(user => user?.username?.toLowerCase().includes(searchTerm.toLowerCase()))
.sort((a, b) => {
if (sortOrder === 'asc') {
return a.username.localeCompare(b.username);
Expand Down
Loading