From bd95d781ee9e6a8d695a57d23bc2940288635fbb Mon Sep 17 00:00:00 2001 From: KristinAoki Date: Fri, 8 Nov 2024 10:15:44 -0500 Subject: [PATCH] feat: add tests --- src/generic/PageNotFound.test.jsx | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/generic/PageNotFound.test.jsx diff --git a/src/generic/PageNotFound.test.jsx b/src/generic/PageNotFound.test.jsx new file mode 100644 index 0000000000..86aa854f24 --- /dev/null +++ b/src/generic/PageNotFound.test.jsx @@ -0,0 +1,41 @@ +import { getConfig, history } from '@edx/frontend-platform'; +import { Routes, Route } from 'react-router-dom'; +import { sendTrackEvent } from '@edx/frontend-platform/analytics'; + +import { + initializeTestStore, + render, + screen, +} from '../setupTest'; +import PageNotFound from './PageNotFound'; +import messages from './messages'; + +jest.mock('@edx/frontend-platform/analytics'); + +describe('PageNotFound', () => { + beforeEach(async () => { + await initializeTestStore(); + const invalidUrl = '/new/course'; + history.push(invalidUrl); + render( + + } /> + , + { wrapWithRouter: true }, + ); + }); + + it('displays page not found header', () => { + expect(screen.getByText(messages.pageNotFoundHeader.defaultMessage)).toBeVisible(); + }); + + it('displays link back to learner dashboard', () => { + const expected = getConfig().LMS_BASE_URL; + const homepageLink = screen.getByRole('link', { name: messages.homepageLink.defaultMessage }); + expect(homepageLink).toHaveAttribute('href', expected); + }); + + it('calls tracking events', () => { + expect(sendTrackEvent).toHaveBeenCalled(); + }); +});