-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add page not found route (#1514)
* feat: add page not found route * feat: add logging * feat: add tests
- Loading branch information
1 parent
0effb32
commit 4da37f3
Showing
4 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { getConfig } from '@edx/frontend-platform'; | ||
import { Hyperlink } from '@openedx/paragon'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { logError } from '@edx/frontend-platform/logging'; | ||
import { sendTrackEvent } from '@edx/frontend-platform/analytics'; | ||
import FooterSlot from '@openedx/frontend-slot-footer'; | ||
|
||
import HeaderSlot from '../plugin-slots/HeaderSlot'; | ||
import messages from './messages'; | ||
|
||
const PageNotFound = () => { | ||
const { formatMessage } = useIntl(); | ||
const location = window.location.href; | ||
|
||
logError('Page failed to load, probably an invalid URL.', location); | ||
sendTrackEvent('edx.ui.lms.page_not_found', { location }); | ||
|
||
return ( | ||
<> | ||
<HeaderSlot /> | ||
<main | ||
id="main-content" | ||
className="main-content d-flex justify-content-center align-items-center flex-column" | ||
style={{ | ||
height: '50vh', | ||
}} | ||
> | ||
<h1 className="h3"> | ||
{formatMessage(messages.pageNotFoundHeader)} | ||
</h1> | ||
<p> | ||
{formatMessage( | ||
messages.pageNotFoundBody, | ||
{ | ||
homepageLink: ( | ||
<Hyperlink destination={getConfig().LMS_BASE_URL}> | ||
{formatMessage(messages.homepageLink)} | ||
</Hyperlink> | ||
), | ||
}, | ||
)} | ||
</p> | ||
</main> | ||
<FooterSlot /> | ||
</> | ||
); | ||
}; | ||
|
||
export default PageNotFound; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters