Skip to content

Commit

Permalink
OH2-357 | Add cypress e2e tests to cover medical types (admin/types/m…
Browse files Browse the repository at this point in the history
…edicals) (#632)

* Add cypress e2e tests to cover medical types (admin/types/medicals)

* Correction de typo

* Correction des attributs mal renseignes

* Remane medical file

* Files organisation
  • Loading branch information
fogouang authored Jul 18, 2024
1 parent 1a33146 commit fccc1c6
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/// <reference types="cypress" />

const MEDICAL_TYPE_STARTS_PATH = "/admin/types/medicals";

describe("Add medical type Activity specs", () => {
it("should render the ui", () => {
cy.authenticate(MEDICAL_TYPE_STARTS_PATH);
cy.dataCy("sub-medical-title").contains("Manage medical types");
});

it("should show medical type creation form", () => {
cy.dataCy("add-medical-type").click();
cy.dataCy("sub-medical-title").contains("New medical type");
});

it("should fail to create a new medical type", () => {
cy.byId("code").type("FAIL");
cy.byId("description").type("Medical type");
cy.dataCy("submit-form").click();
cy.dataCy("info-box").contains("Fail");
});

it("should successfully create a new medical type", () => {
cy.byId("code").clear().type("22");
cy.dataCy("submit-form").click();
cy.dataCy("dialog-info").contains(
"The medical type has been created successfully!"
);
cy.dataCy("approve-dialog").click();
});

it("should redirect after medical type creation", () => {
cy.dataCy("sub-medical-title").contains("Manage medical types");
});

it("should cancel the cancellation of the medical type creation", () => {
cy.dataCy("add-medical-type").click();
cy.dataCy("cancel-form").click();
cy.dataCy("dialog-info").contains(
"Are you sure to cancel the medical type creation?"
);
cy.dataCy("close-dialog").click();
cy.dataCy("dialog-info").should("not.exist");
});

it("should cancel the medical type creation", () => {
cy.dataCy("cancel-form").click();
cy.dataCy("approve-dialog").click();
cy.dataCy("dialog-info").should("not.exist");
cy.dataCy("sub-medical-title").contains("Manage medical types");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/// <reference types="cypress" />

const MEDICAL2_TYPES_START_PATH = "/admin/types/medicals";

describe("Medical Activity specs", () => {
it("should render the ui", () => {
cy.authenticate(MEDICAL2_TYPES_START_PATH);
cy.dataCy("sub-medical-title").contains("Manage medical types");
});

it("should present the table with four rows", () => {
cy.dataCy("medical-types-table")
.find("table")
.then(($table) => {
const rows = $table.find("tbody tr");
expect(rows.length).equal(4);
});
});

it("should display the deletion dialog", () => {
cy.dataCy("table-delete-action").first().click();
cy.dataCy("dialog-info").contains("Are you sure to delete item with code");
});

it("should cancel the medical deletion", () => {
cy.dataCy("close-dialog").click();
cy.dataCy("dialog-info").should("not.exist");
cy.dataCy("medical-types-table")
.find("table")
.then(($table) => {
const rows = $table.find("tbody tr");
expect(rows.length).equal(4);
});
});

it("should delete the medical", () => {
cy.dataCy("table-delete-action").first().click();
cy.dataCy("approve-dialog").click();
cy.dataCy("dialog-info").contains(
"The medical type has been deleted successfully!"
);
cy.dataCy("approve-dialog").last().click();
cy.dataCy("medical-types-table")
.find("table")
.then(($table) => {
const rows = $table.find("tbody tr");
expect(rows.length).equal(3);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/// <reference types="cypress" />

const MEDICAL_TYPE_START_PATH = "/admin/types/medicals";

describe("Medical types Edit Activity specs", () => {
it("should render the ui", () => {
cy.authenticate(MEDICAL_TYPE_START_PATH);
cy.dataCy("sub-medical-title").contains("Manage medical types");
});

it("should show medical type edit form", () => {
cy.dataCy("table-edit-action").first().click();
cy.dataCy("sub-medical-title").contains("Edit medical type");
});

it("should fail to edit the medical type", () => {
cy.byId("code").should("be.disabled");
cy.byId("description").clear();
cy.dataCy("submit-form").click();
cy.dataCy("dialog-info").should("not.exist");
});

it("should successfully save medical type changes", () => {
cy.byId("description").clear().type("Medical type");
cy.dataCy("submit-form").click();
cy.dataCy("dialog-info").contains("has been updated successfully!");
cy.dataCy("approve-dialog").click();
});

it("should redirect after medical type update", () => {
cy.dataCy("sub-medical-title").contains("Manage medical types");
});

it("should cancel the cancellation of the medical type update", () => {
cy.dataCy("table-edit-action").first().click();
cy.dataCy("cancel-form").click();
cy.dataCy("dialog-info").contains(
"Are you sure to cancel the medical type update?"
);
cy.dataCy("close-dialog").click();
cy.dataCy("dialog-info").should("not.exist");
});

it("should cancel the medical type update", () => {
cy.dataCy("cancel-form").click();
cy.dataCy("approve-dialog").click();
cy.dataCy("dialog-info").should("not.exist");
cy.dataCy("sub-medical-title").contains("Manage medical types");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// <reference types="cypress" />

const MEDICAL_TYPES_START_PATH = "/admin/types/medicals";

describe("Medical types Activity specs", () => {
it("should render the ui", () => {
cy.authenticate(MEDICAL_TYPES_START_PATH);
cy.dataCy("sub-medical-title").contains("Manage medical types");
});

it("should present the table with four rows", () => {
cy.dataCy("medical-types-table")
.find("table")
.then(($table) => {
const rows = $table.find("tbody tr");
expect(rows.length).equal(4);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ const MedicalTypes = () => {
const { t } = useTranslation();
return (
<>
<h3>{t("medicalTypes.title")}</h3>
<h3 data-cy="sub-medical-title">{t("medicalTypes.title")}</h3>

<div className="medicalTypes">
<div className="medicalTypes" data-cy="medical-types-table">
<MedicalTypesTable
onEdit={handleEdit}
onDelete={handleDelete}
Expand All @@ -54,6 +54,7 @@ const MedicalTypes = () => {
type="button"
variant="contained"
color="primary"
dataCy="add-medical-type"
>
{t("medicalTypes.addMedicalType")}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { updateMedicalType } from "../../../../../../../state/types/medicals/act
import { PATHS } from "../../../../../../../consts";
import { getInitialFields } from "../medicalTypesForm/consts";
import MedicalTypeForm from "../medicalTypesForm/MedicalTypeForm";
import { setTypeMode } from "../../../../../../../state/types/config";
import { setTypeMode, TypeMode } from "../../../../../../../state/types/config";
import "./styles.scss";

export const EditMedicalType = () => {
Expand All @@ -21,21 +21,29 @@ export const EditMedicalType = () => {
(state) => state.types.medicals.update
);

const mode = useSelector<IState, TypeMode>(
(state) => state.types.config.mode
);

const handleSubmit = (value: MedicalTypeDTO) => {
dispatch(updateMedicalType(value));
};

useEffect(() => {
dispatch(setTypeMode("edit"));
});
if (mode !== "edit") {
dispatch(setTypeMode("edit"));
}
}, [mode, dispatch]);

if (state?.code !== code) {
return <Navigate to={PATHS.admin_medicals_types} />;
}

return (
<div className="editMedicalType">
<h3 className="title">{t("medicalTypes.editMedicalType")}</h3>
<h3 className="title" data-cy="sub-medical-title">
{t("medicalTypes.editMedicalType")}
</h3>
<MedicalTypeForm
creationMode={false}
onSubmit={handleSubmit}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ const MedicalTypeForm: FC<IMedicalTypeFormProps> = ({

<div className="medicalTypesForm__buttonSet">
<div className="submit_button">
<Button type="submit" variant="contained" disabled={isLoading}>
<Button
type="submit"
variant="contained"
disabled={isLoading}
dataCy="submit-form"
>
{submitButtonLabel}
</Button>
</div>
Expand All @@ -150,6 +155,7 @@ const MedicalTypeForm: FC<IMedicalTypeFormProps> = ({
variant="text"
disabled={isLoading}
onClick={() => setOpenResetConfirmation(true)}
dataCy="cancel-form"
>
{resetButtonLabel}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const NewMedicalType = () => {
};

return (
<div className="newMedicalType">
<div className="newMedicalType" data-cy="sub-medical-title">
<h3 className="title">{t("medicalTypes.addMedicalType")}</h3>
<MedicalTypeForm
creationMode
Expand Down

0 comments on commit fccc1c6

Please sign in to comment.