From 1e6250e224792db2e8fea1b5aaa0e8dcfe7b76d7 Mon Sep 17 00:00:00 2001 From: Silevester Dongmo <58907550+SilverD3@users.noreply.github.com> Date: Wed, 17 Jul 2024 15:25:56 +0100 Subject: [PATCH] OH2-331 |Tests / Add cypress e2e tests to cover admission types (admin/types/admissions) (#627) * tests:Tests | Add cypress e2e tests to cover admission types (admin/types/admissions) * fix:check mode before setting it --- .../add_admission_activity.cy.ts | 52 +++++++++++++++++++ .../edit_admission_activity.cy.ts | 50 ++++++++++++++++++ .../manage_admissions_activity.cy.ts | 19 +++++++ .../components/admissions/AdmissionTypes.tsx | 5 +- .../admissionTypesForm/AdmissionTypeForm.tsx | 8 ++- .../editAdmissionType/EditAdmissionType.tsx | 15 ++++-- .../newAdmissionType/NewAdmissionType.tsx | 4 +- 7 files changed, 145 insertions(+), 8 deletions(-) create mode 100644 cypress/integrations/admin_activities/types_activities/admissions_activities/add_admission_activity.cy.ts create mode 100644 cypress/integrations/admin_activities/types_activities/admissions_activities/edit_admission_activity.cy.ts create mode 100644 cypress/integrations/admin_activities/types_activities/admissions_activities/manage_admissions_activity.cy.ts diff --git a/cypress/integrations/admin_activities/types_activities/admissions_activities/add_admission_activity.cy.ts b/cypress/integrations/admin_activities/types_activities/admissions_activities/add_admission_activity.cy.ts new file mode 100644 index 000000000..3bf707bb4 --- /dev/null +++ b/cypress/integrations/admin_activities/types_activities/admissions_activities/add_admission_activity.cy.ts @@ -0,0 +1,52 @@ +/// + +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"); + }); +}); diff --git a/cypress/integrations/admin_activities/types_activities/admissions_activities/edit_admission_activity.cy.ts b/cypress/integrations/admin_activities/types_activities/admissions_activities/edit_admission_activity.cy.ts new file mode 100644 index 000000000..2eb69a1e6 --- /dev/null +++ b/cypress/integrations/admin_activities/types_activities/admissions_activities/edit_admission_activity.cy.ts @@ -0,0 +1,50 @@ +/// + +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"); + }); +}); diff --git a/cypress/integrations/admin_activities/types_activities/admissions_activities/manage_admissions_activity.cy.ts b/cypress/integrations/admin_activities/types_activities/admissions_activities/manage_admissions_activity.cy.ts new file mode 100644 index 000000000..8ca6f8136 --- /dev/null +++ b/cypress/integrations/admin_activities/types_activities/admissions_activities/manage_admissions_activity.cy.ts @@ -0,0 +1,19 @@ +/// + +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); + }); + }); +}); diff --git a/src/components/accessories/admin/types/components/admissions/AdmissionTypes.tsx b/src/components/accessories/admin/types/components/admissions/AdmissionTypes.tsx index 553e79bde..461c5654b 100644 --- a/src/components/accessories/admin/types/components/admissions/AdmissionTypes.tsx +++ b/src/components/accessories/admin/types/components/admissions/AdmissionTypes.tsx @@ -40,9 +40,9 @@ const AdmissionTypes = () => { const { t } = useTranslation(); return ( <> -

{t("admissionTypes.title")}

+

{t("admissionTypes.title")}

-
+
{ type="button" variant="contained" color="primary" + dataCy="add-admission-type" > {t("admissionTypes.addAdmissionType")} diff --git a/src/components/accessories/admin/types/components/admissions/admissionTypesForm/AdmissionTypeForm.tsx b/src/components/accessories/admin/types/components/admissions/admissionTypesForm/AdmissionTypeForm.tsx index 4689d858d..af2481269 100644 --- a/src/components/accessories/admin/types/components/admissions/admissionTypesForm/AdmissionTypeForm.tsx +++ b/src/components/accessories/admin/types/components/admissions/admissionTypesForm/AdmissionTypeForm.tsx @@ -140,7 +140,12 @@ const AdmissionTypeForm: FC = ({
-
@@ -148,6 +153,7 @@ const AdmissionTypeForm: FC = ({