From add46e2fe4e20d5189e62cace3e66322ae4f6a41 Mon Sep 17 00:00:00 2001 From: Santi-3rd Date: Tue, 10 Dec 2024 15:34:14 -0700 Subject: [PATCH] test: can edit form e2e tests --- .../data/agreements_and_blin_data.json5 | 10 +-- frontend/cypress/e2e/canDetail.cy.js | 61 ++++++++++++++++--- .../CANs/CANDetailForm/CANDetailForm.jsx | 2 +- 3 files changed, 60 insertions(+), 13 deletions(-) diff --git a/backend/data_tools/data/agreements_and_blin_data.json5 b/backend/data_tools/data/agreements_and_blin_data.json5 index c94ec2f07d..d545deca11 100644 --- a/backend/data_tools/data/agreements_and_blin_data.json5 +++ b/backend/data_tools/data/agreements_and_blin_data.json5 @@ -319,7 +319,7 @@ agreement_id: 1, amount: 1000000.0, status: "DRAFT", - date_needed: "2024-06-13T14:03:25.765487", + date_needed: "2043-06-13T14:03:25.765487", proc_shop_fee_percentage: 0, services_component_id: 1, clin_id: 1, @@ -335,7 +335,7 @@ agreement_id: 1, amount: 1000000.0, status: "DRAFT", - date_needed: "2024-06-13T14:03:25.765487", + date_needed: "2043-06-13T14:03:25.765487", proc_shop_fee_percentage: 0, on_hold: false, certified: false, @@ -489,7 +489,7 @@ agreement_id: 2, amount: 2000000.0, status: "IN_EXECUTION", - date_needed: "2023-06-13T14:03:25.765487", + date_needed: "2043-06-13T14:03:25.765487", proc_shop_fee_percentage: 0.005, on_hold: false, certified: false, @@ -633,7 +633,7 @@ agreement_id: 10, amount: 1000000.0, status: "PLANNED", - date_needed: "2023-06-13T14:03:25.765487", + date_needed: "2043-06-13T14:03:25.765487", proc_shop_fee_percentage: 0, services_component_id: 7, on_hold: false, @@ -648,7 +648,7 @@ agreement_id: 10, amount: 1000000.0, status: "DRAFT", - date_needed: "2024-06-13T14:03:25.765487", + date_needed: "2043-06-13T14:03:25.765487", proc_shop_fee_percentage: 0, services_component_id: 7, on_hold: false, diff --git a/frontend/cypress/e2e/canDetail.cy.js b/frontend/cypress/e2e/canDetail.cy.js index ec19357b75..f95ba05ebe 100644 --- a/frontend/cypress/e2e/canDetail.cy.js +++ b/frontend/cypress/e2e/canDetail.cy.js @@ -1,5 +1,6 @@ /// import { terminalLog, testLogin } from "./utils"; +import { getCurrentFiscalYear } from "../../src/helpers/utils.js"; beforeEach(() => { testLogin("budget-team"); @@ -10,32 +11,75 @@ afterEach(() => { cy.checkA11y(null, null, terminalLog); }); +const can502Nickname = "SSRD"; +const can502Description = "Social Science Research and Development"; + +const currentFiscalYear = getCurrentFiscalYear(); + describe("CAN detail page", () => { it("shows the CAN details page", () => { cy.visit("/cans/502/"); cy.get("h1").should("contain", "G99PHS9"); // heading - cy.get("p").should("contain", "SSRD"); // sub-heading + cy.get("p").should("contain", can502Nickname); // sub-heading cy.get("span").should("contain", "Nicole Deterding"); // team member cy.get("span").should("contain", "Director Derrek"); // division director cy.get("span").should("contain", "Program Support"); // portfolio cy.get("span").should("contain", "Division of Data and Improvement"); // division }); - it.only("CAN Edit form", () => { + it("CAN Edit form", () => { cy.visit("/cans/502/"); cy.get("#fiscal-year-select").select("2024"); cy.get("#edit").should("not.exist"); - cy.get("#fiscal-year-select").select("2025"); //TODO: change to current fiscal year + cy.get("#fiscal-year-select").select(currentFiscalYear); cy.get("#edit").should("exist"); cy.get("#edit").click(); cy.get("h2").should("contain", "Edit CAN Details"); - cy.get("#can_nick_name", "input").should("contain", "SSRD"); + cy.get("#can_nick_name").invoke("val").should("equal", can502Nickname); + cy.get("#can_nick_name").clear(); + cy.get(".usa-error-message").should("exist").contains("This is required information"); + cy.get("#save-changes").should("be.disabled"); cy.get("#can_nick_name").type("Test Can Nickname"); + cy.get("#save-changes").should("not.be.disabled"); + cy.get(".usa-error-message").should("not.exist"); + cy.get("#description").invoke("val").should("equal", can502Description); + cy.get("#description").clear(); + cy.get("#description").type("Test description."); + cy.get("#save-changes").click(); + cy.get(".usa-alert__body").should("contain", "The CAN G99PHS9 has been successfully updated."); + cy.get("p").should("contain", "Test Can Nickname"); + cy.get("dd").should("contain", "Test description."); + // revert back to original values + cy.get("#edit").click(); + cy.get("#can_nick_name").clear(); + cy.get("#can_nick_name").type(can502Nickname); + cy.get("#description").clear(); + cy.get("#description").type(can502Description); + cy.get("#save-changes").click(); + }); + it("handles cancelling from CAN edit form", () => { + cy.visit("/cans/502/"); + cy.get("#fiscal-year-select").select(currentFiscalYear); + // Attempt cancel without making any changes + cy.get("#edit").click(); + cy.get("[data-cy='cancel-button']").click(); + cy.get(".usa-modal__heading").should( + "contain", + "Are you sure you want to cancel editing? Your changes will not be saved." + ); + cy.get("[data-cy='cancel-action']").click(); + // Exit out of the cancel modal + cy.get("[data-cy='cancel-button']").click(); + // Actual cancel event + cy.get("[data-cy='confirm-action']").click(); + cy.get("h2").should("contain", "CAN Details"); + cy.get("p").should("contain", can502Nickname); + cy.get("dd").should("contain", can502Description); }); it("shows the CAN Spending page", () => { cy.visit("/cans/504/spending"); cy.get("#fiscal-year-select").select("2043"); cy.get("h1").should("contain", "G994426"); // heading - cy.get("p").should("contain", "HS - 5 Years"); // sub-heading + cy.get("p").should("contain", "HS"); // sub-heading // should contain the budget line table cy.get("table").should("exist"); // table should have more than 1 row @@ -87,14 +131,17 @@ describe("CAN detail page", () => { cy.visit("/cans/504/funding"); cy.get("#fiscal-year-select").select("2024"); cy.get("h1").should("contain", "G994426"); // heading - cy.get("p").should("contain", "HS - 5 Years"); // sub-heading + cy.get("p").should("contain", "HS"); // sub-heading cy.get("[data-cy=can-funding-info-card]") .should("exist") .and("contain", "EEXXXX20215DAD") .and("contain", "5 Years") .and("contain", "IDDA") .and("contain", "09/30/25") - .and("contain", "2021"); + .and("contain", "2021") + .and("contain", "Quarterly") + .and("contain", "Direct") + .and("contain", "Discretionary"); cy.get("[data-cy=budget-received-card]") .should("exist") .and("contain", "FY 2024 Funding Received YTD") diff --git a/frontend/src/components/CANs/CANDetailForm/CANDetailForm.jsx b/frontend/src/components/CANs/CANDetailForm/CANDetailForm.jsx index 522c367b0b..ee787b6493 100644 --- a/frontend/src/components/CANs/CANDetailForm/CANDetailForm.jsx +++ b/frontend/src/components/CANs/CANDetailForm/CANDetailForm.jsx @@ -63,7 +63,7 @@ const CANDetailForm = ({ canId, canNumber, canNickname, canDescription, portfoli />