Skip to content

Commit

Permalink
OH2-331 |Tests / Add cypress e2e tests to cover admission types (admi…
Browse files Browse the repository at this point in the history
…n/types/admissions) (informatici#627)

* tests:Tests | Add cypress e2e tests to cover admission types (admin/types/admissions)

* fix:check mode before setting it
  • Loading branch information
SilverD3 authored and gasp committed Jul 24, 2024
1 parent 84deca7 commit 1e6250e
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/// <reference types="cypress" />

const ADMISSION_TYPE_STARTS_PATH = "/admin/types/admissions";

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

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

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

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

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

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

it("should cancel the admission 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 admission types");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/// <reference types="cypress" />

const ADMISSION_TYPE_START_PATH = "/admin/types/admissions";

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

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

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

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

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

it("should cancel the admission 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 admission types");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// <reference types="cypress" />

const ADMISSION_TYPES_START_PATH = "/admin/types/admissions";

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

it("should present the table with three rows", () => {
cy.dataCy("admission-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
Expand Up @@ -40,9 +40,9 @@ const AdmissionTypes = () => {
const { t } = useTranslation();
return (
<>
<h3>{t("admissionTypes.title")}</h3>
<h3 data-cy="sub-activity-title">{t("admissionTypes.title")}</h3>

<div className="admissionTypes">
<div className="admissionTypes" data-cy="admission-types-table">
<AdmissionTypesTable
onEdit={handleEdit}
onDelete={handleDelete}
Expand All @@ -54,6 +54,7 @@ const AdmissionTypes = () => {
type="button"
variant="contained"
color="primary"
dataCy="add-admission-type"
>
{t("admissionTypes.addAdmissionType")}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,20 @@ const AdmissionTypeForm: FC<IAdmissionTypeFormProps> = ({

<div className="admissionTypesForm__buttonSet">
<div className="submit_button">
<Button type="submit" variant="contained" disabled={isLoading}>
<Button
type="submit"
dataCy="submit-form"
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 { updateAdmissionType } from "../../../../../../../state/types/admissions
import { PATHS } from "../../../../../../../consts";
import { getInitialFields } from "../admissionTypesForm/consts";
import AdmissionTypeForm from "../admissionTypesForm/AdmissionTypeForm";
import { setTypeMode } from "../../../../../../../state/types/config";
import { setTypeMode, TypeMode } from "../../../../../../../state/types/config";
import "./styles.scss";

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

const handleSubmit = (value: AdmissionTypeDTO) => {
dispatch(updateAdmissionType(value));
};

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

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

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

return (
<div className="newAdmissionType">
<h3 className="title">{t("admissionTypes.addAdmissionType")}</h3>
<h3 data-cy="sub-activity-title" className="title">
{t("admissionTypes.addAdmissionType")}
</h3>
<AdmissionTypeForm
creationMode
onSubmit={handleSubmit}
Expand Down

0 comments on commit 1e6250e

Please sign in to comment.