From d1044ce1b1d7cb03fdf36a7c7603db06012556d5 Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Fri, 1 Mar 2024 23:13:54 +0500 Subject: [PATCH] fix display default photo in bounty --- src/people/utils/NameTag.tsx | 8 ++-- src/people/utils/__test__/NameTag.spec.tsx | 56 ++++++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 src/people/utils/__test__/NameTag.spec.tsx diff --git a/src/people/utils/NameTag.tsx b/src/people/utils/NameTag.tsx index 8de92ae3..414920e4 100644 --- a/src/people/utils/NameTag.tsx +++ b/src/people/utils/NameTag.tsx @@ -74,13 +74,15 @@ const Wrap = styled.div` function NameTag(props: NameTagProps) { const { owner_alias, owner_pubkey, img, created, id, style, widget, iconSize, textSize, isPaid } = props; - const { ui } = useStores(); + const { ui, main } = useStores(); const color = colors['light']; const history = useHistory(); const isMobile = useIsMobile(); + const userImg = img || main.getUserAvatarPlaceholder(owner_pubkey); + const isSelected = ui.selectedPerson === id ? true : false; function selectPerson(e: any) { @@ -113,7 +115,7 @@ function NameTag(props: NameTagProps) { > {!isSelected && ( <> - + - +
({ + useStores: jest.fn() +})); + +jest.mock('../../../hooks', () => ({ + useIsMobile: jest.fn() +})); + +describe('NameTag', () => { + const mockOwnerPubkey = 'test-pubkey'; + const defaultImageUrl = '/static/avatarPlaceholders/placeholder_1.jpg'; + const mockGetUserAvatarPlaceholder = jest.fn().mockReturnValue(defaultImageUrl); + + beforeEach(() => { + (StoreHooks.useStores as jest.Mock).mockReturnValue({ + main: { + getUserAvatarPlaceholder: mockGetUserAvatarPlaceholder + }, + ui: { + selectedPerson: null + } + }); + (useIsMobile as jest.Mock).mockReset(); + }); + + it('displays the default face image on desktop side', () => { + (useIsMobile as jest.Mock).mockReturnValue(false); + + render( + + ); + + expect(mockGetUserAvatarPlaceholder).toHaveBeenCalledWith(mockOwnerPubkey); + const imageElement = screen.getByTestId('user-avatar'); + expect(imageElement).toBeInTheDocument(); + }); + + it('displays the default face image on mobile side', () => { + (useIsMobile as jest.Mock).mockReturnValue(true); + + render( + + ); + + expect(mockGetUserAvatarPlaceholder).toHaveBeenCalledWith(mockOwnerPubkey); + const imageElement = screen.getByTestId('user-avatar'); + expect(imageElement).toBeInTheDocument(); + }); +});