Skip to content

Commit

Permalink
chore:add e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverD3 committed Nov 4, 2024
1 parent 5e270b9 commit e08230a
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/// <reference types="cypress" />

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

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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const EditAgeTypes = () => {
return (
<div className="editAgeTypes">
<h3 data-cy="sub-activity-title" className="title">
{t("ageTypes.editAgeType")}
{t("ageTypes.editAgeTypes")}
</h3>
{ageTypesState.isLoading && <CircularProgress className="loader" />}
{ageTypesState.hasFailed && (
Expand Down
20 changes: 10 additions & 10 deletions src/mockServer/fixtures/ageTypeDTO.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
];
10 changes: 10 additions & 0 deletions src/mockServer/routes/ageTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
};
1 change: 0 additions & 1 deletion src/resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit e08230a

Please sign in to comment.