-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test cases for SocialMedia component
- Loading branch information
1 parent
3d7998c
commit 7a258ac
Showing
2 changed files
with
75 additions
and
1 deletion.
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
74 changes: 74 additions & 0 deletions
74
frontend/src/components/userDetail/tests/headerProfile.test.js
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,74 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { SocialMedia } from '../headerProfile'; | ||
import { IntlProviders } from '../../../utils/testWithIntl'; | ||
|
||
let mockData = { | ||
id: 10291369, | ||
username: 'johndoe', | ||
slackId: 'johndoeSlack', | ||
twitterId: 'johndoeTwitter', | ||
facebookId: 'johndoeFacebook', | ||
linkedinId: 'johndoeLinkedin', | ||
}; | ||
|
||
describe('SocialMedia component', () => { | ||
it('should render the correct number of icons', () => { | ||
const { container } = render( | ||
<IntlProviders> | ||
<SocialMedia data={mockData} /> | ||
</IntlProviders>, | ||
); | ||
// img tag for OSM, Missng Maps and Slack | ||
expect(screen.getAllByRole('img')).toHaveLength(3); | ||
// SVGs for Facebook, Linkedin, Twitter | ||
expect(container.querySelectorAll('svg').length).toBe(3); | ||
}); | ||
|
||
it('should render correct links', () => { | ||
render( | ||
<IntlProviders> | ||
<SocialMedia data={mockData} /> | ||
</IntlProviders>, | ||
); | ||
expect( | ||
screen.getAllByRole('link', { | ||
name: 'johndoe', | ||
}), | ||
).toHaveLength(2); | ||
expect(screen.queryAllByRole('link', { name: 'johndoe' })[0]).toHaveAttribute( | ||
'href', | ||
'https://www.openstreetmap.org/user/johndoe', | ||
); | ||
expect(screen.queryAllByRole('link', { name: 'johndoe' })[1]).toHaveAttribute( | ||
'href', | ||
'https://www.missingmaps.org/users/#/johndoe', | ||
); | ||
expect(screen.getByRole('link', { name: 'johndoeTwitter' })).toHaveAttribute( | ||
'href', | ||
'https://www.twitter.com/johndoeTwitter', | ||
); | ||
expect(screen.getByRole('link', { name: 'johndoeFacebook' })).toHaveAttribute( | ||
'href', | ||
'https://www.facebook.com/johndoeFacebook', | ||
); | ||
expect(screen.getByRole('link', { name: 'johndoeLinkedin' })).toHaveAttribute( | ||
'href', | ||
'https://www.linkedin.com/in/johndoeLinkedin', | ||
); | ||
}); | ||
|
||
it('should not render the Facebook icon and link for a falsy value', () => { | ||
mockData.facebookId = ''; | ||
render( | ||
<IntlProviders> | ||
<SocialMedia data={mockData} /> | ||
</IntlProviders>, | ||
); | ||
expect( | ||
screen.queryByRole('link', { | ||
name: 'johndoefacebook', | ||
}), | ||
).not.toBeInTheDocument(); | ||
}); | ||
}); |