/
EntityDetailsOverlay.test.tsx
153 lines (129 loc) · 5.76 KB
/
EntityDetailsOverlay.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
// components
import { EntityDetailsOverlay } from "./EntityDetailsOverlay";
// utils
import {
mockAdminUser,
mockEntityDetailsContext,
mockMLRReportEntityStartedFieldData,
mockModalOverlayForm,
mockStateUser,
RouterWrappedComponent,
} from "utils/testing/setupJest";
import { useUser } 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();
jest.mock("utils/auth/useUser");
const mockedUseUser = useUser as jest.MockedFunction<typeof useUser>;
const entityDetailsOverlayComponentStateUser = (
<RouterWrappedComponent>
<EntityContext.Provider value={mockEntityDetailsContext}>
<EntityDetailsOverlay
closeEntityDetailsOverlay={mockCloseEntityDetailsOverlay}
entityType={"program"}
entities={[mockMLRReportEntityStartedFieldData.program[0]]}
form={mockModalOverlayForm}
onSubmit={mockOnSubmit}
disabled={false}
selectedEntity={mockMLRReportEntityStartedFieldData.program[0]}
/>
</EntityContext.Provider>
</RouterWrappedComponent>
);
const entityDetailsOverlayComponentAdminUser = (
<RouterWrappedComponent>
<EntityContext.Provider value={mockEntityDetailsContext}>
<EntityDetailsOverlay
closeEntityDetailsOverlay={mockCloseEntityDetailsOverlay}
entityType={"program"}
entities={[mockMLRReportEntityStartedFieldData.program[0]]}
form={mockModalOverlayForm}
onSubmit={mockOnSubmit}
disabled={true}
selectedEntity={mockMLRReportEntityStartedFieldData.program[0]}
/>
</EntityContext.Provider>
</RouterWrappedComponent>
);
describe("Test EntityDetailsOverlayV2 (empty state)", () => {
beforeEach(() => {
jest.clearAllMocks();
});
const user = userEvent.setup();
const selectedEntity = mockMLRReportEntityStartedFieldData.program[0];
it("should render the initial view for a state user", async () => {
mockedUseUser.mockReturnValue(mockStateUser);
render(entityDetailsOverlayComponentStateUser);
// Close out of the Overlay it opened
const closeButton = screen.getByText("Return to MLR Reporting");
expect(closeButton).toBeVisible();
// Check if header is visible on load - H2
expect(
screen.getByText(overlayVerbiage.MLR.intro.subsection)
).toBeVisible();
// Check if accordion is showing
const accordionHeader = accordionVerbiage.MLR.formIntro.buttonLabel;
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}`;
expect(screen.getByText(reportPlanName)).toBeVisible();
expect(screen.getByText(reportProgramName)).toBeVisible();
expect(screen.getByText(eligibilityGroup)).toBeVisible();
expect(screen.getByText(reportingPeriod)).toBeVisible();
// Make sure footer button appears correctly
const saveAndReturn = screen.getByText("Save & return");
expect(saveAndReturn).toBeVisible();
});
it("should render the initial view for an admin", async () => {
mockedUseUser.mockReturnValue(mockAdminUser);
render(entityDetailsOverlayComponentAdminUser);
// Close out of the Overlay it opened
const closeButton = screen.getByText("Return to MLR Reporting");
expect(closeButton).toBeVisible();
// Check if header is visible on load - H2
expect(
screen.getByText(overlayVerbiage.MLR.intro.subsection)
).toBeVisible();
// Check if accordion is showing
const accordionHeader = accordionVerbiage.MLR.formIntro.buttonLabel;
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}`;
expect(screen.getByText(reportPlanName)).toBeVisible();
expect(screen.getByText(reportProgramName)).toBeVisible();
expect(screen.getByText(eligibilityGroup)).toBeVisible();
expect(screen.getByText(reportingPeriod)).toBeVisible();
// Make sure footer button appears correctly for admins
const returnButton = screen.getByText("Return");
expect(returnButton).toBeVisible();
});
it("should call the close overlay function when clicking Return to MLR", async () => {
// Set as State User
mockedUseUser.mockReturnValue(mockStateUser);
render(entityDetailsOverlayComponentStateUser);
// Close out of the Overlay it opened
const closeButton = screen.getByText("Return to MLR Reporting");
await user.click(closeButton);
expect(mockCloseEntityDetailsOverlay).toBeCalled();
});
it("should call the close overlay function when clicking Return to MLR as an Admin", async () => {
// Set as State User
mockedUseUser.mockReturnValue(mockAdminUser);
render(entityDetailsOverlayComponentAdminUser);
// Close out of the Overlay it opened
const closeButton = screen.getByText("Return to MLR Reporting");
await user.click(closeButton);
expect(mockCloseEntityDetailsOverlay).toBeCalled();
});
});