Skip to content

Commit

Permalink
chore: CE-591 Cypress Tests for Outcome Report (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
afwilcox authored Apr 15, 2024
1 parent a05f03b commit dafb3d8
Show file tree
Hide file tree
Showing 11 changed files with 619 additions and 106 deletions.
114 changes: 22 additions & 92 deletions frontend/cypress/e2e/hwcr-outcome-assessment.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,90 +2,6 @@ import COMPLAINT_TYPES from "../../src/app/types/app/complaint-types";

describe("HWCR Outcome Assessments", () => {

//A couple of functions that are probably only ever going to be used here used here. Could be promoted to commands.
function validateComplaint (complaintIdentifier: string, species: string) {
//-- verify the right complaint identifier is selected and the animal type
cy.get(".comp-box-complaint-id").contains(complaintIdentifier);
cy.get(".comp-box-species-type").contains(species);


//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-outcome-report-complaint-assessment')
.then(function($assessment) {
if ($assessment.find('#outcome-save-button').length) {
cy.get("#ASSESSRISK").should("exist");
cy.get("#ASSESSHLTH").should("exist");
cy.get("#ASSESSHIST").should("exist");
cy.get("#CNFRMIDENT").should("exist");

//validate that dropdowns exist
cy.get("#action-required").should("exist");
cy.get("#outcome-officer").should("exist");

//validate the date picker exists
cy.get("#complaint-outcome-date").should("exist");
}
});
};

function fillInAssessment (assessment: string[], actionRequired: string, officer: string, date: string, justification?: string) {

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

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

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

cy.selectItemById(
"outcome-officer",
officer,
);

cy.enterDateTimeInDatePicker("complaint-outcome-date", date);

//click Save Button
cy.get("#outcome-save-button").click();
};

function validateAssessment (assessment: string[], actionRequired: string, officer: string, date: string, justification?: string) {
//Verify Fields exist
Cypress._.times(assessment.length, (index) => {
cy.get("#assessment-checkbox-div").should(($div) => {
expect($div).to.contain.text(assessment[index]);
});
});

cy.get("#action-required-div").should(($div) => {
expect($div).to.contain.text(actionRequired);
});

if(justification) {
cy.get("#justification-div").should(($div) => {
expect($div).to.contain.text(justification);
});
}

cy.get("#outcome-officer-div").should(($div) => {
expect($div).to.contain.text(officer);
});

cy.get("#complaint-outcome-date-div").should(($div) => {
expect($div).to.contain.text(date); //Don't know the month... could maybe make this a bit smarter but this is probably good enough.
});
};

beforeEach(function () {
cy.viewport("macbook-16");
cy.kcLogout().kcLogin();
Expand All @@ -100,7 +16,7 @@ describe("HWCR Outcome Assessments", () => {
cy.get('.comp-outcome-report-complaint-assessment')
.then(function($assessment) {
if ($assessment.find('#outcome-save-button').length) {
validateComplaint("23-033066", "Coyote");
cy.validateComplaint("23-033066", "Coyote");

//click Save Button
cy.get("#outcome-save-button").click();
Expand All @@ -109,6 +25,20 @@ describe("HWCR Outcome Assessments", () => {
cy.get(".error-message").should(($error) => {
expect($error).to.contain.text("One or more assessment is required");
});

//validate Action Required is required
cy.get("#action-required-div").find(".error-message").should("exist");

//validate officer is required
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");

//validate the toast
cy.get(".Toastify__toast-body").then(($toast) => {
expect($toast).to.contain.text("Errors in form");
});
} else {
cy.log('Test was previously run. Skip the Test')
this.skip()
Expand All @@ -125,9 +55,9 @@ describe("HWCR Outcome Assessments", () => {
cy.get('.comp-outcome-report-complaint-assessment')
.then(function($assessment) {
if ($assessment.find('#outcome-save-button').length) {
validateComplaint("23-033066", "Coyote");
fillInAssessment (["#ASSESSRISK"], "Yes", "Olivia Benson", "01")
validateAssessment (["Assessed public safety risk"], "Yes", "Olivia Benson", "01");
cy.validateComplaint("23-033066", "Coyote");
cy.fillInHWCSection ("ASSESSMENT", ["#ASSESSRISK"], "Olivia Benson", "01", "Yes")
cy.validateHWCSection ("ASSESSMENT", ["Assessed public safety risk"], "Olivia Benson", "01", "Yes");
} else {
cy.log('Test was previously run. Skip the Test')
this.skip()
Expand All @@ -138,7 +68,7 @@ describe("HWCR Outcome Assessments", () => {
it("it can cancel assessment edits", () => {
cy.navigateToDetailsScreen(COMPLAINT_TYPES.HWCR, "23-033066", true);

validateComplaint("23-033066", "Coyote");
cy.validateComplaint("23-033066", "Coyote");

cy.get('.comp-outcome-report-complaint-assessment')
.then(function($assessment) {
Expand Down Expand Up @@ -170,16 +100,16 @@ describe("HWCR Outcome Assessments", () => {
it("it can edit an existing assessment", () => {
cy.navigateToDetailsScreen(COMPLAINT_TYPES.HWCR, "23-033066", true);

validateComplaint("23-033066", "Coyote");
cy.validateComplaint("23-033066", "Coyote");

cy.get('.comp-outcome-report-complaint-assessment')
.then(function($assessment) {
if ($assessment.find('#assessment-edit-button').length) {
cy.get("#assessment-edit-button").click();

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

validateAssessment (["Assessed public safety risk", "Assessed known conflict history"], "No", "Jake Peralta", "01", "No public safety concern");
cy.validateHWCSection ("ASSESSMENT", ["Assessed public safety risk", "Assessed known conflict history"], "Jake Peralta", "01", "No", "No public safety concern");
} else {
cy.log('Assessment Not Found, did a previous test fail? Skip the Test')
this.skip()
Expand Down
150 changes: 150 additions & 0 deletions frontend/cypress/e2e/hwcr-outcome-notes.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import COMPLAINT_TYPES from "../../src/app/types/app/complaint-types";

describe("HWCR Outcome Notes", () => {

//A function to try and reduce code duplication warnings

function enterNote(note: string) {
cy.get("#supporting-notes-textarea-id").click({ force: true });
cy.get("#supporting-notes-textarea-id")
.clear()
.type(note, { delay: 0 });
}

beforeEach(function () {
cy.viewport("macbook-16");
cy.kcLogout().kcLogin();
});

it("it requires valid user input", () => {
cy.navigateToDetailsScreen(COMPLAINT_TYPES.HWCR, "23-032454" , 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-note').length > 0) {
cy.get('#outcome-report-add-note').click();
} else {
cy.log('Test was previously run. Skip the Test');
this.skip();
}
});

cy.get('.comp-outcome-supporting-notes')
.then(function() {
cy.validateComplaint("23-032454", "Black Bear");

//click Save Button
cy.get("#supporting-notes-save-button").click();

//validate error message
cy.get(".error-message").then(($error) => {
expect($error).to.contain.text("Supporting notes required");
});

});
});


it("it can save note", () => {
cy.navigateToDetailsScreen(COMPLAINT_TYPES.HWCR, "23-032454", 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.
cy.get('.comp-hwcr-outcome-report').then(function($outcome) {
if ($outcome.find('#outcome-report-add-note').length > 0) {
cy.get('#outcome-report-add-note').click();

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

enterNote("This is test supporting note from Cypress");

cy.get("#supporting-notes-save-button").click();

//validate the note
cy.get(".comp-outcome-supporting-notes").should(($div) => {
expect($div).to.contain.text("This is test supporting note from Cypress");
});

//validate the officer
cy.get("#comp-notes-officer").should(($div) => {
expect($div).to.contain.text("ENV TestAcct");
});

//validate the toast
cy.get(".Toastify__toast-body").then(($toast) => {
expect($toast).to.contain.text("Supplemental note created");
});
} else {
cy.log('Test was previously run. Skip the Test');
this.skip();
}
});
});


it("it can cancel note edits", () => {
cy.navigateToDetailsScreen(COMPLAINT_TYPES.HWCR, "23-032454", true);

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

cy.get('.comp-outcome-supporting-notes')
.then(function($notes) {
if ($notes.find('#notes-edit-button').length) {
cy.get("#notes-edit-button").click();

enterNote("This text will be cancelled by Cypress");

cy.get("#supporting-notes-cancel-button").click();

cy.get('.modal-footer > .btn-primary').click();

cy.get(".comp-outcome-supporting-notes").should(($div) => {
expect($div).to.not.contain.text("This text will be cancelled by Cypress");
});
} else {
cy.log('Notes Edit Button Not Found, did a previous test fail? Skip the Test')
this.skip()
}
});
});

it("it can edit an existing note", () => {
cy.navigateToDetailsScreen(COMPLAINT_TYPES.HWCR, "23-032454", true);

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

cy.get('.comp-outcome-supporting-notes')
.then(function($notes) {
if ($notes.find('#notes-edit-button').length) {
cy.get("#notes-edit-button").click();

enterNote("This note is edited by Cypress");

cy.get('#supporting-notes-save-button').click();

//Validate the text
cy.get(".comp-outcome-supporting-notes").should(($div) => {
expect($div).to.contain.text("This note is edited by Cypress");
});

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

} else {
cy.log('Note Edit Button Not Found, did a previous test fail? Skip the Test')
this.skip()
}
});
});

});





Loading

0 comments on commit dafb3d8

Please sign in to comment.