Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
…ie-patient into MAT-7734_relevantAttributeChoices
  • Loading branch information
Cecilia Liu committed Oct 30, 2024
2 parents d088380 + 44c3317 commit 53418f4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 59 deletions.
8 changes: 4 additions & 4 deletions src/components/common/quantityInput/QuantityInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ describe("QuantityInput Component", () => {
expect(quantityFieldInput.value).toBe("");
expect(onQuantityChange).toBeCalled();
userEvent.type(quantityFieldInput, "-1-");
await expect(onQuantityChange).toHaveBeenNthCalledWith(2, {
expect(onQuantityChange).toHaveBeenNthCalledWith(2, {
unit: "mg",
value: "-1",
value: -1,
});
userEvent.type(quantityFieldInput, "2.5/...-");
await expect(onQuantityChange).toHaveBeenNthCalledWith(6, {
expect(onQuantityChange).toHaveBeenNthCalledWith(6, {
unit: "mg",
value: "2.5",
value: 2.5,
});
});
});
2 changes: 1 addition & 1 deletion src/components/common/quantityInput/QuantityInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const QuantityInput = ({

const handleQuantityValueChange = (newValue) => {
const newQuantity: CQL.Quantity = {
value: newValue,
value: Number(newValue),
unit: currentQuantity.unit,
};
setCurrentQuantity(newQuantity);
Expand Down
30 changes: 20 additions & 10 deletions src/components/editTestCase/qiCore/EditTestCase.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ describe("EditTestCase component", () => {
const createBtn = screen.getByRole("button", { name: "Save" });
userEvent.click(createBtn);

const alert = await screen.findByTestId("create-test-case-alert");
const alert = await screen.findByTestId("error-toast");
expect(alert).toBeInTheDocument();
expect(alert).toHaveTextContent(
"An error occurred while creating the test case."
Expand Down Expand Up @@ -784,11 +784,20 @@ describe("EditTestCase component", () => {
const createBtn = screen.getByRole("button", { name: "Save" });
userEvent.click(createBtn);

const alert = await screen.findByTestId("create-test-case-alert");
expect(alert).toBeInTheDocument();
const alert = await screen.findByTestId("error-toast");
expect(alert).toHaveTextContent(
"An error occurred - create did not return the expected successful result."
);

const closeAlertBtn = screen.findByTestId("close-toast-button");
userEvent.click(await closeAlertBtn);
await waitFor(() => {
expect(
screen.queryByText(
"An error occurred - create did not return the expected successful result."
)
).not.toBeInTheDocument();
});
});

it("should update test case when update button is clicked", async () => {
Expand Down Expand Up @@ -945,16 +954,18 @@ describe("EditTestCase component", () => {
const createBtn = screen.getByRole("button", { name: "Save" });
userEvent.click(createBtn);

const alert = await screen.findByTestId("create-test-case-alert");
const alert = await screen.findByTestId("error-toast");
expect(alert).toHaveTextContent(
"An error occurred while creating the test case."
);

const closeAlertBtn = screen.findByTestId("close-create-test-case-alert");
const closeAlertBtn = screen.findByTestId("close-toast-button");
userEvent.click(await closeAlertBtn);

const dismissedAlert = await screen.queryByRole("alert");
expect(dismissedAlert).not.toBeInTheDocument();
await waitFor(() => {
expect(
screen.queryByText("An error occurred while creating the test case.")
).not.toBeInTheDocument();
});
});

it("should load existing test case data when viewing specific test case", async () => {
Expand Down Expand Up @@ -1933,7 +1944,6 @@ describe("EditTestCase component", () => {
userEvent.type(seriesInput, testCaseDescription);
const updateBtn = screen.getByRole("button", { name: "Save" });
userEvent.click(updateBtn);

const debugOutput = await screen.findByText(
testCaseAlertToast
? "Changes updated successfully but the following error(s) were found"
Expand Down Expand Up @@ -2404,7 +2414,7 @@ describe("EditTestCase component", () => {
await waitFor(() => expect(saveButton).not.toBeDisabled());
userEvent.click(saveButton);

const alert = await screen.findByTestId("create-test-case-alert");
const alert = await screen.findByTestId("error-toast");
expect(alert).toBeInTheDocument();
});

Expand Down
79 changes: 35 additions & 44 deletions src/components/editTestCase/qiCore/EditTestCase.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {
ReactNode,
Dispatch,
SetStateAction,
useCallback,
Expand Down Expand Up @@ -220,16 +221,16 @@ const EditTestCase = (props: EditTestCaseProps) => {

// Toast utilities
const [toastOpen, setToastOpen] = useState<boolean>(false);
const [toastMessage, setToastMessage] = useState<string>("");
const [toastMessage, setToastMessage] = useState<ReactNode>("");
const [toastType, setToastType] = useState<string>("danger");
const onToastClose = () => {
setToastMessage("");
setToastOpen(false);
};

const showToast = (
message: string,
toastType: "success" | "danger" | "warning"
message: ReactNode,
toastType: "success" | "danger" | "warning" | "info"
) => {
setToastOpen(true);
setToastType(toastType);
Expand Down Expand Up @@ -414,10 +415,7 @@ const EditTestCase = (props: EditTestCaseProps) => {
setSeriesState({ loaded: true, series: existingSeries })
)
.catch((error) => {
setAlert(() => ({
status: "error",
message: error.message,
}));
showToast(error.message, "danger");
setErrors([...errors, error.message]);
});
}
Expand Down Expand Up @@ -471,10 +469,7 @@ const EditTestCase = (props: EditTestCaseProps) => {

handleTestCaseResponse(savedTestCase, "create");
} catch (error) {
setAlert(() => ({
status: "error",
message: "An error occurred while creating the test case.",
}));
showToast("An error occurred while creating the test case.", "danger");
setErrors([...errors, "An error occurred while creating the test case."]);
}
};
Expand Down Expand Up @@ -502,21 +497,14 @@ const EditTestCase = (props: EditTestCaseProps) => {
});
setTestCase(_.cloneDeep(updatedTc));
setEditorVal(updatedTc.json);

handleTestCaseResponse(updatedTc, "update");
} catch (error) {
setAlert(() => {
if (error instanceof MadieError) {
return {
status: "error",
message: error.message,
};
}
return {
status: "error",
message: "An error occurred while updating the test case.",
};
});
showToast(
error instanceof MadieError
? error.message
: "An error occurred while updating the test case.",
"danger"
);
setErrors([...errors, "An error occurred while updating the test case."]);
}
};
Expand Down Expand Up @@ -616,30 +604,33 @@ const EditTestCase = (props: EditTestCaseProps) => {
const valErrors = validationErrors.map((error) => (
<li>{error.diagnostics}</li>
));
setAlert({
status: `${severityOfValidationErrors(validationErrors)}`,
message: testCaseAlertToast ? (
<div>
<h3>
Changes {action}d successfully but the following{" "}
{severityOfValidationErrors(validationErrors)}(s) were found
</h3>
<ul>{valErrors}</ul>
</div>
) : (
`Test case updated successfully with ${severityOfValidationErrors(
validationErrors
)}s in JSON`
),
});
const message: ReactNode = testCaseAlertToast ? (
<div>
<h3>
Changes {action}d successfully but the following{" "}
{severityOfValidationErrors(validationErrors)}(s) were found
</h3>
<ul>{valErrors}</ul>
</div>
) : (
`Test case updated successfully with ${severityOfValidationErrors(
validationErrors
)}s in JSON`
);
let severity = severityOfValidationErrors(validationErrors);
if (severity === "error") {
severity = "danger";
}
//@ts-ignore
showToast(message, severity);
handleHapiOutcome(testCase.hapiOperationOutcome);
}
updateMeasureStore(action, testCase);
} else {
setAlert(() => ({
status: "error",
message: `An error occurred - ${action} did not return the expected successful result.`,
}));
showToast(
`An error occurred - ${action} did not return the expected successful result.`,
"danger"
);
setErrors([
...errors,
`An error occurred - ${action} did not return the expected successful result.`,
Expand Down

0 comments on commit 53418f4

Please sign in to comment.