diff --git a/src/components/pages/ContactPage/ContactPage.test.tsx b/src/components/pages/ContactPage/ContactPage.test.tsx new file mode 100644 index 0000000..839f218 --- /dev/null +++ b/src/components/pages/ContactPage/ContactPage.test.tsx @@ -0,0 +1,41 @@ +import { screen } from '@testing-library/react' +import userEvent from '@testing-library/user-event' + +import { renderWithRouter as render } from 'components/utils/tests' + +import ContactPage from './ContactPage' + +vi.stubGlobal('open', vi.fn()) +describe('ContactPage', () => { + const open = vi.spyOn(window, 'open') + + test('renders without crashing and displays the correct contact methods', () => { + render() + + expect(screen.getAllByText('Contacts')).toHaveLength(2) // Page title and the Appbar drawer link + expect(screen.getByLabelText('Email button')).toBeInTheDocument() + expect(screen.getByLabelText('LinkedIn button')).toBeInTheDocument() + expect(screen.getByLabelText('GitHub button')).toBeInTheDocument() + }) + + test('opens the correct link when the email button is clicked', async () => { + render() + + await userEvent.click(screen.getByLabelText('Email button')) + expect(open).toHaveBeenCalledWith('mailto:michele.tartari+web@live.com', '_blank') + }) + + test('opens the correct link when the LinkedIn button is clicked', async () => { + render() + + await userEvent.click(screen.getByLabelText('LinkedIn button')) + expect(open).toHaveBeenCalledWith('https://www.linkedin.com/in/m-tartari/', '_blank') + }) + + test('opens the correct link when the GitHub button is clicked', async () => { + render() + + await userEvent.click(screen.getByLabelText('GitHub button')) + expect(open).toHaveBeenCalledWith('https://www.github.com/m-tartari/', '_blank') + }) +}) diff --git a/src/components/pages/ContactPage/ContactPage.tsx b/src/components/pages/ContactPage/ContactPage.tsx index ce76fc3..4ecf1ba 100644 --- a/src/components/pages/ContactPage/ContactPage.tsx +++ b/src/components/pages/ContactPage/ContactPage.tsx @@ -24,7 +24,7 @@ const ContactPage = () => { - window.open('mailto:michele.tartari+web@live.com', '_blank')}> + window.open('mailto:michele.tartari+web@live.com', '_blank')}> michele.tartari+web @@ -34,7 +34,7 @@ const ContactPage = () => { - window.open('https://www.linkedin.com/in/m-tartari/', '_blank')}> + window.open('https://www.linkedin.com/in/m-tartari/', '_blank')}> m-tartari @@ -42,7 +42,7 @@ const ContactPage = () => { - window.open('https://www.github.com/m-tartari/', '_blank')}> + window.open('https://www.github.com/m-tartari/', '_blank')}> m-tartari