From 4da1132184b962e573ebb0dbfff49e338af139de Mon Sep 17 00:00:00 2001 From: Manas Date: Thu, 17 Nov 2022 01:28:27 +0530 Subject: [PATCH] feat: add test for social media icon component --- .../social-media-icon/index.test.js | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/test/unit/components/social-media-icon/index.test.js diff --git a/src/test/unit/components/social-media-icon/index.test.js b/src/test/unit/components/social-media-icon/index.test.js new file mode 100644 index 00000000..3a803a6d --- /dev/null +++ b/src/test/unit/components/social-media-icon/index.test.js @@ -0,0 +1,35 @@ +import { render, screen } from '@testing-library/react'; +import SocialMediaIcon from '@components/social-media-icon'; +import iconMapper from '@components/social-media-icon/social-media.constant'; + +const testData = { + id: 'ankushdharkar', + type: 'linkedin_id', +}; + +describe('describe Social Media Icon', () => { + beforeEach(() => + render() + ); + + it('Should render img icon properly ', () => { + const socialMediaIcon = screen.getByAltText('linkedIn'); + expect(socialMediaIcon).toBeInTheDocument(); + expect(socialMediaIcon).toHaveAttribute( + 'src', + iconMapper[testData.type].src + ); + }); + + it('Should render the info icon correctly', () => { + const socialMediaAnchor = document.querySelector('a'); + + expect(socialMediaAnchor).toHaveAttribute('target', '_blank'); + expect(socialMediaAnchor).toHaveAttribute('rel', 'noreferrer'); + expect(socialMediaAnchor).toHaveAttribute('tabIndex', '0'); + expect(socialMediaAnchor).toHaveAttribute( + 'href', + `${iconMapper[testData.type].href}/${[testData.id]}` + ); + }); +});