From 49f476f000a654221ef5474c0f3c8a3fe2b0a79f Mon Sep 17 00:00:00 2001 From: "Frank Pigeon Jr." Date: Mon, 16 Sep 2024 11:59:16 -0500 Subject: [PATCH] fix: fixes logic for displaying requestor name (#2788) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fixes logic for displaying requestor name fix: adds createdBy prop for budget lines * test: 🧪adds tests --- .../data/agreements_and_blin_data.json5 | 148 ++++++++++-------- .../cypress/e2e/statusChangeRequest.cy.js | 8 + .../StatusChangeReviewCard.jsx | 18 +-- .../StatusChangeReviewCard.test.jsx | 17 +- 4 files changed, 115 insertions(+), 76 deletions(-) diff --git a/backend/data_tools/data/agreements_and_blin_data.json5 b/backend/data_tools/data/agreements_and_blin_data.json5 index a7e99dec04..06abf76328 100644 --- a/backend/data_tools/data/agreements_and_blin_data.json5 +++ b/backend/data_tools/data/agreements_and_blin_data.json5 @@ -1,5 +1,4 @@ { - direct_agreement: [ { name: "DIRECT ALLOCATION #2: African American Child and Family Research Center", @@ -14,18 +13,18 @@ payee: "The Foundation of People Who Get Paid", team_members: [ { - "tablename": "ops_user", - "id": 500, + tablename: "ops_user", + id: 500, }, { - "tablename": "ops_user", - "id": 503 + tablename: "ops_user", + id: 503, }, { - "tablename": "ops_user", - "id": 520, - } - ] + tablename: "ops_user", + id: 520, + }, + ], }, ], grant_agreement: [ @@ -106,7 +105,7 @@ contract_type: "TIME_AND_MATERIALS", contract_category: "SERVICE", support_contacts: [], - service_requirement_type: "SEVERABLE" + service_requirement_type: "SEVERABLE", }, { name: "MIHOPE Long-Term", @@ -125,7 +124,7 @@ contract_type: "LABOR_HOUR", support_contacts: [], contract_category: "SERVICE", - service_requirement_type: "NON_SEVERABLE" + service_requirement_type: "NON_SEVERABLE", }, { name: "Interoperability Initiatives", @@ -147,14 +146,14 @@ support_contacts: [], team_members: [ { - "tablename": "ops_user", - "id": 511, + tablename: "ops_user", + id: 511, }, { - "tablename": "ops_user", - "id": 520, - } - ] + tablename: "ops_user", + id: 520, + }, + ], }, { name: "Contract Workflow Test", @@ -176,21 +175,21 @@ support_contacts: [], team_members: [ { - "tablename": "ops_user", - "id": 500, + tablename: "ops_user", + id: 500, }, { - "tablename": "ops_user", - "id": 503, + tablename: "ops_user", + id: 503, }, { - "tablename": "ops_user", - "id": 520, + tablename: "ops_user", + id: 520, }, { - "tablename": "ops_user", - "id": 522, - } + tablename: "ops_user", + id: 522, + }, ], }, { @@ -213,15 +212,15 @@ support_contacts: [], team_members: [ { - "tablename": "ops_user", - "id": 511, + tablename: "ops_user", + id: 511, }, { - "tablename": "ops_user", - "id": 520, - } - ] - } + tablename: "ops_user", + id: 520, + }, + ], + }, ], clin: [ { @@ -241,7 +240,7 @@ name: "CLIN 3", number: 3, contract_agreement_id: 1, - } + }, ], services_component: [ { @@ -280,7 +279,7 @@ period_end: "2045-06-13T14:00:00", contract_agreement_id: 7, }, - { + { id: 5, number: 1, optional: false, @@ -315,13 +314,14 @@ period_start: "2044-06-13T14:00:00", period_end: "2045-06-13T14:00:00", contract_agreement_id: 11, - } + }, ], budget_line_item: [ { line_description: "LI 1", comments: "", can_id: 504, + created_by: 503, agreement_id: 1, amount: 1000000.0, status: "DRAFT", @@ -337,6 +337,7 @@ line_description: "LI 2", comments: "", can_id: 504, + created_by: 503, agreement_id: 1, amount: 1000000.0, status: "DRAFT", @@ -350,6 +351,7 @@ line_description: "Line Item 1", comments: "", can_id: 507, + created_by: 503, agreement_id: 2, amount: 1000000.0, status: "PLANNED", @@ -357,12 +359,13 @@ proc_shop_fee_percentage: 0.005, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "Line Item 2", comments: "", can_id: 507, + created_by: 503, agreement_id: 2, amount: 1000000.0, status: "PLANNED", @@ -370,12 +373,13 @@ proc_shop_fee_percentage: 0.005, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "Line Item 1", comments: "", can_id: 508, + created_by: 503, agreement_id: 2, amount: 1000000.0, status: "PLANNED", @@ -383,12 +387,13 @@ proc_shop_fee_percentage: 0.005, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "Line Item 2", comments: "", can_id: 508, + created_by: 503, agreement_id: 2, amount: 1000000.0, status: "PLANNED", @@ -396,12 +401,13 @@ proc_shop_fee_percentage: 0.005, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "Line Item 1", comments: "", can_id: 508, + created_by: 503, agreement_id: 2, amount: 1000000.0, status: "PLANNED", @@ -409,12 +415,13 @@ proc_shop_fee_percentage: 0.005, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "Line Item 2", comments: "", can_id: 508, + created_by: 503, agreement_id: 2, amount: 2000000.0, status: "IN_EXECUTION", @@ -422,12 +429,13 @@ proc_shop_fee_percentage: 0.005, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "Line Item 2", comments: "", can_id: 500, + created_by: 503, agreement_id: 2, amount: 2000000.0, status: "IN_EXECUTION", @@ -435,12 +443,13 @@ proc_shop_fee_percentage: 0.005, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "Line Item 2", comments: "", can_id: 503, + created_by: 503, agreement_id: 2, amount: 2000000.0, status: "IN_EXECUTION", @@ -448,12 +457,13 @@ proc_shop_fee_percentage: 0.005, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "Line Item 2", comments: "", can_id: 501, + created_by: 503, agreement_id: 2, amount: 2000000.0, status: "IN_EXECUTION", @@ -461,12 +471,13 @@ proc_shop_fee_percentage: 0.005, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "Line Item 2", comments: "", can_id: 502, + created_by: 503, agreement_id: 2, amount: 2000000.0, status: "IN_EXECUTION", @@ -474,12 +485,13 @@ proc_shop_fee_percentage: 0.005, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "Line Item 2", comments: "", can_id: 504, + created_by: 503, agreement_id: 2, amount: 2000000.0, status: "IN_EXECUTION", @@ -487,12 +499,13 @@ proc_shop_fee_percentage: 0.005, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "Line Item 2", comments: "", can_id: 505, + created_by: 503, agreement_id: 2, amount: 2000000.0, status: "IN_EXECUTION", @@ -500,12 +513,13 @@ proc_shop_fee_percentage: 0.005, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "Line Item 2", comments: "", can_id: 506, + created_by: 503, agreement_id: 2, amount: 2000000.0, status: "IN_EXECUTION", @@ -513,12 +527,13 @@ proc_shop_fee_percentage: 0.005, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "Line Item 2", comments: "", can_id: 501, + created_by: 503, agreement_id: 2, amount: 1000000.0, status: "PLANNED", @@ -526,12 +541,13 @@ proc_shop_fee_percentage: 0.005, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "Line Item 2", comments: "", can_id: 501, + created_by: 503, agreement_id: 2, amount: 3000000.0, status: "OBLIGATED", @@ -539,12 +555,13 @@ proc_shop_fee_percentage: 0.005, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "Line Item 2", comments: "", can_id: 502, + created_by: 503, agreement_id: 2, amount: 7000000.0, status: "PLANNED", @@ -552,12 +569,13 @@ proc_shop_fee_percentage: 0.005, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "Yet Another Line Item", comments: "", can_id: 512, + created_by: 503, agreement_id: 7, amount: 500.0, status: "OBLIGATED", @@ -566,12 +584,13 @@ services_component_id: 4, on_hold: false, certified: false, - closed: false + closed: false, }, { - line_description: "Yet Another Line Item", + line_description: "Yet Another Line Item", comments: "", can_id: 514, + created_by: 503, agreement_id: 8, amount: 500.0, status: "OBLIGATED", @@ -580,12 +599,13 @@ services_component_id: 5, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "SC2", comments: "", can_id: 502, + created_by: 503, agreement_id: 9, amount: 700000.0, status: "PLANNED", @@ -594,12 +614,13 @@ services_component_id: 6, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "SC3", comments: "", can_id: 512, + created_by: 503, agreement_id: 9, amount: 300000.0, status: "PLANNED", @@ -608,12 +629,13 @@ services_component_id: 6, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "LI 1", comments: "", can_id: 504, + created_by: 503, agreement_id: 10, amount: 1000000.0, status: "PLANNED", @@ -622,12 +644,13 @@ services_component_id: 7, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "LI 2", comments: "", can_id: 504, + created_by: 503, agreement_id: 10, amount: 1000000.0, status: "DRAFT", @@ -636,12 +659,13 @@ services_component_id: 7, on_hold: false, certified: false, - closed: false + closed: false, }, { line_description: "Support #1", comments: "", can_id: 516, + created_by: 503, agreement_id: 11, amount: 300000.0, status: "PLANNED", @@ -650,7 +674,7 @@ services_component_id: 8, on_hold: false, certified: false, - closed: false - } - ] + closed: false, + }, + ], } diff --git a/frontend/cypress/e2e/statusChangeRequest.cy.js b/frontend/cypress/e2e/statusChangeRequest.cy.js index 57f8781ffc..30b842b1c8 100644 --- a/frontend/cypress/e2e/statusChangeRequest.cy.js +++ b/frontend/cypress/e2e/statusChangeRequest.cy.js @@ -94,6 +94,14 @@ it("BLI Status Change", () => { cy.wait(1); }); cy.get('[data-cy="send-to-approval-btn"]').should("not.be.disabled"); + cy.get('[data-cy="review-card"]').within(() => { + cy.contains(bliId); + cy.contains("Admin Demo"); + cy.contains("Status"); + cy.contains("Draft"); + cy.contains("Planned"); + cy.contains("$1,005,000.00"); + }); // type pls approve in the #submitter-notes textarea cy.get("#submitter-notes").type("pls approve"); cy.get('[data-cy="send-to-approval-btn"]').click(); diff --git a/frontend/src/components/ChangeRequests/StatusChangeReviewCard/StatusChangeReviewCard.jsx b/frontend/src/components/ChangeRequests/StatusChangeReviewCard/StatusChangeReviewCard.jsx index 59c55b775d..360334ad5e 100644 --- a/frontend/src/components/ChangeRequests/StatusChangeReviewCard/StatusChangeReviewCard.jsx +++ b/frontend/src/components/ChangeRequests/StatusChangeReviewCard/StatusChangeReviewCard.jsx @@ -2,10 +2,10 @@ import PropTypes from "prop-types"; import { renderChangeValues } from "../../../helpers/changeRequests.helpers"; import { convertCodeForDisplay, renderField } from "../../../helpers/utils"; import { useGetBLITotal, useGetNameForCanId } from "../../../hooks/lookup.hooks"; +import { useGetLoggedInUserFullName } from "../../../hooks/user.hooks"; import { CHANGE_REQUEST_TYPES } from "../ChangeRequests.constants"; import ReviewCard from "../ReviewCard"; import TermTag from "../TermTag"; -import useGetUserFullNameFromId from "../../../hooks/user.hooks"; /** * BudgetChangeReviewCard component @@ -20,7 +20,6 @@ import useGetUserFullNameFromId from "../../../hooks/user.hooks"; * @param {Function} props.handleReviewChangeRequest - Function to handle review of change requests * @param {boolean} [props.isCondensed=false] - Whether the card is condensed * @param {boolean} [props.forceHover=false] - Whether to force hover state - * @param {number} [props.createdById] - The ID of the user who created the change request * @returns {JSX.Element} - The rendered component */ function StatusChangeReviewCard({ @@ -32,8 +31,7 @@ function StatusChangeReviewCard({ changeTo, handleReviewChangeRequest, isCondensed = false, - forceHover = false, - createdById + forceHover = false }) { const keyName = Object.keys(changeTo)[0]; const totalAmount = useGetBLITotal(bliId); @@ -41,18 +39,15 @@ function StatusChangeReviewCard({ const newCan = useGetNameForCanId(changeTo.can_id?.new); const { oldValue, newValue } = renderChangeValues(keyName, changeTo, oldCan, newCan); const changeMsg = `\u2022 BL ${bliId} ${convertCodeForDisplay("changeToTypes", keyName)}: ${oldValue} to ${newValue}`; - const createdBy = useGetUserFullNameFromId(createdById); - if (createdById === null && !requesterName) { - requesterName = createdBy; - } - + const loggedInUserFullName = useGetLoggedInUserFullName(); + const displayedRequesterName = requesterName ?? loggedInUserFullName; return ( ({ @@ -25,7 +25,7 @@ describe("StatusChangeReviewCard", () => { useGetCansQuery.mockReturnValue({ data: [agreement.budget_line_items[0].can] }); useGetBLITotal.mockReturnValue(1000000); useReviewChangeRequestMutation.mockReturnValue([vi.fn(), { isLoading: false }]); - useGetUserFullNameFromId.mockReturnValue("unknown"); + useGetLoggedInUserFullName.mockReturnValue("Logged In User"); const initialProps = { changeRequestId: 1, @@ -53,6 +53,7 @@ describe("StatusChangeReviewCard", () => { expect(screen.getByRole("heading", { name: "Status Change Planned" })).toBeInTheDocument(); expect(screen.getByText("$1,000,000.00")).toBeInTheDocument(); + expect(screen.getByText("Jane Doe")).toBeInTheDocument(); }); it("should render a status change of DRAFT to PLANNED", () => { render( @@ -87,4 +88,16 @@ describe("StatusChangeReviewCard", () => { expect(screen.getByText(/planned/i)).toBeInTheDocument(); expect(screen.getByText(/executing/i, { selector: "span" })).toBeInTheDocument(); }); + it("should render logged in user name if no requestor name is passed", () => { + render( + + + + ); + expect(screen.getByText("Logged In User")).toBeInTheDocument(); + }); });