diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 5f575d656..671463be0 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -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"), @@ -27,6 +30,7 @@ const reviewer = { }; Cypress.Commands.add("authenticate", (userType, userCredentials) => { + cy.reload(); let credentials = {}; if (userType && userCredentials) { console.warn( @@ -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( diff --git a/tests/cypress/tests/integration/submitAndUncertify.spec.js b/tests/cypress/tests/integration/submitAndUncertify.spec.js index 44f11d7b6..167a13308 100644 --- a/tests/cypress/tests/integration/submitAndUncertify.spec.js +++ b/tests/cypress/tests/integration/submitAndUncertify.spec.js @@ -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"); }); });