Skip to content

Commit

Permalink
[MDCT-2555] Stabilize carts e2e smoke test (#139420)
Browse files Browse the repository at this point in the history
  • Loading branch information
BearHanded authored Jul 27, 2023
1 parent fbd5999 commit 940060a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 40 deletions.
38 changes: 38 additions & 0 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ before(() => {

const emailForCognito = "//input[@name='email']";
const passwordForCognito = "//input[@name='password']";
const uncertifyButton = "[data-testid='uncertifyButton']";
const logoutButton = "[data-testid='header-menu-option-log-out']";
const headerDropdownMenu = "[data-testid='headerDropDownMenu']";

const stateUser = {
email: Cypress.env("STATE_USER_EMAIL"),
Expand All @@ -27,6 +30,7 @@ const reviewer = {
};

Cypress.Commands.add("authenticate", (userType, userCredentials) => {
cy.reload();
let credentials = {};
if (userType && userCredentials) {
console.warn(
Expand Down Expand Up @@ -56,6 +60,40 @@ Cypress.Commands.add("authenticate", (userType, userCredentials) => {
cy.get('[data-cy="login-with-cognito-button"]').click();
});

Cypress.Commands.add("logout", () => {
cy.wait(3000);
cy.get(headerDropdownMenu).click();
cy.get(logoutButton).click();
cy.wait(3000); // let logout settle
});

Cypress.Commands.add("ensureAvailableReport", () => {
// login as admin
cy.visit("/");
cy.authenticate("adminUser");

/*
* check if there is a certified program, if so, uncertify
* so state user will always have an editable program
*/
// Scope to test user's state
cy.get(".dropdown-heading").first().click();
cy.contains("Alabama").click();
cy.get("body").click(0, 0);
cy.get(".filter-button").contains("Filter").click();
cy.wait(3000);

cy.get("body").then(($body) => {
if ($body.find(uncertifyButton).length > 0) {
cy.get(uncertifyButton).first().click();
cy.get("button").contains("Yes, Uncertify").click();
}
return;
});

cy.logout();
});

// Define at the top of the spec file or just import it
function terminalLog(violations) {
cy.task(
Expand Down
55 changes: 15 additions & 40 deletions tests/cypress/tests/integration/submitAndUncertify.spec.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,43 @@
// element selectors
const logoutButton = "[data-testid='header-menu-option-log-out']";
const headerDropdownMenu = "[data-testid='headerDropDownMenu']";
const actionButton = "[data-testid='report-action-button']";
const certifySubmitButton = "[data-testid='certifySubmit']";
const uncertifyButton = "[data-testid='uncertifyButton']";

describe("CARTS Submit and Uncertify Integration Tests", () => {
before(() => {
cy.visit("/");

// login as admin
cy.authenticate("adminUser");
/*
* check if there is a certified program, if so, uncertify
* so state user will always have an editable program
*/
cy.wait(15000);

cy.get("body").then(($body) => {
if ($body.text().includes("Uncertify")) {
cy.wait(3000);
cy.get(uncertifyButton).first().click();
cy.get("button").contains("Yes, Uncertify").click();
}
return;
});

cy.wait(3000);
cy.get(headerDropdownMenu).click();
cy.get(logoutButton).click();
});

it("Should submit form as a State User and uncertify as a Reviewer", () => {
cy.ensureAvailableReport(); // Needs to happen each iteration of the test

// log in as State User
cy.authenticate("stateUser");

// certify and submit report
cy.get(actionButton, { timeout: 30000 }).contains("Edit").click();
cy.wait(3000);
cy.contains("Certify and Submit").click();
cy.wait(3000);

cy.get(certifySubmitButton).click();
cy.get("button").contains("Confirm Certify and Submit").click();
cy.get("button").contains("Return Home").click();

// log out
cy.get(headerDropdownMenu).click();
cy.get(logoutButton).click();
cy.logout();

// log in as CMS Admin (user who can uncertify)
cy.authenticate("adminUser");

// uncertify report
// uncertify report - Scope to test user's state
cy.get(".dropdown-heading").first().click();
cy.contains("Alabama").click();
cy.get("body").click(0, 0);
cy.get(".filter-button").contains("Filter").click();
cy.wait(3000);

cy.get(uncertifyButton).first().contains("Uncertify").click();
cy.get("button").contains("Yes, Uncertify").click();

cy.wait(3000);

// log back out
cy.get(headerDropdownMenu).click();
cy.get(logoutButton).click();
cy.logout();

// log back in as State User
// log back in as State User - the report should be "In Progress" again
cy.authenticate("stateUser");

// the report should be "In Progress" again
cy.get(actionButton).contains("Edit").should("be.visible");
});
});

0 comments on commit 940060a

Please sign in to comment.