Skip to content

Commit 54916e3

Browse files
authored
Merge pull request #1159 from CruGlobal/hs-1248886-appeal-commitment
MPDX-8413 - Appeal contact row actions click fix
2 parents fb060bb + 0af946c commit 54916e3

2 files changed

Lines changed: 72 additions & 45 deletions

File tree

src/components/Tool/Appeal/List/ContactRow/ContactRow.test.tsx

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import React from 'react';
22
import { ThemeProvider } from '@mui/material/styles';
3+
import { AdapterLuxon } from '@mui/x-date-pickers/AdapterLuxon';
4+
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
35
import { render } from '@testing-library/react';
46
import userEvent from '@testing-library/user-event';
7+
import { SnackbarProvider } from 'notistack';
58
import TestRouter from '__tests__/util/TestRouter';
69
import { GqlMockedProvider } from '__tests__/util/graphqlMocking';
710
import { AppealsWrapper } from 'pages/accountLists/[accountListId]/tools/appeals/AppealsWrapper';
@@ -24,9 +27,10 @@ const router = {
2427
query: { accountListId },
2528
isReady: true,
2629
};
30+
const contactUrl = `/accountLists/${accountListId}/tools/appeals/${appealId}/${defaultContact.id}`;
2731

2832
const getContactUrl = jest.fn().mockReturnValue({
29-
contactUrl: `/contacts/${defaultContact.id}`,
33+
contactUrl,
3034
});
3135
const contactDetailsOpen = true;
3236
const toggleSelectionById = jest.fn();
@@ -43,29 +47,33 @@ const Components = ({
4347
excludedContacts = [],
4448
}: ComponentsProps) => (
4549
<TestRouter router={router}>
46-
<GqlMockedProvider>
47-
<ThemeProvider theme={theme}>
48-
<AppealsWrapper>
49-
<AppealsContext.Provider
50-
value={
51-
{
52-
appealId,
53-
getContactUrl,
54-
isRowChecked,
55-
contactDetailsOpen,
56-
toggleSelectionById,
57-
} as unknown as AppealsType
58-
}
59-
>
60-
<ContactRow
61-
contact={contact}
62-
appealStatus={appealStatus}
63-
excludedContacts={excludedContacts}
64-
/>
65-
</AppealsContext.Provider>
66-
</AppealsWrapper>
67-
</ThemeProvider>
68-
</GqlMockedProvider>
50+
<LocalizationProvider dateAdapter={AdapterLuxon}>
51+
<SnackbarProvider>
52+
<GqlMockedProvider>
53+
<ThemeProvider theme={theme}>
54+
<AppealsWrapper>
55+
<AppealsContext.Provider
56+
value={
57+
{
58+
appealId,
59+
getContactUrl,
60+
isRowChecked,
61+
contactDetailsOpen,
62+
toggleSelectionById,
63+
} as unknown as AppealsType
64+
}
65+
>
66+
<ContactRow
67+
contact={contact}
68+
appealStatus={appealStatus}
69+
excludedContacts={excludedContacts}
70+
/>
71+
</AppealsContext.Provider>
72+
</AppealsWrapper>
73+
</ThemeProvider>
74+
</GqlMockedProvider>
75+
</SnackbarProvider>
76+
</LocalizationProvider>
6977
</TestRouter>
7078
);
7179

@@ -92,7 +100,17 @@ describe('ContactsRow', () => {
92100

93101
const contact = getByTestId('rowButton');
94102
expect(contact).toBeInTheDocument();
95-
expect(contact).toHaveAttribute('href', `/contacts/${defaultContact.id}`);
103+
expect(contact).toHaveAttribute('href', contactUrl);
104+
});
105+
106+
it('should open commitment modal', async () => {
107+
const { getByTestId, findByRole } = render(<Components />);
108+
109+
const addCommitment = getByTestId('AddIcon');
110+
userEvent.click(addCommitment);
111+
expect(
112+
await findByRole('heading', { name: 'Add Commitment' }),
113+
).toBeInTheDocument();
96114
});
97115

98116
describe('Contact Row by status type', () => {

src/components/Tool/Appeal/List/ContactRow/ContactRow.tsx

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ const ContactRowActions = styled(Box)(() => ({
6363
paddingRight: theme.spacing(2),
6464
}));
6565

66+
export const handleClickWithCallback = (
67+
event: React.MouseEvent<HTMLDivElement>,
68+
callback: () => void,
69+
) => {
70+
event.preventDefault();
71+
callback();
72+
};
73+
6674
interface Props {
6775
contact: AppealContactInfoFragment;
6876
appealStatus: AppealStatusEnum;
@@ -249,21 +257,22 @@ export const ContactRow: React.FC<Props> = ({
249257
<IconButton
250258
size={'small'}
251259
component="div"
252-
onClick={(event) => {
253-
event.stopPropagation();
254-
handleCreatePledge();
255-
}}
260+
onClick={(event) =>
261+
handleClickWithCallback(event, handleCreatePledge)
262+
}
256263
onMouseOver={preloadPledgeModal}
257264
>
258265
<AddIcon />
259266
</IconButton>
260267
<IconButton
261268
size={'small'}
262269
component="div"
263-
onClick={(event) => {
264-
event.stopPropagation();
265-
handleRemoveContactFromAppeal();
266-
}}
270+
onClick={(event) =>
271+
handleClickWithCallback(
272+
event,
273+
handleRemoveContactFromAppeal,
274+
)
275+
}
267276
onMouseOver={preloadDeleteAppealContactModal}
268277
>
269278
<DeleteIcon color="error" />
@@ -277,21 +286,19 @@ export const ContactRow: React.FC<Props> = ({
277286
<IconButton
278287
size={'small'}
279288
component="div"
280-
onClick={(event) => {
281-
event.stopPropagation();
282-
handleEditContact();
283-
}}
289+
onClick={(event) =>
290+
handleClickWithCallback(event, handleEditContact)
291+
}
284292
onMouseOver={preloadPledgeModal}
285293
>
286294
<EditIcon />
287295
</IconButton>
288296
<IconButton
289297
size={'small'}
290298
component="div"
291-
onClick={(event) => {
292-
event.stopPropagation();
293-
handleRemovePledge();
294-
}}
299+
onClick={(event) =>
300+
handleClickWithCallback(event, handleRemovePledge)
301+
}
295302
onMouseOver={preloadDeletePledgeModal}
296303
>
297304
<DeleteIcon color="error" />
@@ -302,10 +309,12 @@ export const ContactRow: React.FC<Props> = ({
302309
<IconButton
303310
size={'small'}
304311
component="div"
305-
onClick={(event) => {
306-
event.stopPropagation();
307-
handleAddExcludedContactToAppeal();
308-
}}
312+
onClick={(event) =>
313+
handleClickWithCallback(
314+
event,
315+
handleAddExcludedContactToAppeal,
316+
)
317+
}
309318
onMouseOver={preloadAddExcludedContactModal}
310319
>
311320
<AddIcon />

0 commit comments

Comments
 (0)