Skip to content

Commit 452fb31

Browse files
committed
BN-71 | Fix. Broken DiagnosesForm Tests
1 parent 226a8f6 commit 452fb31

File tree

3 files changed

+86
-30
lines changed

3 files changed

+86
-30
lines changed

src/components/clinical/diagnosesForm/DiagnosesForm.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const DiagnosesForm: React.FC<DiagnosesFormProps> = React.memo(
4646
// Handle search errors
4747
useEffect(() => {
4848
if (searchError) {
49-
setDiagnosisErrors([searchError]);
49+
setDiagnosisErrors([...diagnosisErrors, searchError]);
5050
}
5151
}, [searchError]);
5252

@@ -79,7 +79,8 @@ const DiagnosesForm: React.FC<DiagnosesFormProps> = React.memo(
7979
const isSearchEmpty =
8080
searchResults.length === 0 &&
8181
!isSearchLoading &&
82-
searchDiagnosesTerm.length > 2;
82+
searchDiagnosesTerm.length > 2 &&
83+
!searchError;
8384

8485
return (
8586
<Tile className={styles.diagnosesFormTile}>

src/components/clinical/diagnosesForm/__tests__/DiagnosesForm.test.tsx

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,69 @@ describe('DiagnosesForm', () => {
454454
expect(screen.getByText('DIAGNOSES_FORM_TITLE')).toBeInTheDocument();
455455
});
456456

457-
it('should handle special characters in search term', async () => {
457+
it('should handle network errors gracefully', async () => {
458+
const networkError = new Error('Network error: Failed to fetch');
459+
(useConceptSearch as jest.Mock).mockReturnValue({
460+
searchResults: [],
461+
loading: false,
462+
error: networkError,
463+
});
464+
458465
render(<DiagnosesForm {...defaultProps} />);
459466
const searchInput = screen.getByPlaceholderText(
460467
'DIAGNOSES_SEARCH_PLACEHOLDER',
461468
);
462-
await userEvent.type(searchInput, '@#$%^&*');
469+
await waitFor(() => {
470+
userEvent.type(searchInput, 'hyper');
471+
});
472+
waitFor(() => {
473+
expect(screen.getByRole('alert')).toHaveTextContent(
474+
networkError.message,
475+
);
476+
});
477+
});
463478

464-
expect(useConceptSearch).toHaveBeenCalledWith('@#$%^&*');
479+
it('should handle server errors gracefully', async () => {
480+
const serverError = new Error('Server error: 500 Internal Server Error');
481+
(useConceptSearch as jest.Mock).mockReturnValue({
482+
searchResults: [],
483+
loading: false,
484+
error: serverError,
485+
});
486+
487+
render(<DiagnosesForm {...defaultProps} />);
488+
const searchInput = screen.getByPlaceholderText(
489+
'DIAGNOSES_SEARCH_PLACEHOLDER',
490+
);
491+
await waitFor(() => {
492+
userEvent.type(searchInput, 'hyper');
493+
});
494+
waitFor(() => {
495+
expect(screen.getByRole('alert')).toHaveTextContent(
496+
serverError.message,
497+
);
498+
});
499+
});
500+
501+
it('should handle special characters in search term', async () => {
502+
const mockError = new Error('Special characters not allowed');
503+
(useConceptSearch as jest.Mock).mockReturnValue({
504+
searchResults: [],
505+
loading: false,
506+
error: mockError,
507+
});
508+
509+
render(<DiagnosesForm {...defaultProps} />);
510+
const searchInput = screen.getByPlaceholderText(
511+
'DIAGNOSES_SEARCH_PLACEHOLDER',
512+
);
513+
await waitFor(() => {
514+
userEvent.type(searchInput, '@#$%^&*');
515+
});
516+
await waitFor(() => {
517+
expect(screen.getByRole('alert')).toBeInTheDocument();
518+
expect(screen.getByText(mockError.message)).toBeInTheDocument();
519+
});
465520
});
466521
});
467522

src/components/clinical/diagnosesForm/__tests__/__snapshots__/DiagnosesForm.test.tsx.snap

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ exports[`DiagnosesForm Snapshot Tests empty form matches snapshot 1`] = `
2020
<input
2121
aria-activedescendant=""
2222
aria-autocomplete="list"
23-
aria-controls="downshift-«r3l»-menu"
23+
aria-controls="downshift-«r3r»-menu"
2424
aria-expanded="false"
2525
aria-haspopup="listbox"
2626
aria-label="DIAGNOSES_SEARCH_ARIA_LABEL"
@@ -35,11 +35,11 @@ exports[`DiagnosesForm Snapshot Tests empty form matches snapshot 1`] = `
3535
value=""
3636
/>
3737
<button
38-
aria-controls="downshift-«r3l»-menu"
38+
aria-controls="downshift-«r3r»-menu"
3939
aria-expanded="false"
4040
aria-label="Open"
4141
class="cds--list-box__menu-icon"
42-
id="downshift-«r3l»-toggle-button"
42+
id="downshift-«r3r»-toggle-button"
4343
tabindex="-1"
4444
title="Open"
4545
type="button"
@@ -61,9 +61,9 @@ exports[`DiagnosesForm Snapshot Tests empty form matches snapshot 1`] = `
6161
</button>
6262
</div>
6363
<ul
64-
aria-labelledby="downshift-«r3l»-label"
64+
aria-labelledby="downshift-«r3r»-label"
6565
class="cds--list-box__menu"
66-
id="downshift-«r3l»-menu"
66+
id="downshift-«r3r»-menu"
6767
role="listbox"
6868
style="position: fixed; left: 0px; top: 0px; visibility: visible; transform: translate(0px, 0px);"
6969
/>
@@ -93,7 +93,7 @@ exports[`DiagnosesForm Snapshot Tests form with errors matches snapshot 1`] = `
9393
<input
9494
aria-activedescendant=""
9595
aria-autocomplete="list"
96-
aria-controls="downshift-«r45»-menu"
96+
aria-controls="downshift-«r4b»-menu"
9797
aria-expanded="false"
9898
aria-haspopup="listbox"
9999
aria-label="DIAGNOSES_SEARCH_ARIA_LABEL"
@@ -108,11 +108,11 @@ exports[`DiagnosesForm Snapshot Tests form with errors matches snapshot 1`] = `
108108
value=""
109109
/>
110110
<button
111-
aria-controls="downshift-«r45»-menu"
111+
aria-controls="downshift-«r4b»-menu"
112112
aria-expanded="false"
113113
aria-label="Open"
114114
class="cds--list-box__menu-icon"
115-
id="downshift-«r45»-toggle-button"
115+
id="downshift-«r4b»-toggle-button"
116116
tabindex="-1"
117117
title="Open"
118118
type="button"
@@ -134,9 +134,9 @@ exports[`DiagnosesForm Snapshot Tests form with errors matches snapshot 1`] = `
134134
</button>
135135
</div>
136136
<ul
137-
aria-labelledby="downshift-«r45»-label"
137+
aria-labelledby="downshift-«r4b»-label"
138138
class="cds--list-box__menu"
139-
id="downshift-«r45»-menu"
139+
id="downshift-«r4b»-menu"
140140
role="listbox"
141141
style="position: fixed; left: 0px; top: 0px; visibility: visible; transform: translate(0px, 0px);"
142142
/>
@@ -230,7 +230,7 @@ exports[`DiagnosesForm Snapshot Tests form with search results matches snapshot
230230
<input
231231
aria-activedescendant=""
232232
aria-autocomplete="list"
233-
aria-controls="downshift-«r3o»-menu"
233+
aria-controls="downshift-«r3u»-menu"
234234
aria-expanded="false"
235235
aria-haspopup="listbox"
236236
aria-label="DIAGNOSES_SEARCH_ARIA_LABEL"
@@ -245,11 +245,11 @@ exports[`DiagnosesForm Snapshot Tests form with search results matches snapshot
245245
value=""
246246
/>
247247
<button
248-
aria-controls="downshift-«r3o»-menu"
248+
aria-controls="downshift-«r3u»-menu"
249249
aria-expanded="false"
250250
aria-label="Open"
251251
class="cds--list-box__menu-icon"
252-
id="downshift-«r3o»-toggle-button"
252+
id="downshift-«r3u»-toggle-button"
253253
tabindex="-1"
254254
title="Open"
255255
type="button"
@@ -271,9 +271,9 @@ exports[`DiagnosesForm Snapshot Tests form with search results matches snapshot
271271
</button>
272272
</div>
273273
<ul
274-
aria-labelledby="downshift-«r3o»-label"
274+
aria-labelledby="downshift-«r3u»-label"
275275
class="cds--list-box__menu"
276-
id="downshift-«r3o»-menu"
276+
id="downshift-«r3u»-menu"
277277
role="listbox"
278278
style="position: fixed; left: 0px; top: 0px; visibility: visible; transform: translate(0px, 0px);"
279279
/>
@@ -303,7 +303,7 @@ exports[`DiagnosesForm Snapshot Tests form with selected diagnoses matches snaps
303303
<input
304304
aria-activedescendant=""
305305
aria-autocomplete="list"
306-
aria-controls="downshift-«r3r»-menu"
306+
aria-controls="downshift-«r41»-menu"
307307
aria-expanded="false"
308308
aria-haspopup="listbox"
309309
aria-label="DIAGNOSES_SEARCH_ARIA_LABEL"
@@ -318,11 +318,11 @@ exports[`DiagnosesForm Snapshot Tests form with selected diagnoses matches snaps
318318
value=""
319319
/>
320320
<button
321-
aria-controls="downshift-«r3r»-menu"
321+
aria-controls="downshift-«r41»-menu"
322322
aria-expanded="false"
323323
aria-label="Open"
324324
class="cds--list-box__menu-icon"
325-
id="downshift-«r3r»-toggle-button"
325+
id="downshift-«r41»-toggle-button"
326326
tabindex="-1"
327327
title="Open"
328328
type="button"
@@ -344,9 +344,9 @@ exports[`DiagnosesForm Snapshot Tests form with selected diagnoses matches snaps
344344
</button>
345345
</div>
346346
<ul
347-
aria-labelledby="downshift-«r3r»-label"
347+
aria-labelledby="downshift-«r41»-label"
348348
class="cds--list-box__menu"
349-
id="downshift-«r3r»-menu"
349+
id="downshift-«r41»-menu"
350350
role="listbox"
351351
style="position: fixed; left: 0px; top: 0px; visibility: visible; transform: translate(0px, 0px);"
352352
/>
@@ -394,12 +394,12 @@ exports[`DiagnosesForm Snapshot Tests form with selected diagnoses matches snaps
394394
>
395395
<button
396396
aria-activedescendant=""
397-
aria-controls="downshift-«r3u»-menu"
397+
aria-controls="downshift-«r44»-menu"
398398
aria-expanded="false"
399399
aria-haspopup="listbox"
400400
aria-label="DIAGNOSES_CERTAINTY_ARIA_LABEL"
401401
class="cds--list-box__field"
402-
id="downshift-«r3u»-toggle-button"
402+
id="downshift-«r44»-toggle-button"
403403
role="combobox"
404404
tabindex="0"
405405
title="Confirmed"
@@ -435,9 +435,9 @@ exports[`DiagnosesForm Snapshot Tests form with selected diagnoses matches snaps
435435
</div>
436436
</button>
437437
<ul
438-
aria-labelledby="downshift-«r3u»-label"
438+
aria-labelledby="downshift-«r44»-label"
439439
class="cds--list-box__menu"
440-
id="downshift-«r3u»-menu"
440+
id="downshift-«r44»-menu"
441441
role="listbox"
442442
style="position: fixed; left: 0px; top: 0px; visibility: visible; transform: translate(0px, 0px);"
443443
/>
@@ -481,7 +481,7 @@ exports[`DiagnosesForm Snapshot Tests form with selected diagnoses matches snaps
481481
<span
482482
aria-hidden="true"
483483
class="cds--popover"
484-
id="tooltip-«r40»"
484+
id="tooltip-«r46»"
485485
role="tooltip"
486486
>
487487
<span

0 commit comments

Comments
 (0)