Skip to content

Commit 0077767

Browse files
committed
fix. add Allergy test
1 parent 42f59d6 commit 0077767

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

micro-frontends/src/next-ui/Components/AddAllergy/AddAllergy.spec.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { render, fireEvent, screen, act, getByTestId, waitFor } from "@testing-library/react";
2+
import { render, fireEvent, screen, waitFor } from "@testing-library/react";
33
import { AddAllergy } from "./AddAllergy";
44
import {
55
saveAllergiesAPICall
@@ -277,6 +277,7 @@ describe("AddAllergy", () => {
277277

278278
it("should save allergies successfully and set isSaveSuccess to true", async () => {
279279
const { container } = render(
280+
<IntlProvider locale="en">
280281
<AddAllergy
281282
onClose={onClose}
282283
onSave={onSave}
@@ -286,6 +287,7 @@ describe("AddAllergy", () => {
286287
allergens={mockAllergensData}
287288
reaction={mockReactionsData}
288289
/>
290+
</IntlProvider>
289291
);
290292
saveAllergiesAPICall.mockResolvedValueOnce({ status: 201 });
291293
searchAllergen();
@@ -311,6 +313,7 @@ describe("AddAllergy", () => {
311313

312314
it("should set isSaveSuccess to false if saveAllergiesAPICall fails", async () => {
313315
const { container } = render(
316+
<IntlProvider locale="en">
314317
<AddAllergy
315318
onClose={onClose}
316319
onSave={onSave}
@@ -320,6 +323,7 @@ describe("AddAllergy", () => {
320323
allergens={mockAllergensData}
321324
reaction={mockReactionsData}
322325
/>
326+
</IntlProvider>
323327
);
324328
searchAllergen();
325329
selectAllergen();

micro-frontends/src/next-ui/Components/SearchAllergen/SearchAllergen.spec.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ describe("SearchAllergen", function () {
8989
});
9090
it('should call onChange function when an allergen is clicked', function () {
9191
const { container } = render(
92+
<IntlProvider locale="en">
9293
<SearchAllergen onChange={onChange} allergens={mockAllergensData} />
94+
</IntlProvider>
9395
);
9496

9597
const searchInput = container.querySelector('.bx--search-input');

micro-frontends/src/next-ui/Containers/patientAlergies/PatientAlergiesControl.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { ViewAllergiesAndReactions } from "../../Components/ViewAllergiesAndReactions/ViewAllergiesAndReactions";
1414
import { I18nProvider } from "../../Components/i18n/I18nProvider";
1515
import { NotificationCarbon } from "bahmni-carbon-ui";
16+
import { allergyError, getErrorKey } from "../../errorMessages";
1617

1718
/** NOTE: for reasons known only to react2angular,
1819
* any functions passed in as props will be undefined at the start, even ones inside other objects
@@ -125,6 +126,7 @@ export function PatientAlergiesControl(props) {
125126
const [allergiesAndReactions, setAllergiesAndReactions] = useState([]);
126127
const [showSuccessPopup, setShowSuccessPopup] = useState(false);
127128
const [showErrorPopup, setShowErrorPopup] = useState(false);
129+
const [error, setError] = useState('');
128130

129131
const noAllergiesText = (
130132
<FormattedMessage
@@ -222,12 +224,13 @@ export function PatientAlergiesControl(props) {
222224
onClose={() => {
223225
setShowAddAllergyPanel(false);
224226
}}
225-
onSave={async (isSaveSuccess) => {
227+
onSave={async (isSaveSuccess, error) => {
226228
if(isSaveSuccess){
227229
setShowSuccessPopup(true);
228230
setShowAddAllergyPanel(false);
229231
}
230232
else if(isSaveSuccess === false){
233+
setError(getErrorKey(error));
231234
setShowErrorPopup(true);
232235
}
233236
}}

0 commit comments

Comments
 (0)