Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OH2-329 | Tests / Add cypress e2e tests to cover admin/vaccines #626

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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