Skip to content

Commit

Permalink
test:OH2-324 | Tests | Add cypress e2e tests to cover admin/wards (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverD3 authored Jun 21, 2024
1 parent fe0af22 commit 5f2bf5b
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/// <reference types="cypress" />

const WARD_START_PATH = "/admin/wards";

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

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

it("should fail to create a new ward", () => {
cy.byId("code").type("FAIL");
cy.byId("description").type("Children ward");
cy.byId("email").type("[email protected]");
cy.byId("telephone").type("698123234");
cy.get('input[name="opd"]').check();
cy.get('input[name="pharmacy"]').check();
cy.get('input[name="pharmacy"]').uncheck();
cy.dataCy("submit-form").click();
cy.dataCy("info-box").contains("Fail");
});

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

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

it("should cancel the cancellation of the ward creation", () => {
cy.dataCy("add-new-ward").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.be.visible");
});

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

const WARD_STARTS_PATH = "/admin/wards";

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

it("should show ward creation form", () => {
cy.get('button[title="Edit"]').first().click();
cy.dataCy("activity-title").contains("Edit Ward");
});

it("should fail to edit the ward", () => {
cy.byId("code").should("be.disabled");
cy.get('input[name="opd"]').uncheck();
cy.get('input[name="pharmacy"]').check();
cy.byId("telephone").type("+237698123234");
cy.dataCy("submit-form").click();
cy.dataCy("dialog-info").should("not.exist");
});

it("should successfully save ward changes", () => {
cy.byId("telephone").clear().type("623123234");
cy.dataCy("submit-form").click();
cy.dataCy("dialog-info").contains("has been updated successfully!");
cy.dataCy("approve-dialog").click();
});

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

it("should cancel the cancellation of the ward creation", () => {
cy.get('button[title="Edit"]').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.be.visible");
});

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

const WARDS_START_PATH = "/admin/wards";

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

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

it("should display the deletion dialog", () => {
cy.get('button[title="Delete"]').first().click();
cy.dataCy("dialog-info").should(
"contain",
"Are you sure to delete item with code"
);
});

it("should cancel the ward deletion", () => {
cy.dataCy("close-dialog").click();
cy.dataCy("dialog-info").should("not.be.visible");
cy.dataCy("wards-table")
.find("table")
.then(($table) => {
const rows = $table.find("tbody tr");
expect(rows.length).equal(8);
});
});

it("should delete the ward", () => {
cy.get('button[title="Delete"]').first().click();
cy.dataCy("approve-dialog").click();
cy.dataCy("dialog-info").should("not.be.visible");
cy.dataCy("approve-dialog").last().click();
});
});
5 changes: 4 additions & 1 deletion cypress/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ const plugin: Cypress.PluginConfig = (on, config) => {
// `config` is the resolved Cypress config

on("before:browser:launch", (browser, launchOptions) => {
if (browser.name === "chrome") {
if (browser.name === "chrome" || browser.name === "firefox") {
launchOptions.args.push("--lang=en");
return launchOptions;
} else {
launchOptions.env.LANG = "en_US";
return launchOptions;
}
});
};
Expand Down
3 changes: 2 additions & 1 deletion src/components/accessories/admin/wards/Wards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const Wards = () => {
};

return (
<div className={classes.wards}>
<div className={classes.wards} data-cy="wards-table">
<WardTable
onEdit={handleEdit}
onDelete={handleDelete}
Expand All @@ -47,6 +47,7 @@ export const Wards = () => {
type="button"
variant="contained"
color="primary"
dataCy="add-new-ward"
>
{t("ward.addWard")}
</Button>
Expand Down
10 changes: 8 additions & 2 deletions src/components/accessories/admin/wards/wardForm/WardForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const WardForm: FC<IWardProps> = ({
},
});

const { setFieldValue, resetForm } = formik;
const { setFieldValue } = formik;

const isValid = (fieldName: string): boolean => {
return has(formik.touched, fieldName) && has(formik.errors, fieldName);
Expand Down Expand Up @@ -279,12 +279,18 @@ const WardForm: FC<IWardProps> = ({

<div className="wardForm__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
dataCy="cancel-form"
type="reset"
variant="text"
disabled={isLoading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const ConfirmationDialog: FunctionComponent<IProps> = ({
<div className="dialog__buttonSet" data-cy="dialog-button-set">
<div data-cy="dialog-return-button" className="return_button">
<Button
dataCy="approve-dialog"
type="submit"
variant="contained"
onClick={handlePrimaryButtonClick}
Expand All @@ -43,6 +44,7 @@ const ConfirmationDialog: FunctionComponent<IProps> = ({
{secondaryButtonLabel ? (
<div className="reset_button">
<Button
dataCy="close-dialog"
type="reset"
variant="text"
onClick={handleSecondaryButtonClick}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const AdminActivityContent = ({ title, children }: IOwnProps) => {
return (
<div className={classes.content}>
<div className={classes.header}>
<h2>{title}</h2>
<h2 data-cy="activity-title">{title}</h2>
</div>
{children}
</div>
Expand Down

0 comments on commit 5f2bf5b

Please sign in to comment.