From 82cdacbc4d75112de9213062a57a2c8c2936758c Mon Sep 17 00:00:00 2001
From: m-tartari <37861893+m-tartari@users.noreply.github.com>
Date: Sat, 17 Feb 2024 16:04:50 +0100
Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test(atoms):=20add=20`Publication`?=
=?UTF-8?q?=20unit=20tests?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../atoms/Publication/Publication.test.tsx | 37 +++++++++++++++++++
1 file changed, 37 insertions(+)
create mode 100644 src/components/atoms/Publication/Publication.test.tsx
diff --git a/src/components/atoms/Publication/Publication.test.tsx b/src/components/atoms/Publication/Publication.test.tsx
new file mode 100644
index 0000000..99de24c
--- /dev/null
+++ b/src/components/atoms/Publication/Publication.test.tsx
@@ -0,0 +1,37 @@
+import { render, screen } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
+import { Box } from '@mui/material'
+
+import Publication from '.'
+
+vi.stubGlobal('open', vi.fn())
+const open = vi.spyOn(window, 'open')
+
+describe('Publication component', () => {
+ const defaultProps = {
+ year: '2022',
+ authors: 'Test Author',
+ title: 'Test Title',
+ location: 'Test Location',
+ link: 'https://test.com',
+ }
+ test('renders without crashing and displays the correct year, authors, title, and location', () => {
+ render()
+ expect(screen.getByText(defaultProps.year)).toBeInTheDocument()
+ expect(screen.getByText(defaultProps.title)).toBeInTheDocument()
+ expect(screen.getByText(defaultProps.authors, { exact: false })).toBeInTheDocument()
+ expect(screen.getByText(defaultProps.location, { exact: false })).toBeInTheDocument()
+ expect(screen.queryByRole('button')).not.toBeInTheDocument()
+ })
+
+ test('opens the correct link when the link button is clicked', async () => {
+ render()
+ await userEvent.click(screen.getByRole('button'))
+ expect(open).toHaveBeenCalledWith(defaultProps.link, '_blank')
+ })
+
+ test('renders correctly with a custom base component', () => {
+ render()
+ expect(screen.getByText(defaultProps.title)).toBeInTheDocument()
+ })
+})