From e08230a955647c7e132d37457096b49c1e3087cb Mon Sep 17 00:00:00 2001 From: SilverD3 Date: Mon, 4 Nov 2024 15:41:04 +0100 Subject: [PATCH] chore:add e2e tests --- .../ages_activities/edit_ages_activity.cy.ts | 50 +++++++++++++++++++ .../manage_ages_activity.cy.ts | 19 +++++++ .../agetypes/editAgeTypes/EditAgeTypes.tsx | 2 +- src/mockServer/fixtures/ageTypeDTO.js | 20 ++++---- src/mockServer/routes/ageTypes.js | 10 ++++ src/resources/i18n/en.json | 1 - 6 files changed, 90 insertions(+), 12 deletions(-) create mode 100644 cypress/integrations/admin_activities/types_activities/ages_activities/edit_ages_activity.cy.ts create mode 100644 cypress/integrations/admin_activities/types_activities/ages_activities/manage_ages_activity.cy.ts diff --git a/cypress/integrations/admin_activities/types_activities/ages_activities/edit_ages_activity.cy.ts b/cypress/integrations/admin_activities/types_activities/ages_activities/edit_ages_activity.cy.ts new file mode 100644 index 000000000..95506cffc --- /dev/null +++ b/cypress/integrations/admin_activities/types_activities/ages_activities/edit_ages_activity.cy.ts @@ -0,0 +1,50 @@ +/// + +const AGE_TYPE_START_PATH = "/admin/types/ages"; + +describe("Admission types Edit Activity specs", () => { + it("should render the ui", () => { + cy.authenticate(AGE_TYPE_START_PATH); + cy.dataCy("sub-activity-title").contains("Manage age types"); + }); + + it("should show age types edit form", () => { + cy.dataCy("edit-age-types").click(); + cy.dataCy("sub-activity-title").contains("Edit age types"); + }); + + it("should fail to edit the age type", () => { + cy.byId("ageTypes\\[0\\]\\.to").type("1"); + cy.dataCy("submit-form").click(); + cy.dataCy("dialog-info").should("not.exist"); + }); + + it("should successfully save age types changes", () => { + cy.byId("ageTypes\\[0\\]\\.to").clear().type("0"); + cy.byId("ageTypes\\[5\\]\\.to").clear().type("104"); + cy.dataCy("submit-form").click(); + cy.dataCy("dialog-info").contains("have been updated successfully!"); + cy.dataCy("approve-dialog").click(); + }); + + it("should redirect after age types update", () => { + cy.dataCy("sub-activity-title").contains("Manage age types"); + }); + + it("should cancel the cancellation of the age types update", () => { + cy.dataCy("edit-age-types").click(); + cy.dataCy("cancel-form").click(); + cy.dataCy("dialog-info").contains( + "Are you sure to cancel the age types update?" + ); + cy.dataCy("close-dialog").click(); + cy.dataCy("dialog-info").should("not.exist"); + }); + + it("should cancel the age types 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 age types"); + }); +}); diff --git a/cypress/integrations/admin_activities/types_activities/ages_activities/manage_ages_activity.cy.ts b/cypress/integrations/admin_activities/types_activities/ages_activities/manage_ages_activity.cy.ts new file mode 100644 index 000000000..034172dbd --- /dev/null +++ b/cypress/integrations/admin_activities/types_activities/ages_activities/manage_ages_activity.cy.ts @@ -0,0 +1,19 @@ +/// + +const AGE_TYPES_START_PATH = "/admin/types/ages"; + +describe("Age types Activity specs", () => { + it("should render the ui", () => { + cy.authenticate(AGE_TYPES_START_PATH); + cy.dataCy("sub-activity-title").contains("Manage age types"); + }); + + it("should present the table with 6 rows", () => { + cy.dataCy("age-types-table") + .find("table") + .then(($table) => { + const rows = $table.find("tbody tr"); + expect(rows.length).equal(6); + }); + }); +}); diff --git a/src/components/accessories/admin/types/components/agetypes/editAgeTypes/EditAgeTypes.tsx b/src/components/accessories/admin/types/components/agetypes/editAgeTypes/EditAgeTypes.tsx index f6dc9bb12..d0ffa4953 100644 --- a/src/components/accessories/admin/types/components/agetypes/editAgeTypes/EditAgeTypes.tsx +++ b/src/components/accessories/admin/types/components/agetypes/editAgeTypes/EditAgeTypes.tsx @@ -42,7 +42,7 @@ export const EditAgeTypes = () => { return (

- {t("ageTypes.editAgeType")} + {t("ageTypes.editAgeTypes")}

{ageTypesState.isLoading && } {ageTypesState.hasFailed && ( diff --git a/src/mockServer/fixtures/ageTypeDTO.js b/src/mockServer/fixtures/ageTypeDTO.js index 3556d4f4e..2f48ec5b3 100644 --- a/src/mockServer/fixtures/ageTypeDTO.js +++ b/src/mockServer/fixtures/ageTypeDTO.js @@ -3,36 +3,36 @@ export const ageTypeDTO = [ code: "d0", description: "New Born", from: 0, - to: 1 + to: 0 }, { code: "d1", description: "Early Child Hood", - from: 6, - to: 17 + from: 1, + to: 5 }, { code: "d2", description: "Late Child Hood", - from: 18, - to: 200 + from: 6, + to: 15 }, { code: "d3", description: "Adolescent", - from: 18, - to: 200 + from: 16, + to: 50 }, { code: "d4", description: "Adult", - from: 18, - to: 200 + from: 51, + to: 80 }, { code: "d5", description: "Elderly", - from: 18, + from: 81, to: 200 }, ]; diff --git a/src/mockServer/routes/ageTypes.js b/src/mockServer/routes/ageTypes.js index 586108c72..30bcb9f63 100644 --- a/src/mockServer/routes/ageTypes.js +++ b/src/mockServer/routes/ageTypes.js @@ -5,5 +5,15 @@ export const ageTypeRoutes = (server) => { server.get("/").intercept((req, res) => { res.status(200).json(ageTypeDTO); }); + server.put("/").intercept((req, res) => { + const body = req.jsonBody(); + switch (body[0].to) { + case 1: + res.status(400).json({ message: "Fail to update age types" }); + break; + default: + res.status(200).json(body); + } + }); }); }; diff --git a/src/resources/i18n/en.json b/src/resources/i18n/en.json index 34b8df3fd..0d3c460c5 100644 --- a/src/resources/i18n/en.json +++ b/src/resources/i18n/en.json @@ -1065,7 +1065,6 @@ "to": "To", "title": "Manage age types", "editAgeTypes": "Edit age types", - "editAgeType": "Edit age type", "updateAgeType": "Save changes", "created": "Age type created", "updated": "Age types updated",