Skip to content

Commit

Permalink
Fixing issue with allow MPDX contacts to be deleted and then updating…
Browse files Browse the repository at this point in the history
… tests to ensure the issue is caught.
  • Loading branch information
dr-bizz committed Dec 5, 2024
1 parent 990e393 commit dbb69a2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ import React from 'react';
import { ThemeProvider } from '@mui/material/styles';
import { LocalizationProvider } from '@mui/x-date-pickers';
import { AdapterLuxon } from '@mui/x-date-pickers/AdapterLuxon';
import { render } from '@testing-library/react';
import { render, waitFor } from '@testing-library/react';
import { SnackbarProvider } from 'notistack';
import TestRouter from '__tests__/util/TestRouter';
import { GqlMockedProvider } from '__tests__/util/graphqlMocking';
import { ContactSourceEnum } from 'src/graphql/types.generated';
import theme from 'src/theme';
import { ContactSourceQuery } from './ContactSource.generated';
import { DeleteContactModal } from './DeleteContactModal';

const contactId = 'contact-id';
const mutationSpy = jest.fn();
const setOpen = jest.fn();
const deleteContact = jest.fn();

interface TestComponentProps {
open?: boolean;
deleting?: boolean;
contactSource?: string;
contactSource?: ContactSourceEnum;
addressSources?: string[];
emailSources?: string[];
phoneSources?: string[];
Expand All @@ -26,7 +28,7 @@ interface TestComponentProps {
const TestComponent: React.FC<TestComponentProps> = ({
open = true,
deleting = false,
contactSource = 'MPDX',
contactSource = ContactSourceEnum.Mpdx,
addressSources = [],
emailSources = [],
phoneSources = [],
Expand All @@ -39,7 +41,7 @@ const TestComponent: React.FC<TestComponentProps> = ({
ContactSource: ContactSourceQuery;
}>
mocks={{
GetContactDetailsHeader: {
ContactSource: {
contact: {
id: contactId,
source: contactSource,
Expand All @@ -61,6 +63,7 @@ const TestComponent: React.FC<TestComponentProps> = ({
},
},
}}
onCall={mutationSpy}
>
<DeleteContactModal
open={open}
Expand All @@ -85,19 +88,27 @@ describe('DeleteContactModal', () => {
).not.toBeInTheDocument();
});

it('should be able to delete contact', () => {
it('should be able to delete contact', async () => {
const { getByText, getByRole } = render(<TestComponent />);

await waitFor(() => {
expect(mutationSpy).toHaveGraphqlOperation('ContactSource');
});

expect(
getByText(/Are you sure you want to permanently delete this contact?/),
).toBeInTheDocument();

expect(getByRole('button', { name: 'delete contact' })).toBeInTheDocument();
});

it('should prevent user from deleting contact while currently deleting contact', () => {
it('should prevent user from deleting contact while currently deleting contact', async () => {
const { getByRole } = render(<TestComponent deleting={true} />);

await waitFor(() => {
expect(mutationSpy).toHaveGraphqlOperation('ContactSource');
});

expect(getByRole('button', { name: 'delete contact' })).toBeDisabled();
});

Expand All @@ -109,7 +120,7 @@ describe('DeleteContactModal', () => {
const tests: TestProps[] = [
{
testName: 'disables deletion if contact created by third party',
props: { contactSource: 'Siebel' },
props: { contactSource: ContactSourceEnum.GiveSite },
},
{
testName:
Expand Down Expand Up @@ -151,19 +162,21 @@ describe('DeleteContactModal', () => {

describe('Enable deletion', () => {
it('should show modal and be able to delete user', async () => {
const { findByText, getByRole } = render(
const { getByText, getByRole } = render(
<TestComponent
contactSource={'MPDX'}
contactSource={ContactSourceEnum.Mpdx}
addressSources={['MPDX', 'MPDX']}
emailSources={['MPDX', 'MPDX']}
phoneSources={['MPDX', 'MPDX']}
/>,
);

await waitFor(() => {
expect(mutationSpy).toHaveGraphqlOperation('ContactSource');
});

expect(
await findByText(
/Are you sure you want to permanently delete this contact?/,
),
getByText(/Are you sure you want to permanently delete this contact?/),
).toBeInTheDocument();

expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const DeleteContactModal: React.FC<DeleteContactModalProps> = ({
// Which will only recreate the data after deleting it on MPDX.
// To prevent this confusion, we do not allow a contact to be deleted if it has non editable data.

const isContactNonEditable = isEditableSource(contactSources.source ?? '');
const isContactNonEditable = !isEditableSource(contactSources.source ?? '');

const isAddressNonEditable = contactSources.addresses?.nodes.some(
(address) => !isEditableSource(address.source ?? ''),
Expand Down

0 comments on commit dbb69a2

Please sign in to comment.