forked from stakwork/sphinx-tribes-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e5eb3e
commit d1044ce
Showing
2 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import * as StoreHooks from '../../../store'; | ||
import { useIsMobile } from '../../../hooks'; | ||
import NameTag from '../NameTag.tsx'; | ||
|
||
jest.mock('../../../store', () => ({ | ||
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( | ||
<NameTag owner_pubkey={mockOwnerPubkey} owner_alias={''} img={''} id={0} widget={undefined} /> | ||
); | ||
|
||
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( | ||
<NameTag owner_pubkey={mockOwnerPubkey} owner_alias={''} img={''} id={0} widget={undefined} /> | ||
); | ||
|
||
expect(mockGetUserAvatarPlaceholder).toHaveBeenCalledWith(mockOwnerPubkey); | ||
const imageElement = screen.getByTestId('user-avatar'); | ||
expect(imageElement).toBeInTheDocument(); | ||
}); | ||
}); |