Skip to content

Commit d720f5b

Browse files
[PRM-94] WCAG 3.3.1: Missing error summary for empty patient search (#611)
* Adds conditional rendering error box for incorrect input * More strict comparison for input error * Removed console logs * Changed error box rendering to trigger if inputError is equal to incorrect format message --------- Co-authored-by: oliverbeumkes-nhs <[email protected]>
1 parent a7d2de5 commit d720f5b

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

app/src/pages/patientSearchPage/PatientSearchPage.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('PatientSearchPage', () => {
7878
userEvent.type(screen.getByRole('textbox', { name: 'Enter NHS number' }), '21212');
7979
userEvent.click(screen.getByRole('button', { name: 'Search' }));
8080
await waitFor(() => {
81-
expect(screen.getByText(incorrectFormatMessage)).toBeInTheDocument();
81+
expect(screen.getAllByText(incorrectFormatMessage)).toHaveLength(2);
8282
});
8383
});
8484
});
@@ -422,7 +422,7 @@ describe('PatientSearchPage', () => {
422422
renderPatientSearchPage();
423423
userEvent.click(screen.getByRole('button', { name: 'Search' }));
424424
await waitFor(() => {
425-
expect(screen.getByText(incorrectFormatMessage)).toBeInTheDocument();
425+
expect(screen.getAllByText(incorrectFormatMessage)).toHaveLength(2);
426426
});
427427
});
428428

@@ -436,7 +436,7 @@ describe('PatientSearchPage', () => {
436436
);
437437
userEvent.click(screen.getByRole('button', { name: 'Search' }));
438438
await waitFor(() => {
439-
expect(screen.getByText(incorrectFormatMessage)).toBeInTheDocument();
439+
expect(screen.getAllByText(incorrectFormatMessage)).toHaveLength(2);
440440
});
441441
},
442442
);

app/src/pages/patientSearchPage/PatientSearchPage.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ function PatientSearchPage() {
6767
setInputError(null);
6868
setStatusCode(null);
6969
const nhsNumber = data.nhsNumber.replace(/[-\s]/gi, '');
70-
7170
try {
7271
const patientDetails = await getPatientDetails({
7372
nhsNumber,
@@ -127,7 +126,8 @@ function PatientSearchPage() {
127126
<BackLink asElement="a" href={routes.HOME}>
128127
Return to Home
129128
</BackLink>
130-
{submissionState === SEARCH_STATES.FAILED && (
129+
{(submissionState === SEARCH_STATES.FAILED ||
130+
inputError === incorrectFormatMessage) && (
131131
<>
132132
{isError ? (
133133
<ServiceError />
@@ -141,8 +141,9 @@ function PatientSearchPage() {
141141
)}
142142
</>
143143
)}
144+
144145
<h1>{pageTitle}</h1>
145-
<form onSubmit={handleSubmit(handleSearch, handleError)} noValidate>
146+
<form onSubmit={handleSubmit(handleSearch, handleError)}>
146147
<TextInput
147148
id="nhs-number-input"
148149
data-testid="nhs-number-input"

0 commit comments

Comments
 (0)