Skip to content

Commit

Permalink
Fix appeal contact row click to prevent it opening contact when click…
Browse files Browse the repository at this point in the history
…ing on action icons.
  • Loading branch information
dr-bizz committed Oct 28, 2024
1 parent fb060bb commit 0af946c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 45 deletions.
68 changes: 43 additions & 25 deletions src/components/Tool/Appeal/List/ContactRow/ContactRow.test.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();
Expand All @@ -43,29 +47,33 @@ const Components = ({
excludedContacts = [],
}: ComponentsProps) => (
<TestRouter router={router}>
<GqlMockedProvider>
<ThemeProvider theme={theme}>
<AppealsWrapper>
<AppealsContext.Provider
value={
{
appealId,
getContactUrl,
isRowChecked,
contactDetailsOpen,
toggleSelectionById,
} as unknown as AppealsType
}
>
<ContactRow
contact={contact}
appealStatus={appealStatus}
excludedContacts={excludedContacts}
/>
</AppealsContext.Provider>
</AppealsWrapper>
</ThemeProvider>
</GqlMockedProvider>
<LocalizationProvider dateAdapter={AdapterLuxon}>
<SnackbarProvider>
<GqlMockedProvider>
<ThemeProvider theme={theme}>
<AppealsWrapper>
<AppealsContext.Provider
value={
{
appealId,
getContactUrl,
isRowChecked,
contactDetailsOpen,
toggleSelectionById,
} as unknown as AppealsType
}
>
<ContactRow
contact={contact}
appealStatus={appealStatus}
excludedContacts={excludedContacts}
/>
</AppealsContext.Provider>
</AppealsWrapper>
</ThemeProvider>
</GqlMockedProvider>
</SnackbarProvider>
</LocalizationProvider>
</TestRouter>
);

Expand All @@ -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(<Components />);

const addCommitment = getByTestId('AddIcon');
userEvent.click(addCommitment);
expect(
await findByRole('heading', { name: 'Add Commitment' }),
).toBeInTheDocument();
});

describe('Contact Row by status type', () => {
Expand Down
49 changes: 29 additions & 20 deletions src/components/Tool/Appeal/List/ContactRow/ContactRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ const ContactRowActions = styled(Box)(() => ({
paddingRight: theme.spacing(2),
}));

export const handleClickWithCallback = (
event: React.MouseEvent<HTMLDivElement>,
callback: () => void,
) => {
event.preventDefault();
callback();
};

interface Props {
contact: AppealContactInfoFragment;
appealStatus: AppealStatusEnum;
Expand Down Expand Up @@ -249,21 +257,22 @@ export const ContactRow: React.FC<Props> = ({
<IconButton
size={'small'}
component="div"
onClick={(event) => {
event.stopPropagation();
handleCreatePledge();
}}
onClick={(event) =>
handleClickWithCallback(event, handleCreatePledge)
}
onMouseOver={preloadPledgeModal}
>
<AddIcon />
</IconButton>
<IconButton
size={'small'}
component="div"
onClick={(event) => {
event.stopPropagation();
handleRemoveContactFromAppeal();
}}
onClick={(event) =>
handleClickWithCallback(

Check warning on line 271 in src/components/Tool/Appeal/List/ContactRow/ContactRow.tsx

View check run for this annotation

Codecov / codecov/patch

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

Added line #L271 was not covered by tests
event,
handleRemoveContactFromAppeal,
)
}
onMouseOver={preloadDeleteAppealContactModal}
>
<DeleteIcon color="error" />
Expand All @@ -277,21 +286,19 @@ export const ContactRow: React.FC<Props> = ({
<IconButton
size={'small'}
component="div"
onClick={(event) => {
event.stopPropagation();
handleEditContact();
}}
onClick={(event) =>
handleClickWithCallback(event, handleEditContact)

Check warning on line 290 in src/components/Tool/Appeal/List/ContactRow/ContactRow.tsx

View check run for this annotation

Codecov / codecov/patch

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

Added line #L290 was not covered by tests
}
onMouseOver={preloadPledgeModal}
>
<EditIcon />
</IconButton>
<IconButton
size={'small'}
component="div"
onClick={(event) => {
event.stopPropagation();
handleRemovePledge();
}}
onClick={(event) =>
handleClickWithCallback(event, handleRemovePledge)

Check warning on line 300 in src/components/Tool/Appeal/List/ContactRow/ContactRow.tsx

View check run for this annotation

Codecov / codecov/patch

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

Added line #L300 was not covered by tests
}
onMouseOver={preloadDeletePledgeModal}
>
<DeleteIcon color="error" />
Expand All @@ -302,10 +309,12 @@ export const ContactRow: React.FC<Props> = ({
<IconButton
size={'small'}
component="div"
onClick={(event) => {
event.stopPropagation();
handleAddExcludedContactToAppeal();
}}
onClick={(event) =>
handleClickWithCallback(

Check warning on line 313 in src/components/Tool/Appeal/List/ContactRow/ContactRow.tsx

View check run for this annotation

Codecov / codecov/patch

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

Added line #L313 was not covered by tests
event,
handleAddExcludedContactToAppeal,
)
}
onMouseOver={preloadAddExcludedContactModal}
>
<AddIcon />
Expand Down

0 comments on commit 0af946c

Please sign in to comment.