From f508eebbcd02a0c71fde2f99b756cbe727f4e844 Mon Sep 17 00:00:00 2001 From: karla-vm Date: Fri, 24 May 2024 14:24:17 -0400 Subject: [PATCH] not skip over tests --- .../overlays/EntityDetailsOverlay.test.tsx | 74 +++++++++---------- .../overlays/EntityDetailsOverlay.tsx | 5 +- .../reports/EntityProvider.test.tsx | 53 ++++++------- .../src/components/tables/EntityRow.test.tsx | 2 +- .../tables/EntityStatusIcon.test.tsx | 6 +- .../tables/MobileEntityRow.test.tsx | 2 +- .../src/utils/autosave/autosave.test.ts | 10 +-- .../ui-src/src/utils/testing/mockZustand.tsx | 31 +++++++- 8 files changed, 98 insertions(+), 85 deletions(-) diff --git a/services/ui-src/src/components/overlays/EntityDetailsOverlay.test.tsx b/services/ui-src/src/components/overlays/EntityDetailsOverlay.test.tsx index 22b0d0565..8ae935394 100644 --- a/services/ui-src/src/components/overlays/EntityDetailsOverlay.test.tsx +++ b/services/ui-src/src/components/overlays/EntityDetailsOverlay.test.tsx @@ -5,8 +5,7 @@ import { EntityDetailsOverlay } from "./EntityDetailsOverlay"; // utils import { mockAdminUserStore, - mockEntityDetailsContext, - mockMLRReportEntityStartedFieldData, + mockEntityStore, mockModalOverlayForm, mockStateUserStore, RouterWrappedComponent, @@ -15,7 +14,6 @@ import { useStore } from "utils"; // verbiage import accordionVerbiage from "../../verbiage/pages/accordion"; import overlayVerbiage from "../../verbiage/pages/overlays"; -import { EntityContext } from "components"; const mockCloseEntityDetailsOverlay = jest.fn(); const mockOnSubmit = jest.fn(); @@ -25,35 +23,25 @@ const mockedUseStore = useStore as jest.MockedFunction; const entityDetailsOverlayComponentStateUser = ( - - - + ); const entityDetailsOverlayComponentAdminUser = ( - - - + ); @@ -63,10 +51,13 @@ describe("Test EntityDetailsOverlayV2 (empty state)", () => { }); const user = userEvent.setup(); - const selectedEntity = mockMLRReportEntityStartedFieldData.program[0]; + const selectedEntity = mockEntityStore.selectedEntity; it("should render the initial view for a state user", async () => { - mockedUseStore.mockReturnValue(mockStateUserStore); + mockedUseStore.mockReturnValue({ + ...mockStateUserStore, + ...mockEntityStore, + }); render(entityDetailsOverlayComponentStateUser); // Close out of the Overlay it opened @@ -83,10 +74,12 @@ describe("Test EntityDetailsOverlayV2 (empty state)", () => { expect(screen.getByText(accordionHeader)).toBeVisible(); // Check if MLR Report For is showing the correct Entity Data - const reportPlanName = selectedEntity.report_planName; - const reportProgramName = selectedEntity.report_programName; - const eligibilityGroup = selectedEntity.report_eligibilityGroup[0].value; - const reportingPeriod = `${selectedEntity.report_reportingPeriodStartDate} to ${selectedEntity.report_reportingPeriodEndDate}`; + const reportPlanName = selectedEntity!.report_planName; + const reportProgramName = selectedEntity!.report_programName; + const eligibilityGroup = selectedEntity!.report_eligibilityGroup[0].value; + const reportingPeriod = `${ + selectedEntity!.report_reportingPeriodStartDate + } to ${selectedEntity!.report_reportingPeriodEndDate}`; expect(screen.getByText(reportPlanName)).toBeVisible(); expect(screen.getByText(reportProgramName)).toBeVisible(); @@ -99,7 +92,10 @@ describe("Test EntityDetailsOverlayV2 (empty state)", () => { }); it("should render the initial view for an admin", async () => { - mockedUseStore.mockReturnValue(mockAdminUserStore); + mockedUseStore.mockReturnValue({ + ...mockAdminUserStore, + ...mockEntityStore, + }); render(entityDetailsOverlayComponentAdminUser); // Close out of the Overlay it opened @@ -116,10 +112,12 @@ describe("Test EntityDetailsOverlayV2 (empty state)", () => { expect(screen.getByText(accordionHeader)).toBeVisible(); // Check if MLR Report For is showing the correct Entity Data - const reportPlanName = selectedEntity.report_planName; - const reportProgramName = selectedEntity.report_programName; - const eligibilityGroup = selectedEntity.report_eligibilityGroup[0].value; - const reportingPeriod = `${selectedEntity.report_reportingPeriodStartDate} to ${selectedEntity.report_reportingPeriodEndDate}`; + const reportPlanName = selectedEntity!.report_planName; + const reportProgramName = selectedEntity!.report_programName; + const eligibilityGroup = selectedEntity!.report_eligibilityGroup[0].value; + const reportingPeriod = `${ + selectedEntity!.report_reportingPeriodStartDate + } to ${selectedEntity!.report_reportingPeriodEndDate}`; expect(screen.getByText(reportPlanName)).toBeVisible(); expect(screen.getByText(reportProgramName)).toBeVisible(); diff --git a/services/ui-src/src/components/overlays/EntityDetailsOverlay.tsx b/services/ui-src/src/components/overlays/EntityDetailsOverlay.tsx index ce7d43782..c54bdf825 100644 --- a/services/ui-src/src/components/overlays/EntityDetailsOverlay.tsx +++ b/services/ui-src/src/components/overlays/EntityDetailsOverlay.tsx @@ -3,7 +3,7 @@ import React, { MouseEventHandler, useEffect } from "react"; import { Box, Button, Flex, Image, Spinner, Text } from "@chakra-ui/react"; import { Form, ReportPageIntro } from "components"; // types -import { EntityShape, EntityType, FormJson } from "types"; +import { EntityShape, FormJson } from "types"; // utils import { useStore } from "utils"; // assets @@ -111,11 +111,8 @@ export const EntityDetailsOverlay = ({ interface Props { closeEntityDetailsOverlay: Function; - entityType: EntityType; - entities: any; form: FormJson; onSubmit: Function; - selectedEntity: EntityShape; disabled: boolean; setEntering: Function; submitting?: boolean; diff --git a/services/ui-src/src/components/reports/EntityProvider.test.tsx b/services/ui-src/src/components/reports/EntityProvider.test.tsx index 58938b792..3d4cffd11 100644 --- a/services/ui-src/src/components/reports/EntityProvider.test.tsx +++ b/services/ui-src/src/components/reports/EntityProvider.test.tsx @@ -1,66 +1,57 @@ import { render } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; -import { useContext, useEffect } from "react"; +import { useContext } from "react"; +import { useStore } from "utils"; +import { + mockEntityStore, + mockMcparReportStore, +} from "utils/testing/mockZustand"; import { EntityContext, EntityProvider } from "./EntityProvider"; -const testEntities = [ - { - id: "foo", - }, - { - id: "bar", - }, -]; +const testEntities = { ...mockEntityStore.selectedEntity }; const testEntitiesUpdated = [ { - id: "foo", + id: "mock-id", + type: "plans", test: "update", }, - { - id: "bar", - }, ]; -interface Props { - noEntity?: boolean; -} +jest.mock("utils/state/useStore"); +const mockedUseStore = useStore as jest.MockedFunction; +mockedUseStore.mockReturnValue(mockEntityStore); -const TestComponent = (props: Props) => { - const { entities, setEntities, updateEntities, setSelectedEntity } = - useContext(EntityContext); - - useEffect(() => { - setEntities(testEntities); - if (!props.noEntity) { - setSelectedEntity({ id: "foo" }); - } - }, [setEntities, setSelectedEntity]); +const TestComponent = () => { + const { prepareEntityPayload } = useContext(EntityContext); return (
- -

{JSON.stringify(entities)}

-

{entities.length}

+

{JSON.stringify(mockEntityStore.selectedEntity)}

); }; const testComponent = ( - + ); const testComponentNoEntity = ( - + ); describe("Test update entities provider function", () => { + beforeEach(() => { + mockedUseStore.mockReturnValue(mockMcparReportStore); + mockedUseStore.mockReturnValue(mockEntityStore); + }); test("Should update entities if the selected entity is valid", async () => { const result = await render(testComponent); expect( diff --git a/services/ui-src/src/components/tables/EntityRow.test.tsx b/services/ui-src/src/components/tables/EntityRow.test.tsx index 0a98294d5..6359e02b3 100644 --- a/services/ui-src/src/components/tables/EntityRow.test.tsx +++ b/services/ui-src/src/components/tables/EntityRow.test.tsx @@ -64,7 +64,7 @@ describe("Test EntityRow", () => { mockedUseStore.mockReturnValue(mockStateUserStore); }); - test.skip("It should render an error if an entity is incomplete", async () => { + test("It should render an error if an entity is incomplete", async () => { const { findByText } = render(incompleteRowComponent); expect( await findByText("Select “Enter MLR” to complete this report.") diff --git a/services/ui-src/src/components/tables/EntityStatusIcon.test.tsx b/services/ui-src/src/components/tables/EntityStatusIcon.test.tsx index bce27348b..a0d611a38 100644 --- a/services/ui-src/src/components/tables/EntityStatusIcon.test.tsx +++ b/services/ui-src/src/components/tables/EntityStatusIcon.test.tsx @@ -113,15 +113,15 @@ describe("EntityStatusIcon functionality tests", () => { const { findByText } = render(entityStatusIconPdfComponent); expect(await findByText("Complete")).toBeVisible(); }); - test.skip("should show a false icon if some required data is missing", () => { + test("should show a false icon if some required data is missing", () => { const { container } = render(entityStatusIconComponentIncomplete); expect(container.querySelector("img[alt='warning icon']")).toBeVisible(); }); - test.skip("should show special text on a pdf page if required data is missing", async () => { + test("should show special text on a pdf page if required data is missing", async () => { const { findByText } = render(entityStatusIconComponentIncompletePdf); expect(await findByText("Error")).toBeVisible(); }); - test.skip("should show a false icon if nested required value is missing", () => { + test("should show a false icon if nested required value is missing", () => { const { container } = render(entityStatusIconComponentIncompleteNested); expect(container.querySelector("img[alt='warning icon']")).toBeVisible(); }); diff --git a/services/ui-src/src/components/tables/MobileEntityRow.test.tsx b/services/ui-src/src/components/tables/MobileEntityRow.test.tsx index 0644cc965..22ed684c2 100644 --- a/services/ui-src/src/components/tables/MobileEntityRow.test.tsx +++ b/services/ui-src/src/components/tables/MobileEntityRow.test.tsx @@ -67,7 +67,7 @@ describe("Test MobileEntityRow", () => { jest.clearAllMocks(); }); - test.skip("It should render an error if an entity is incomplete", async () => { + test("It should render an error if an entity is incomplete", async () => { const { findByText } = render(incompleteRowComponent); expect( await findByText("Select “Enter MLR” to complete this report.") diff --git a/services/ui-src/src/utils/autosave/autosave.test.ts b/services/ui-src/src/utils/autosave/autosave.test.ts index c29dd9a7b..652f89cd8 100644 --- a/services/ui-src/src/utils/autosave/autosave.test.ts +++ b/services/ui-src/src/utils/autosave/autosave.test.ts @@ -1,4 +1,4 @@ -import { mockStateUserStore } from "utils/testing/setupJest"; +import { mockEntityStore, mockStateUserStore } from "utils/testing/setupJest"; import { autosaveFieldData, EntityContextShape, @@ -42,12 +42,10 @@ const fields = [ ]; const mockEntityContext: EntityContextShape = { - updateEntities: jest.fn(() => { + prepareEntityPayload: jest.fn(() => { return [{ id: "foo", testField: 1, field1: "value1", field2: "value2" }]; }), - entities: [{ id: "foo", testField: 1 }], - entityType: "program", - selectedEntity: { id: "foo" }, + selectedEntity: { ...mockEntityStore.selectedEntity! }, }; describe("autosaveFieldData", () => { @@ -130,7 +128,7 @@ describe("autosaveFieldData", () => { lastAlteredBy: "stateuser@test.com", }, fieldData: { - program: [ + plans: [ { id: "foo", testField: 1, field1: "value1", field2: "value2" }, ], }, diff --git a/services/ui-src/src/utils/testing/mockZustand.tsx b/services/ui-src/src/utils/testing/mockZustand.tsx index 3eb3aacd9..216443cbb 100644 --- a/services/ui-src/src/utils/testing/mockZustand.tsx +++ b/services/ui-src/src/utils/testing/mockZustand.tsx @@ -8,6 +8,8 @@ import { // types import { AdminBannerState, + entityTypes, + McrEntityState, McrReportState, McrUserState, UserRoles, @@ -162,12 +164,39 @@ export const mockEmptyReportStore: McrReportState = { setLastSavedTime: () => {}, }; -// BOUND STORE +// ENTITY STATES / STORE +export const mockEntityStore: McrEntityState = { + selectedEntity: { + id: "mock-id", + type: entityTypes[0], + report_planName: "mock-plan", + report_programName: "mock-programName", + report_programType: [ + { + key: "report-programType-mock", + value: "mock value", + }, + ], + report_eligibilityGroup: [ + { + key: "report-eligibilityGroup-mock", + value: "mock value", + }, + ], + report_reportingPeriodStartDate: "11/11/2011", + report_reportingPeriodEndDate: "11/11/2011", + }, + // ACTIONS + setSelectedEntity: () => {}, + clearSelectedEntity: () => {}, +}; +// BOUND STORE export const mockUseStore: McrUserState & AdminBannerState & McrReportState = { ...mockStateUserStore, ...mockBannerStore, ...mockMcparReportStore, ...mockMlrReport, ...mockEmptyReportStore, + ...mockEntityStore, };