Skip to content

Commit

Permalink
feat: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KristinAoki committed Nov 8, 2024
1 parent 2a29602 commit bd95d78
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/generic/PageNotFound.test.jsx
Original file line number Diff line number Diff line change
@@ -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(
<Routes>
<Route path="*" element={<PageNotFound />} />
</Routes>,
{ 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();
});
});

0 comments on commit bd95d78

Please sign in to comment.