Skip to content

Commit

Permalink
Merge pull request #569 from gasp/patient-update-action
Browse files Browse the repository at this point in the history
fix(wording): patient edit submit is a save action
  • Loading branch information
axelpezzo authored May 21, 2024
2 parents 62829fc + 8c10320 commit 57e3853
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
13 changes: 6 additions & 7 deletions cypress/integrations/edit_patient_activity.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ describe("EditPatientActivity spec", () => {
});
});

it("should pass the “submit” button label", () => {
cy.dataCy("patient-data-form").contains("Submit");
it("should pass the “save” button label", () => {
cy.dataCy("patient-data-submit-button").contains("Save");
});

it("should allow the user to change the profile picture", () => {
Expand All @@ -51,9 +51,8 @@ describe("EditPatientActivity spec", () => {
force: true,
});
cy.get(".MuiDialogContent-root .MuiButton-containedPrimary").click();
cy.wait(2000);
cy.wait(3000);

cy.wait(1000);
cy.dataCy("profile-picture")
.find("img")
.invoke("attr", "src")
Expand Down Expand Up @@ -82,7 +81,7 @@ describe("EditPatientActivity spec", () => {

it("should show a confirmation dialog when the call is successful", () => {
cy.byId("firstName").clear().type("Marcelo");
cy.dataCy("patient-data-form").contains("Submit").click();
cy.dataCy("patient-data-submit-button").click();
cy.dataCy("dialog-info").contains("The patient was edit successfully.");
});

Expand All @@ -92,7 +91,7 @@ describe("EditPatientActivity spec", () => {
});

it("should redirect the user to the Patient on Patient button click", () => {
cy.dataCy("patient-data-form").contains("Submit").click();
cy.dataCy("patient-data-submit-button").click();
cy.dataCy("dialog-button-set").contains("Patient").click();
cy.dataCy("patient-details");
});
Expand All @@ -104,7 +103,7 @@ describe("EditPatientActivity spec", () => {

it("should not leave on the Cancel button click, if the Cancel button of the Cancel Dialog is click", () => {
cy.byId("firstName").clear().type("Marcelo");
cy.dataCy("patient-data-form").contains("Cancel").click();
cy.dataCy("patient-data-cancel-button").click();
cy.url().then((url) => {
cy.dataCy("dialog-button-set").contains("Keep").click();
cy.url().should("eq", url);
Expand Down
17 changes: 11 additions & 6 deletions cypress/integrations/new_patient_activity.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import initialValues from "../fixtures/newPatientInitialValues.json";

const START_PATH = "http://localhost:3000/patients/new";
type InitialValuesKeys = keyof typeof initialValues;

const START_PATH = "/patients/new";

describe("NewPatientActivity spec", () => {
it("should render the ui", () => {
Expand All @@ -26,12 +28,15 @@ describe("NewPatientActivity spec", () => {
id: `[id=${fieldName.toString()}]`,
}));
fields.forEach((field) => {
cy.get(field.id).should("have.value", initialValues[field.fieldName]);
cy.get(field.id).should(
"have.value",
initialValues[field.fieldName as InitialValuesKeys]
);
});
});

it("should pass the “submit” button label", () => {
cy.get(".submit_button button");
cy.dataCy("patient-data-submit-button").contains("Submit");
});

it("should allow the user to add and remove a profile picture", () => {
Expand Down Expand Up @@ -98,7 +103,7 @@ describe("NewPatientActivity spec", () => {
cy.byId("secondName").clear().type("fail");
cy.get(".MuiSelect-select[id=sex]").click();
cy.dataValue("M").click();
cy.dataCy("patient-data-form").contains("Submit").click();
cy.dataCy("patient-data-submit-button").click();
cy.dataCy("info-box").should("have.class", "error");
});

Expand All @@ -110,7 +115,7 @@ describe("NewPatientActivity spec", () => {
cy.byId("secondName").clear().type("Jobim");
cy.get(".MuiSelect-select[id=sex]").click();
cy.dataValue("M").click();
cy.dataCy("patient-data-form").contains("Submit").click();
cy.dataCy("patient-data-submit-button").click();
cy.dataCy("dialog-info").contains(
"The patient registration was successful."
);
Expand All @@ -131,7 +136,7 @@ describe("NewPatientActivity spec", () => {
cy.byId("secondName").type("Jobim");
cy.get(".MuiSelect-select[id=sex]").click();
cy.dataValue("M").click();
cy.dataCy("patient-data-form").contains("Submit").click();
cy.dataCy("patient-data-submit-button").click();
cy.dataCy("dialog-button-set").contains("Go to home").click();
cy.dataCy("dashboard-activity");
});
Expand Down
30 changes: 18 additions & 12 deletions src/components/accessories/patientDataForm/PatientDataForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import SelectField from "../selectField/SelectField";
import Button from "../button/Button";
import TextField from "../textField/TextField";
import "./styles.scss";
import { TAgeFieldName, TAgeType, TProps } from "./types";
import { TAgeFieldName, TProps } from "./types";
import { useTranslation } from "react-i18next";
import { Tooltip } from "@material-ui/core";
import { formCustomization } from "../../../customization/formCustomization";
Expand Down Expand Up @@ -77,15 +77,15 @@ const PatientDataForm: FunctionComponent<TProps> = ({
: string(),
sex: string().required(t("common.required")),
telephone: string().matches(
/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/,
/^[+]?[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-\s.]?[0-9]{4,6}$/,
t("common.incorrectformat")
),
});
}, [ageType]);
}, [ageType, t]);

useEffect(() => {
dispatch(getAgeTypes());
}, []);
}, [dispatch]);

const initialValues = getFromFields(fields, "value");
const cities = useSelector((state: IState) => state.patients.getCities.data);
Expand Down Expand Up @@ -167,7 +167,7 @@ const PatientDataForm: FunctionComponent<TProps> = ({
setFieldValue(fieldName, value);
formik.setFieldTouched(fieldName);
},
[setFieldValue]
[setFieldValue, formik]
);

const onBlurCallback = useCallback(
Expand Down Expand Up @@ -303,7 +303,7 @@ const PatientDataForm: FunctionComponent<TProps> = ({
required={FIELD_VALIDATION.SUGGESTED}
/>
</div>
{ageType == "agetype" && (
{ageType === "agetype" && (
<div className="patientDataForm__item">
<SelectField
fieldName="agetype"
Expand All @@ -323,7 +323,7 @@ const PatientDataForm: FunctionComponent<TProps> = ({
/>
</div>
)}
{ageType == "age" && (
{ageType === "age" && (
<div className="patientDataForm__item">
<TextField
field={formik.getFieldProps("age")}
Expand Down Expand Up @@ -552,7 +552,12 @@ const PatientDataForm: FunctionComponent<TProps> = ({

<div className="patientDataForm__buttonSet">
<div className="submit_button">
<Button type="submit" variant="contained" disabled={isLoading}>
<Button
type="submit"
variant="contained"
disabled={isLoading}
dataCy="patient-data-submit-button"
>
{submitButtonLabel}
</Button>
</div>
Expand All @@ -562,14 +567,15 @@ const PatientDataForm: FunctionComponent<TProps> = ({
variant="text"
disabled={isLoading}
onClick={() => setOpenResetConfirmation(true)}
dataCy="patient-data-cancel-button"
>
{mode == "create" && resetButtonLabel}
{mode == "edit" && t("common.cancel")}
{mode === "create" && resetButtonLabel}
{mode === "edit" && t("common.cancel")}
</Button>
</div>
</div>

{mode == "create" && (
{mode === "create" && (
<ConfirmationDialog
isOpen={openResetConfirmation}
title={resetButtonLabel.toUpperCase()}
Expand All @@ -582,7 +588,7 @@ const PatientDataForm: FunctionComponent<TProps> = ({
/>
)}

{mode == "edit" && (
{mode === "edit" && (
<ConfirmationDialog
isOpen={openResetConfirmation}
title={t("common.cancel").toUpperCase()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const EditPatientActivity: FunctionComponent<TProps> = ({
fields={updateFields(initialFields, patient?.data)}
profilePicture={patient.data?.blobPhoto}
onSubmit={onSubmit}
submitButtonLabel={t("common.submit")}
submitButtonLabel={t("common.save")}
resetButtonLabel={t("common.reset")}
isLoading={isLoading}
shouldResetForm={shouldResetForm}
Expand Down

0 comments on commit 57e3853

Please sign in to comment.