Skip to content

Commit

Permalink
tests:OH2-356 | Tests / Add cypress e2e tests to cover exam types (ad…
Browse files Browse the repository at this point in the history
…min/types/exams) (#631)
  • Loading branch information
SilverD3 authored Jul 18, 2024
1 parent fccc1c6 commit 6585a2d
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/// <reference types="cypress" />

const EXAM_TYPE_STARTS_PATH = "/admin/types/exams";

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

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

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

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

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

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

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

const EXAM_TYPE_START_PATH = "/admin/types/exams";

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

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

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

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

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

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

const EXAM_TYPES_START_PATH = "/admin/types/exams";

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

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

it("should cancel the deletion of the exam 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 exam 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("exam-types-table")
.find("table")
.then(($table) => {
const rows = $table.find("tbody tr");
expect(rows.length).equal(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ const ExamTypes = () => {
const { t } = useTranslation();
return (
<>
<h3>{t("examTypes.title")}</h3>
<h3 data-cy="sub-activity-title">{t("examTypes.title")}</h3>

<div className="examTypes">
<div className="examTypes" data-cy="exam-types-table">
<ExamTypesTable
onEdit={handleEdit}
onDelete={handleDelete}
Expand All @@ -54,6 +54,7 @@ const ExamTypes = () => {
type="button"
variant="contained"
color="primary"
dataCy="add-exam-type"
>
{t("examTypes.addExamType")}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export const EditExamType = () => {

return (
<div className="editExamType">
<h3 className="title">{t("examTypes.editExamType")}</h3>
<h3 data-cy="sub-activity-title" className="title">
{t("examTypes.editExamType")}
</h3>
<ExamTypeForm
creationMode={false}
onSubmit={handleSubmit}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,20 @@ const ExamTypeForm: FC<IExamTypeFormProps> = ({

<div className="examTypesForm__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 @@ -27,7 +27,9 @@ export const NewExamType = () => {

return (
<div className="newExamType">
<h3 className="title">{t("examTypes.addExamType")}</h3>
<h3 data-cy="sub-activity-title" className="title">
{t("examTypes.addExamType")}
</h3>
<ExamTypeForm
creationMode
onSubmit={handleSubmit}
Expand Down
2 changes: 1 addition & 1 deletion src/resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@
"deleted": "Deleted",
"deleteSuccess": "The exam type has been deleted successfully!",
"saveExamTypes": "Save",
"editVaccineType": "Edit exam type",
"editExamType": "Edit exam type",
"updateExamType": "Save changes",
"created": "Exam type created",
"createSuccess": "The exam type has been created successfully!",
Expand Down

0 comments on commit 6585a2d

Please sign in to comment.