Skip to content

Commit

Permalink
Updates to Assessment and P&E Cypress tests (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
afwilcox authored May 1, 2024
1 parent 5d6a163 commit 15ca6b5
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 137 deletions.
43 changes: 30 additions & 13 deletions frontend/cypress/e2e/hwcr-outcome-assessment.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("HWCR Outcome Assessments", () => {
cy.get("#outcome-officer-div").find(".error-message").should("exist");

//validate the date is required
cy.get("#complaint-outcome-date-div").find(".error-message").should("exist");
cy.get("#assessment-checkbox-div").find(".error-message").should("exist");

//validate the toast
cy.get(".Toastify__toast-body").then(($toast) => {
Expand All @@ -53,8 +53,21 @@ describe("HWCR Outcome Assessments", () => {
cy.get(".comp-outcome-report-complaint-assessment").then(function ($assessment) {
if ($assessment.find("#outcome-save-button").length) {
cy.validateComplaint("23-033066", "Coyote");
cy.fillInHWCSection("ASSESSMENT", ["#ASSESSRISK"], "Olivia Benson", "01", "Yes");
cy.validateHWCSection("ASSESSMENT", ["Assessed public safety risk"], "Olivia Benson", "01", "Yes");

let sectionParams = {
section: "ASSESSMENT",
checkboxes: ["#ASSESSRISK"],
officer: "Olivia Benson",
date: "01",
actionRequired: "Yes",
toastText: "Assessment has been saved",
};

cy.fillInHWCSection(sectionParams).then(() => {
sectionParams.checkboxes = ["Assessed public safety risk"];

cy.validateHWCSection(sectionParams);
});
} else {
cy.log("Test was previously run. Skip the Test");
this.skip();
Expand Down Expand Up @@ -102,16 +115,20 @@ describe("HWCR Outcome Assessments", () => {
if ($assessment.find("#assessment-edit-button").length) {
cy.get("#assessment-edit-button").click();

cy.fillInHWCSection("ASSESSMENT", ["#ASSESSHIST"], "Jake Peralta", "01", "No", "No public safety concern");

cy.validateHWCSection(
"ASSESSMENT",
["Assessed public safety risk", "Assessed known conflict history"],
"Jake Peralta",
"01",
"No",
"No public safety concern",
);
let sectionParams = {
section: "ASSESSMENT",
checkboxes: ["#ASSESSHIST"],
officer: "Jake Peralta",
date: "01",
actionRequired: "No",
justification: "No public safety concern",
toastText: "Assessment has been updated",
};

cy.fillInHWCSection(sectionParams).then(() => {
sectionParams.checkboxes = ["Assessed public safety risk", "Assessed known conflict history"];
cy.validateHWCSection(sectionParams);
});
} else {
cy.log("Assessment Not Found, did a previous test fail? Skip the Test");
this.skip();
Expand Down
129 changes: 73 additions & 56 deletions frontend/cypress/e2e/hwcr-outcome-prev-and-educ.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,74 @@ describe("HWCR Outcome Prevention and Education", () => {
cy.kcLogout().kcLogin();
});

it("it can save prevention and education", () => {
it("it requires valid user input", () => {
cy.navigateToDetailsScreen(COMPLAINT_TYPES.HWCR, "23-030330", true);

//This is required to make the tests re-runnable. It's not great because it means it will only run the first time.
//If we ever get the ability to remove an assessment this test suite should be rewritten to remove this conditional
//and to add a test at the end to delete the assessment.
//If we ever get the ability to remove an prevention and education this test suite should be rewritten to remove this conditional
//and to add a test at the end to delete the prevention and education.
cy.get(".comp-hwcr-outcome-report").then(function ($outcome) {
if ($outcome.find("#outcome-report-add-prevention-outcome").length > 0) {
cy.get("#outcome-report-add-prevention-outcome").click();
cy.validateComplaint("23-030330", "Black Bear");
cy.fillInHWCSection("PREV&EDUC", ["#PROVSFTYIN", "#CNTCTBYLAW"], "Olivia Benson", "01");
cy.validateHWCSection(
"PREV&EDUC",
["Provided safety information to the public", "Contacted bylaw to assist with managing attractants"],
"Olivia Benson",
"01",
);
} else {
cy.log("Test was previously run. Skip the Test");
this.skip();
}
});

cy.get(".comp-outcome-report-complaint-prev-and-educ").then(function () {
//click Save Button
cy.get("#outcome-save-prev-and-educ-button").click();

//validate officer is required
cy.get("#prev-educ-outcome-officer-div").find(".error-message").should("exist");

//validate the date is required
cy.get("#prev-educ-checkbox-div").find(".error-message").should("exist");

//validate error message
cy.get(".error-message").then(($error) => {
expect($error).to.contain.text("One or more prevention and education is required");
});

//validate the toast
cy.get(".Toastify__toast-body").then(($toast) => {
expect($toast).to.contain.text("Errors in form");
});
});
});

it("it can edit an existing prevention and education", () => {
it("it can save prevention and education", () => {
cy.navigateToDetailsScreen(COMPLAINT_TYPES.HWCR, "23-030330", true);

cy.validateComplaint("23-030330", "Black Bear");

cy.get(".comp-outcome-report-complaint-prev-and-educ").then(function ($preventionAndEducation) {
if ($preventionAndEducation.find("#prevention-edit-button").length) {
cy.get("#prevention-edit-button").click();
let params = {
section: "PREV&EDUC",
checkboxes: ["#PROVSFTYIN", "#CNTCTBYLAW"],
officer: "Olivia Benson",
date: "01",
toastText: "Prevention and education has been saved",
};

cy.fillInHWCSection("PREV&EDUC", ["#CNTCTBIOVT"], "Jake Peralta", "01");
//This is required to make the tests re-runnable. It's not great because it means it will only run the first time.
//If we ever get the ability to remove an assessment this test suite should be rewritten to remove this conditional
//and to add a test at the end to delete the assessment.
cy.get(".comp-hwcr-outcome-report").then(function ($outcome) {
if ($outcome.find("#outcome-report-add-prevention-outcome").length > 0) {
cy.get("#outcome-report-add-prevention-outcome").click();
cy.validateComplaint("23-030330", "Black Bear");

cy.validateHWCSection(
"PREV&EDUC",
[
cy.fillInHWCSection(params).then(() => {
//expand checkboxes for validating in view state
params.checkboxes = [
"Provided safety information to the public",
"Contacted bylaw to assist with managing attractants",
"Contacted biologist and/or veterinarian",
],
"Jake Peralta",
"01",
);
];

cy.validateHWCSection(params);
});
} else {
cy.log("Prevention and Education Edit Button Not Found, did a previous test fail? Skip the Test");
cy.log("Test was previously run. Skip the Test");
this.skip();
}
});
Expand Down Expand Up @@ -92,41 +113,37 @@ describe("HWCR Outcome Prevention and Education", () => {
});
});

it("it requires valid user input", () => {
it("it can edit an existing prevention and education", () => {
cy.navigateToDetailsScreen(COMPLAINT_TYPES.HWCR, "23-030330", true);

//This is required to make the tests re-runnable. It's not great because it means it will only run the first time.
//If we ever get the ability to remove an prevention and education this test suite should be rewritten to remove this conditional
//and to add a test at the end to delete the prevention and education.
cy.get(".comp-hwcr-outcome-report").then(function ($outcome) {
if ($outcome.find("#outcome-report-add-prevention-outcome").length > 0) {
cy.get("#outcome-report-add-prevention-outcome").click();
cy.validateComplaint("23-030330", "Black Bear");
} else {
cy.log("Test was previously run. Skip the Test");
this.skip();
}
});

cy.get(".comp-outcome-report-complaint-prev-and-educ").then(function () {
//click Save Button
cy.get("#outcome-save-prev-and-educ-button").click();

//validate officer is required
cy.get("#prev-educ-outcome-officer-div").find(".error-message").should("exist");
cy.validateComplaint("23-030330", "Black Bear");

//validate the date is required
cy.get("#prev-educ-outcome-date-div").find(".error-message").should("exist");
cy.get(".comp-outcome-report-complaint-prev-and-educ").then(function ($preventionAndEducation) {
if ($preventionAndEducation.find("#prevention-edit-button").length) {
cy.get("#prevention-edit-button").click();

//validate error message
cy.get(".error-message").then(($error) => {
expect($error).to.contain.text("One or more prevention and education is required");
});
let params = {
section: "PREV&EDUC",
checkboxes: ["#CNTCTBIOVT"],
officer: "Jake Peralta",
date: "01",
toastText: "Prevention and education has been updated",
};

cy.fillInHWCSection(params).then(() => {
//expand checkboxes for validating in view state
params.checkboxes = [
"Provided safety information to the public",
"Contacted bylaw to assist with managing attractants",
"Contacted biologist and/or veterinarian",
];

//validate the toast
cy.get(".Toastify__toast-body").then(($toast) => {
expect($toast).to.contain.text("Errors in form");
});
cy.validateHWCSection(params);
});
} else {
cy.log("Prevention and Education Edit Button Not Found, did a previous test fail? Skip the Test");
this.skip();
}
});
});
});
86 changes: 34 additions & 52 deletions frontend/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,76 +323,56 @@ Cypress.Commands.add("validateComplaint", (complaintIdentifier: string, species:
});
});

Cypress.Commands.add(
"fillInHWCSection",
(
section: string,
checkboxes: string[],
officer: string,
date: string,
actionRequired?: string,
justification?: string,
) => {
let officerId = "";
let datePickerId = "";
let saveButtonId = "";

if (section === "ASSESSMENT") {
officerId = "outcome-officer";
datePickerId = "complaint-outcome-date";
saveButtonId = "#outcome-save-button";
} else {
officerId = "prev-educ-outcome-officer";
datePickerId = "prev-educ-outcome-date";
saveButtonId = "#outcome-save-prev-and-educ-button";
}
Cypress.Commands.add("fillInHWCSection", ({ section, checkboxes, officer, date, actionRequired, justification }) => {
let officerId = "";
let datePickerId = "";
let saveButtonId = "";

if (section === "ASSESSMENT") {
officerId = "outcome-officer";
datePickerId = "complaint-outcome-date";
saveButtonId = "#outcome-save-button";
} else {
officerId = "prev-educ-outcome-officer";
datePickerId = "prev-educ-outcome-date";
saveButtonId = "#outcome-save-prev-and-educ-button";
}

Cypress._.times(checkboxes.length, (index) => {
cy.get(checkboxes[index]).check();
});
Cypress._.times(checkboxes.length, (index) => {
cy.get(checkboxes[index]).check();
});

if (actionRequired) {
cy.selectItemById("action-required", actionRequired);
}
if (actionRequired) {
cy.selectItemById("action-required", actionRequired);
}

if (justification) {
cy.selectItemById("justification", justification);
}
if (justification) {
cy.selectItemById("justification", justification);
}

cy.selectItemById(officerId, officer);
cy.selectItemById(officerId, officer);

cy.enterDateTimeInDatePicker(datePickerId, date);
cy.enterDateTimeInDatePicker(datePickerId, date);

//click Save Button
cy.get(saveButtonId).click();
},
);
//click Save Button
cy.get(saveButtonId).click();
});

Cypress.Commands.add(
"validateHWCSection",
(
section: string,
checkboxes: string[],
officer: string,
date: string,
actionRequired?: string,
justification?: string,
) => {
({ section, checkboxes, officer, date, actionRequired, justification, toastText }) => {
let checkboxDiv = "";
let officerDiv = "";
let dateDiv = "";
let toastText = "";

if (section === "ASSESSMENT") {
checkboxDiv = "#assessment-checkbox-div";
officerDiv = "#outcome-officer-div";
dateDiv = "#complaint-outcome-date-div";
toastText = "Assessment has been updated";
} else {
checkboxDiv = "#prev-educ-checkbox-div";
officerDiv = "#prev-educ-outcome-officer-div";
dateDiv = "#prev-educ-outcome-date-div";
toastText = "Prevention and education has been updated";
}

//Verify Fields exist
Expand Down Expand Up @@ -423,9 +403,11 @@ Cypress.Commands.add(
});

//validate the toast
cy.get(".Toastify__toast-body").then(($toast) => {
expect($toast).to.contain.text(toastText);
});
if (toastText) {
cy.get(".Toastify__toast-body").then(($toast) => {
expect($toast).to.contain.text(toastText);
});
}
},
);

Expand Down
28 changes: 12 additions & 16 deletions frontend/cypress/support/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
/// <reference types="cypress" />

declare namespace Cypress {
export interface HwcSection {
section: string;
checkboxes: string[];
officer: string;
date: string;
actionRequired?: string;
justification?: string;
toastText?: string;
}

interface Chainable {
kcLogin(): Chainable<Element>;
kcLogout(): Chainable<any>;
Expand All @@ -17,21 +27,7 @@ declare namespace Cypress {
enterDateTimeInDatePicker(datePickerId: string, day: string, hour?: string, minute?: string): Chainable<any>;
navigateToTab(complaintTab: string, removeFilters: boolean): Chainable<void>;
validateComplaint(complaintIdentifier: string, species: string): Chainable<void>;
fillInHWCSection(
section: string,
checkboxes: string[],
officer: string,
date: string,
actionRequired?: string,
justification?: string,
): Chainable<void>;
validateHWCSection(
section: string,
checkboxes: string[],
officer: string,
date: string,
actionRequired?: string,
justification?: string,
): Chainable<void>;
fillInHWCSection(section: HwcSection): Chainable<void>;
validateHWCSection(section: HwcSection): Chainable<void>;
}
}

0 comments on commit 15ca6b5

Please sign in to comment.