Skip to content

Commit 226a8f6

Browse files
committed
BN-71 | Fix. Remove Incorrect Error Mock
1 parent 441a3ce commit 226a8f6

File tree

2 files changed

+33
-98
lines changed

2 files changed

+33
-98
lines changed

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

Lines changed: 8 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import React from 'react';
2-
import { render, screen, waitFor, fireEvent } from '@testing-library/react';
2+
import {
3+
render,
4+
screen,
5+
waitFor,
6+
fireEvent,
7+
act,
8+
} from '@testing-library/react';
39
import userEvent from '@testing-library/user-event';
410
import { useTranslation, I18nextProvider } from 'react-i18next';
511
import DiagnosesForm from '../DiagnosesForm';
@@ -286,7 +292,7 @@ describe('DiagnosesForm', () => {
286292
await userEvent.type(searchInput, 'hyper');
287293

288294
// Attempt to select the same diagnosis
289-
await waitFor(async () => {
295+
await act(async () => {
290296
fireEvent.change(searchInput, {
291297
target: { value: mockConcepts[0].conceptName },
292298
});
@@ -335,37 +341,6 @@ describe('DiagnosesForm', () => {
335341
expect(defaultProps.handleResultSelection).not.toHaveBeenCalled();
336342
});
337343
});
338-
339-
it('should handle invalid item selection without errors', async () => {
340-
render(<DiagnosesForm {...defaultProps} />);
341-
342-
const searchInput = screen.getByPlaceholderText(
343-
'DIAGNOSES_SEARCH_PLACEHOLDER',
344-
);
345-
await userEvent.type(searchInput, 'hyper');
346-
347-
// Simulate selecting an item
348-
fireEvent.change(searchInput, {
349-
target: { value: mockConcepts[0].conceptName },
350-
});
351-
// Get the combobox and dropdown button
352-
const comboBox = screen.getByRole('combobox');
353-
const clearButton = screen.getByRole('button', {
354-
name: 'Clear selected item',
355-
});
356-
const dropdownButton = screen.getByRole('button', { name: 'Close' });
357-
358-
// Simulate selection of invalid item
359-
await waitFor(async () => {
360-
await userEvent.click(clearButton);
361-
await userEvent.click(dropdownButton);
362-
});
363-
364-
// Assertions
365-
expect(comboBox).toHaveValue('');
366-
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
367-
expect(defaultProps.handleResultSelection).not.toHaveBeenCalled();
368-
});
369344
});
370345

371346
describe('Error Handling', () => {
@@ -479,46 +454,6 @@ describe('DiagnosesForm', () => {
479454
expect(screen.getByText('DIAGNOSES_FORM_TITLE')).toBeInTheDocument();
480455
});
481456

482-
it('should handle network errors gracefully', async () => {
483-
const networkError = new Error('Network error: Failed to fetch');
484-
(useConceptSearch as jest.Mock).mockReturnValue({
485-
searchResults: [],
486-
loading: false,
487-
error: networkError,
488-
});
489-
490-
render(<DiagnosesForm {...defaultProps} />);
491-
const searchInput = screen.getByPlaceholderText(
492-
'DIAGNOSES_SEARCH_PLACEHOLDER',
493-
);
494-
await userEvent.type(searchInput, 'hyper');
495-
waitFor(() => {
496-
expect(screen.getByRole('alert')).toHaveTextContent(
497-
networkError.message,
498-
);
499-
});
500-
});
501-
502-
it('should handle server errors gracefully', async () => {
503-
const serverError = new Error('Server error: 500 Internal Server Error');
504-
(useConceptSearch as jest.Mock).mockReturnValue({
505-
searchResults: [],
506-
loading: false,
507-
error: serverError,
508-
});
509-
510-
render(<DiagnosesForm {...defaultProps} />);
511-
const searchInput = screen.getByPlaceholderText(
512-
'DIAGNOSES_SEARCH_PLACEHOLDER',
513-
);
514-
await userEvent.type(searchInput, 'hyper');
515-
waitFor(() => {
516-
expect(screen.getByRole('alert')).toHaveTextContent(
517-
serverError.message,
518-
);
519-
});
520-
});
521-
522457
it('should handle special characters in search term', async () => {
523458
render(<DiagnosesForm {...defaultProps} />);
524459
const searchInput = screen.getByPlaceholderText(

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-«r3u»-menu"
23+
aria-controls="downshift-«r3l»-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-«r3u»-menu"
38+
aria-controls="downshift-«r3l»-menu"
3939
aria-expanded="false"
4040
aria-label="Open"
4141
class="cds--list-box__menu-icon"
42-
id="downshift-«r3u»-toggle-button"
42+
id="downshift-«r3l»-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-«r3u»-label"
64+
aria-labelledby="downshift-«r3l»-label"
6565
class="cds--list-box__menu"
66-
id="downshift-«r3u»-menu"
66+
id="downshift-«r3l»-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-«r4e»-menu"
96+
aria-controls="downshift-«r45»-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-«r4e»-menu"
111+
aria-controls="downshift-«r45»-menu"
112112
aria-expanded="false"
113113
aria-label="Open"
114114
class="cds--list-box__menu-icon"
115-
id="downshift-«r4e»-toggle-button"
115+
id="downshift-«r45»-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-«r4e»-label"
137+
aria-labelledby="downshift-«r45»-label"
138138
class="cds--list-box__menu"
139-
id="downshift-«r4e»-menu"
139+
id="downshift-«r45»-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-«r41»-menu"
233+
aria-controls="downshift-«r3o»-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-«r41»-menu"
248+
aria-controls="downshift-«r3o»-menu"
249249
aria-expanded="false"
250250
aria-label="Open"
251251
class="cds--list-box__menu-icon"
252-
id="downshift-«r41»-toggle-button"
252+
id="downshift-«r3o»-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-«r41»-label"
274+
aria-labelledby="downshift-«r3o»-label"
275275
class="cds--list-box__menu"
276-
id="downshift-«r41»-menu"
276+
id="downshift-«r3o»-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-«r44»-menu"
306+
aria-controls="downshift-«r3r»-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-«r44»-menu"
321+
aria-controls="downshift-«r3r»-menu"
322322
aria-expanded="false"
323323
aria-label="Open"
324324
class="cds--list-box__menu-icon"
325-
id="downshift-«r44»-toggle-button"
325+
id="downshift-«r3r»-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-«r44»-label"
347+
aria-labelledby="downshift-«r3r»-label"
348348
class="cds--list-box__menu"
349-
id="downshift-«r44»-menu"
349+
id="downshift-«r3r»-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-«r47»-menu"
397+
aria-controls="downshift-«r3u»-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-«r47»-toggle-button"
402+
id="downshift-«r3u»-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-«r47»-label"
438+
aria-labelledby="downshift-«r3u»-label"
439439
class="cds--list-box__menu"
440-
id="downshift-«r47»-menu"
440+
id="downshift-«r3u»-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-«r49»"
484+
id="tooltip-«r40»"
485485
role="tooltip"
486486
>
487487
<span

0 commit comments

Comments
 (0)