From fd367af18884640582c461330fa50d09d4d5783c Mon Sep 17 00:00:00 2001 From: m-tartari <37861893+m-tartari@users.noreply.github.com> Date: Sat, 17 Feb 2024 14:40:26 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test(template):=20add=20`Page`=20un?= =?UTF-8?q?it=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/templates/Page/Page.test.tsx | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/components/templates/Page/Page.test.tsx diff --git a/src/components/templates/Page/Page.test.tsx b/src/components/templates/Page/Page.test.tsx new file mode 100644 index 0000000..904ecf7 --- /dev/null +++ b/src/components/templates/Page/Page.test.tsx @@ -0,0 +1,32 @@ +import { screen } from '@testing-library/react' + +import { renderWithRouter as render } from 'components/utils/tests' + +import Page from '.' + +describe('Page component', () => { + const defaultProps = { + title: 'Test Page', + children:
Test Content
, + sx: { color: 'text.secondary' }, + } + + it('renders correctly and without crashing', () => { + render() + + // displays the correct title + expect(screen.getByText(defaultProps.title)).toBeInTheDocument() + + // displays the correct children + expect(screen.getByText('Test Content')).toBeInTheDocument() + + // sets the document title correctly + expect(document.title).toBe(`Michele Tartari - ${defaultProps.title}`) + }) + + it('does not render the title and divider when title is not provided', () => { + render() + expect(screen.queryByText(defaultProps.title)).not.toBeInTheDocument() + expect(screen.queryByRole('separator')).not.toBeInTheDocument() + }) +})