Skip to content

Commit

Permalink
chore:OH2-329 | Tests / Add cypress e2e tests to cover admin/vaccines (
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverD3 authored and gasp committed Jul 24, 2024
1 parent 1e6250e commit 58795d9
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/// <reference types="cypress" />

const VACCINE_STARTS_PATH = "/admin/vaccines";

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

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

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

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

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

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

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

const VACCINE_START_PATH = "/admin/vaccines";

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

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

it("should fail to edit the vaccine", () => {
cy.byId("code").should("be.disabled");
cy.byId("vaccineType").clear().blur();
cy.dataCy("submit-form").click();
cy.dataCy("dialog-info").should("not.exist");
});

it("should successfully save vaccine changes", () => {
cy.byId("vaccineType").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 vaccine update", () => {
cy.dataCy("activity-title").contains("Vaccines");
});

it("should cancel the cancellation of the vaccine creation", () => {
cy.dataCy("table-edit-action").first().click();
cy.dataCy("cancel-form").click();
cy.dataCy("dialog-info").contains(
"Are you sure to cancel the vaccine update"
);
cy.dataCy("close-dialog").click();
cy.dataCy("dialog-info").should("not.exist");
});

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

const VACCINES_START_PATH = "/admin/vaccines";

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

it("should present the table with eight rows", () => {
cy.dataCy("vaccines-table")
.find("table")
.then(($table) => {
const rows = $table.find("tbody tr");
expect(rows.length).equal(8);
});
});
});
35 changes: 19 additions & 16 deletions src/components/accessories/admin/vaccines/Vaccines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,24 @@ export const Vaccines = () => {
};

return (
<VaccinesTable
onEdit={handleEdit}
onDelete={handleDelete}
headerActions={
<Button
onClick={() => {
navigate(PATHS.admin_vaccines_new);
}}
type="button"
variant="contained"
color="primary"
>
{t("vaccine.addVaccine")}
</Button>
}
/>
<div data-cy="vaccines-table">
<VaccinesTable
onEdit={handleEdit}
onDelete={handleDelete}
headerActions={
<Button
onClick={() => {
navigate(PATHS.admin_vaccines_new);
}}
type="button"
variant="contained"
color="primary"
dataCy="add-new-vaccine"
>
{t("vaccine.addVaccine")}
</Button>
}
/>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,20 @@ const VaccineForm: FC<IVaccineFormProps> = ({

<div className="vaccineForm__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"
variant="text"
dataCy="cancel-form"
disabled={isLoading}
onClick={() => setOpenResetConfirmation(true)}
>
Expand Down

0 comments on commit 58795d9

Please sign in to comment.