Skip to content

Commit

Permalink
OH2-326 | Tests | Add cypress e2e tests to cover admin/diseases (#622)
Browse files Browse the repository at this point in the history
* tests:OH2-326 | Tests | Add cypress e2e tests to cover admin/diseases

* chore:Improve cypress indexing
  • Loading branch information
SilverD3 authored Jun 27, 2024
1 parent 5f2bf5b commit 189a6d1
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/// <reference types="cypress" />

const DISEASE_STARTS_PATH = "/admin/diseases";

describe("Add Disease Activity specs", () => {
it("should render the ui", () => {
cy.authenticate(DISEASE_STARTS_PATH);
cy.dataCy("activity-title").contains("Diseases");
});

it("should show disease creation form", () => {
cy.dataCy("add-new-disease").click();
cy.dataCy("activity-title").contains("Add Disease");
});

it("should fail to create a new disease", () => {
cy.byId("code").type("FAIL");
cy.byId("diseaseType").click();
cy.get('.MuiAutocomplete-popper li[data-option-index="0"]').click();
cy.byId("description").type("Children disease");
cy.get('input[name="opdInclude"]').check();
cy.get('input[name="ipdInInclude"]').check();
cy.get('input[name="ipdInInclude"]').uncheck();
cy.dataCy("submit-form").click();
cy.dataCy("info-box").contains("Fail");
});

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

it("should redirect after disease creation", () => {
cy.dataCy("activity-title").contains("Diseases");
});

it("should cancel the cancellation of the disease creation", () => {
cy.dataCy("add-new-disease").click();
cy.dataCy("cancel-form").click();
cy.dataCy("dialog-info").contains(
"Are you sure to Reset the Form? All the unsaved data will be lost."
);
cy.dataCy("close-dialog").click();
cy.dataCy("dialog-info").should("not.exist");
});

it("should cancel the disease creation", () => {
cy.dataCy("cancel-form").click();
cy.dataCy("approve-dialog").click();
cy.dataCy("dialog-info").should("not.exist");
cy.dataCy("activity-title").contains("Diseases");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/// <reference types="cypress" />

const DISEASE_START_PATH = "/admin/diseases";

describe("Diseases Edit Activity specs", () => {
it("should render the ui", () => {
cy.authenticate(DISEASE_START_PATH);
cy.dataCy("activity-title").contains("Diseases");
});

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

it("should fail to edit the disease", () => {
cy.byId("code").should("be.disabled");
cy.get('input[name="opdInclude"]').uncheck();
cy.get('input[name="ipdInInclude"]').check();
cy.byId("diseaseType").clear();
cy.dataCy("submit-form").click();
cy.dataCy("dialog-info").should("not.exist");
});

it("should successfully save disease changes", () => {
cy.byId("diseaseType").click();
cy.get('.MuiAutocomplete-popper li[data-option-index="0"]').click();
cy.dataCy("submit-form").click();
cy.dataCy("dialog-info").contains("has been updated successfully!");
cy.dataCy("approve-dialog").click();
});

it("should redirect after disease update", () => {
cy.dataCy("activity-title").contains("Diseases");
});

it("should cancel the cancellation of the disease creation", () => {
cy.dataCy("table-edit-action").first().click();
cy.dataCy("cancel-form").click();
cy.dataCy("dialog-info").contains(
"Are you sure to Reset the Form? All the unsaved data will be lost."
);
cy.dataCy("close-dialog").click();
cy.dataCy("dialog-info").should("not.exist");
});

it("should cancel the disease update", () => {
cy.dataCy("cancel-form").click();
cy.dataCy("approve-dialog").click();
cy.dataCy("dialog-info").should("not.exist");
cy.dataCy("activity-title").contains("Diseases");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// <reference types="cypress" />

const DISEASES_START_PATH = "/admin/diseases";

describe("Diseases Activity specs", () => {
it("should render the ui", () => {
cy.authenticate(DISEASES_START_PATH);
cy.dataCy("activity-title").contains("Diseases");
});

it("should present the table with three rows", () => {
cy.dataCy("diseases-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 @@ -2,7 +2,7 @@

const WARD_START_PATH = "/admin/wards";

describe("Wards Activity specs", () => {
describe("Add Ward Activity specs", () => {
it("should render the ui", () => {
cy.authenticate(WARD_START_PATH);
cy.dataCy("activity-title").contains("Wards");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const WARD_STARTS_PATH = "/admin/wards";

describe("Wards Activity specs", () => {
describe("Edit Ward Activity specs", () => {
it("should render the ui", () => {
cy.authenticate(WARD_STARTS_PATH);
cy.dataCy("activity-title").contains("Wards");
Expand Down
3 changes: 2 additions & 1 deletion src/components/accessories/admin/diseases/Diseases.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ export const Diseases = () => {
};

return (
<div className={classes.diseases}>
<div className={classes.diseases} data-cy="diseases-table">
<DiseaseTable
onEdit={handleEdit}
headerActions={
<Button
onClick={() => {
navigate(PATHS.admin_diseases_new);
}}
dataCy="add-new-disease"
type="button"
variant="contained"
color="primary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,19 @@ const DiseaseForm: FC<IDiseaseProps> = ({

<div className="diseaseForm__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"
dataCy="cancel-form"
variant="text"
disabled={isLoading}
onClick={() => setOpenResetConfirmation(true)}
Expand Down
8 changes: 8 additions & 0 deletions src/components/accessories/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const Table: FunctionComponent<IProps> = ({
case "edit":
return (
<IconButton
data-cy="table-edit-action"
title="Edit"
size="small"
onClick={() => onEdit && onEdit(row)}
Expand All @@ -115,6 +116,7 @@ const Table: FunctionComponent<IProps> = ({
case "delete":
return (
<IconButton
data-cy="table-delete-action"
size="small"
title="Delete"
onClick={() => {
Expand All @@ -128,6 +130,7 @@ const Table: FunctionComponent<IProps> = ({
case "print":
return (
<IconButton
data-cy="table-print-action"
size="small"
title="Print"
onClick={() => onPrint && onPrint(row)}
Expand All @@ -139,6 +142,7 @@ const Table: FunctionComponent<IProps> = ({
case "view":
return (
<IconButton
data-cy="table-view-action"
size="small"
title="View details"
onClick={() => onView && onView(row)}
Expand All @@ -149,6 +153,7 @@ const Table: FunctionComponent<IProps> = ({
case "pay":
return (
<IconButton
data-cy="table-pay-action"
size="small"
title="Add a payment"
onClick={() => onPay && onPay(row)}
Expand All @@ -160,6 +165,7 @@ const Table: FunctionComponent<IProps> = ({
case "close":
return (
<IconButton
data-cy="table-close-action"
size="small"
title="Close the bill"
onClick={() => onClose && onClose(row)}
Expand All @@ -171,6 +177,7 @@ const Table: FunctionComponent<IProps> = ({
case "cancel":
return (
<IconButton
data-cy="table-cancel-action"
size="small"
title="Cancel"
onClick={() => {
Expand All @@ -184,6 +191,7 @@ const Table: FunctionComponent<IProps> = ({
case "add":
return (
<IconButton
data-cy="table-add-action"
size="small"
title={addTitle ?? "Add"}
onClick={() => onAdd && onAdd(row)}
Expand Down

0 comments on commit 189a6d1

Please sign in to comment.