diff --git a/src/components/Tool/Appeal/List/ContactRow/ContactRow.test.tsx b/src/components/Tool/Appeal/List/ContactRow/ContactRow.test.tsx index 645db7149..836f4c427 100644 --- a/src/components/Tool/Appeal/List/ContactRow/ContactRow.test.tsx +++ b/src/components/Tool/Appeal/List/ContactRow/ContactRow.test.tsx @@ -1,7 +1,10 @@ import React from 'react'; import { ThemeProvider } from '@mui/material/styles'; +import { AdapterLuxon } from '@mui/x-date-pickers/AdapterLuxon'; +import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; import { render } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; +import { SnackbarProvider } from 'notistack'; import TestRouter from '__tests__/util/TestRouter'; import { GqlMockedProvider } from '__tests__/util/graphqlMocking'; import { AppealsWrapper } from 'pages/accountLists/[accountListId]/tools/appeals/AppealsWrapper'; @@ -24,9 +27,10 @@ const router = { query: { accountListId }, isReady: true, }; +const contactUrl = `/accountLists/${accountListId}/tools/appeals/${appealId}/${defaultContact.id}`; const getContactUrl = jest.fn().mockReturnValue({ - contactUrl: `/contacts/${defaultContact.id}`, + contactUrl, }); const contactDetailsOpen = true; const toggleSelectionById = jest.fn(); @@ -43,29 +47,33 @@ const Components = ({ excludedContacts = [], }: ComponentsProps) => ( - - - - - - - - - + + + + + + + + + + + + + ); @@ -92,7 +100,17 @@ describe('ContactsRow', () => { const contact = getByTestId('rowButton'); expect(contact).toBeInTheDocument(); - expect(contact).toHaveAttribute('href', `/contacts/${defaultContact.id}`); + expect(contact).toHaveAttribute('href', contactUrl); + }); + + it('should open commitment modal', async () => { + const { getByTestId, findByRole } = render(); + + const addCommitment = getByTestId('AddIcon'); + userEvent.click(addCommitment); + expect( + await findByRole('heading', { name: 'Add Commitment' }), + ).toBeInTheDocument(); }); describe('Contact Row by status type', () => { diff --git a/src/components/Tool/Appeal/List/ContactRow/ContactRow.tsx b/src/components/Tool/Appeal/List/ContactRow/ContactRow.tsx index 3d4d03e62..5e95a5054 100644 --- a/src/components/Tool/Appeal/List/ContactRow/ContactRow.tsx +++ b/src/components/Tool/Appeal/List/ContactRow/ContactRow.tsx @@ -63,6 +63,14 @@ const ContactRowActions = styled(Box)(() => ({ paddingRight: theme.spacing(2), })); +export const handleClickWithCallback = ( + event: React.MouseEvent, + callback: () => void, +) => { + event.preventDefault(); + callback(); +}; + interface Props { contact: AppealContactInfoFragment; appealStatus: AppealStatusEnum; @@ -249,10 +257,9 @@ export const ContactRow: React.FC = ({ { - event.stopPropagation(); - handleCreatePledge(); - }} + onClick={(event) => + handleClickWithCallback(event, handleCreatePledge) + } onMouseOver={preloadPledgeModal} > @@ -260,10 +267,12 @@ export const ContactRow: React.FC = ({ { - event.stopPropagation(); - handleRemoveContactFromAppeal(); - }} + onClick={(event) => + handleClickWithCallback( + event, + handleRemoveContactFromAppeal, + ) + } onMouseOver={preloadDeleteAppealContactModal} > @@ -277,10 +286,9 @@ export const ContactRow: React.FC = ({ { - event.stopPropagation(); - handleEditContact(); - }} + onClick={(event) => + handleClickWithCallback(event, handleEditContact) + } onMouseOver={preloadPledgeModal} > @@ -288,10 +296,9 @@ export const ContactRow: React.FC = ({ { - event.stopPropagation(); - handleRemovePledge(); - }} + onClick={(event) => + handleClickWithCallback(event, handleRemovePledge) + } onMouseOver={preloadDeletePledgeModal} > @@ -302,10 +309,12 @@ export const ContactRow: React.FC = ({ { - event.stopPropagation(); - handleAddExcludedContactToAppeal(); - }} + onClick={(event) => + handleClickWithCallback( + event, + handleAddExcludedContactToAppeal, + ) + } onMouseOver={preloadAddExcludedContactModal} >