Skip to content

Commit

Permalink
Added title and h1 to page not found shared component (#30355)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosfelix2 authored Jun 20, 2024
1 parent 24bff29 commit 4b5d5b9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe(`${appName} -- transitional Medical Records page disabled`, () => {
});

it('renders not found page', () => {
cy.findByRole('heading', { level: 3, name: notFoundHeading });
cy.findByRole('heading', { name: notFoundHeading });
cy.injectAxeThenAxeCheck();
});
});
13 changes: 10 additions & 3 deletions src/platform/site-wide/user-nav/components/PageNotFound.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { useEffect } from 'react';
import PropTypes from 'prop-types';
// Cypress does not like @ imports, so import record-event with a path
// Cypress does not like @ imports, so import with a path instead
import recordEventFn from '~/platform/monitoring/record-event';
import { focusElement } from '~/platform/utilities/ui';

export const notFoundHeading = 'Sorry — we can’t find that page';
export const notFoundTitle = 'Page not found | Veterans Affairs';

const PageNotFound = ({ recordEvent = recordEventFn } = {}) => {
useEffect(
Expand All @@ -15,13 +17,18 @@ const PageNotFound = ({ recordEvent = recordEventFn } = {}) => {
[recordEvent],
);

useEffect(() => {
document.title = notFoundTitle;
focusElement('h1');
}, []);

return (
<>
<div className="main maintenance-page vads-u-padding-top--4" role="main">
<div className="primary">
<div className="row">
<div className="usa-content vads-u-text-align--center vads-u-margin-x--auto">
<h3 id="sorry--we-cant-find-that-page">{notFoundHeading}</h3>
<div className="usa-content vads-u-text-align--center vads-u-margin-x--auto columns">
<h1 id="sorry--we-cant-find-that-page">{notFoundHeading}</h1>
<p>Try the search box or one of the common questions below.</p>
<div className="feature vads-u-display--flex vads-u-align-items--center">
<form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import React from 'react';
import { render, waitFor } from '@testing-library/react';
import { expect } from 'chai';
import sinon from 'sinon';
import PageNotFound from '../../components/PageNotFound';
import PageNotFound, {
notFoundHeading,
notFoundTitle,
} from '../../components/PageNotFound';

describe('PageNotFound Component', () => {
it('renders', async () => {
const recordEvent = sinon.spy();
const props = { recordEvent };
const { getByRole } = render(<PageNotFound {...props} />);
getByRole('heading', { name: /we can’t find that page/ });
const heading = getByRole('heading', { name: notFoundHeading });
expect(heading).to.exist;
expect(document.activeElement).to.eq(heading);
expect(document.title).to.eql(notFoundTitle);
await waitFor(() => {
expect(recordEvent.calledOnce).to.be.true;
expect(recordEvent.calledWith({ event: 'nav-404-error' })).to.be.true;
Expand Down

0 comments on commit 4b5d5b9

Please sign in to comment.