Skip to content

Commit

Permalink
OH2-355 | Tests / Add cypress e2e tests to cover diseases types (admi…
Browse files Browse the repository at this point in the history
…n/types/diseases) (#628)

* tests:OH2-355 | Tests / Add cypress e2e tests to cover diseases types (admin/types/diseases)

* chore: code quality improvement
  • Loading branch information
SilverD3 authored Jul 19, 2024
1 parent e8ce818 commit eb18e34
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/// <reference types="cypress" />

const DISEASE_TYPE_STARTS_PATH = "/admin/types/diseases";

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

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

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

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

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

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

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

const DISEASE_TYPE_START_PATH = "/admin/types/diseases";

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

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

it("should fail to edit the disease 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 disease type changes", () => {
cy.byId("description").clear().type("Disease type");
cy.dataCy("submit-form").click();
cy.dataCy("dialog-info").contains("has been updated successfully!");
cy.dataCy("approve-dialog").click();
});

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

it("should cancel the cancellation of the disease 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 disease type update?"
);
cy.dataCy("close-dialog").click();
cy.dataCy("dialog-info").should("not.exist");
});

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

const DISEASE_TYPES_START_PATH = "/admin/types/diseases";

describe("Disease types Activity specs", () => {
it("should render the ui", () => {
cy.authenticate(DISEASE_TYPES_START_PATH);
cy.dataCy("sub-activity-title").contains("Manage disease types");
});

it("should present the table with two rows", () => {
cy.dataCy("disease-types-table")
.find("table")
.then((table) => {
expect(table.find("tbody tr").length).equal(2);
});
});

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

it("should delete the first disease type", () => {
cy.dataCy("table-delete-action").first().click();
cy.dataCy("approve-dialog").click();
cy.dataCy("dialog-info").contains("has been deleted successfully!");
cy.dataCy("approve-dialog").last().click();
cy.dataCy("dialog-info").should("not.exist");
cy.dataCy("disease-types-table")
.find("table")
.then((table) => {
expect(table.find("tbody tr").length).equal(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ const DiseaseTypes = () => {
const { t } = useTranslation();
return (
<>
<h3>{t("diseaseTypes.title")}</h3>
<h3 data-cy="sub-activity-title">{t("diseaseTypes.title")}</h3>

<div className="diseaseTypes">
<div className="diseaseTypes" data-cy="disease-types-table">
<DiseaseTypesTable
onEdit={handleEdit}
onDelete={handleDelete}
Expand All @@ -54,6 +54,7 @@ const DiseaseTypes = () => {
type="button"
variant="contained"
color="primary"
dataCy="add-disease-type"
>
{t("diseaseTypes.addDiseaseType")}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,20 @@ const DiseaseTypeForm: FC<IDiseaseTypeFormProps> = ({

<div className="diseaseTypesForm__buttonSet">
<div className="submit_button">
<Button type="submit" variant="contained" disabled={isLoading}>
<Button
dataCy="submit-form"
type="submit"
variant="contained"
disabled={isLoading}
>
{submitButtonLabel}
</Button>
</div>
<div className="reset_button">
<Button
type="reset"
variant="text"
dataCy="cancel-form"
disabled={isLoading}
onClick={() => setOpenResetConfirmation(true)}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { updateDiseaseType } from "../../../../../../../state/types/diseases/act
import { PATHS } from "../../../../../../../consts";
import { getInitialFields } from "../diseaseTypesForm/consts";
import DiseaseTypeForm from "../diseaseTypesForm/DiseaseTypeForm";
import { setTypeMode } from "../../../../../../../state/types/config";
import { setTypeMode, TypeMode } from "../../../../../../../state/types/config";
import "./styles.scss";

export const EditDiseaseType = () => {
Expand All @@ -20,22 +20,29 @@ export const EditDiseaseType = () => {
const update = useSelector<IState, ApiResponse<DiseaseTypeDTO>>(
(state) => state.types.diseases.update
);
const mode = useSelector<IState, TypeMode>(
(state) => state.types.config.mode
);

const handleSubmit = (value: DiseaseTypeDTO) => {
dispatch(updateDiseaseType(value));
};

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

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

return (
<div className="editDiseaseType">
<h3 className="title">{t("diseaseTypes.editDiseaseType")}</h3>
<h3 data-cy="sub-activity-title" className="title">
{t("diseaseTypes.editDiseaseType")}
</h3>
<DiseaseTypeForm
creationMode={false}
onSubmit={handleSubmit}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export const NewDiseaseType = () => {

return (
<div className="newDiseaseType">
<h3 className="title">{t("diseaseTypes.addDiseaseType")}</h3>
<h3 data-cy="sub-activity-title" className="title">
{t("diseaseTypes.addDiseaseType")}
</h3>
<DiseaseTypeForm
creationMode
onSubmit={handleSubmit}
Expand Down

0 comments on commit eb18e34

Please sign in to comment.