Skip to content

Commit

Permalink
Fix inline email address editing
Browse files Browse the repository at this point in the history
  • Loading branch information
wrandall22 committed Jul 19, 2024
1 parent 73a395c commit 17b3df4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import { DateTime } from 'luxon';
import TestWrapper from '__tests__/util/TestWrapper';
import { GqlMockedProvider } from '__tests__/util/graphqlMocking';
import { render, waitFor } from '__tests__/util/testingLibraryReactMock';
import { PersonEmailAddressInput } from 'src/graphql/types.generated';
import theme from '../../../theme';
import { EmailAddressesMutation } from './AddEmailAddress.generated';
import {
FixEmailAddressPerson,
FixEmailAddressPersonProps,
} from './FixEmailAddressPerson';
import { EmailAddressData } from './FixEmailAddresses';
import { EmailAddressData, PersonEmailAddresses } from './FixEmailAddresses';
import { GetInvalidEmailAddressesQuery } from './FixEmailAddresses.generated';
import { mockInvalidEmailAddressesResponse } from './FixEmailAddressesMocks';

Expand Down Expand Up @@ -48,6 +49,14 @@ const TestComponent = ({ mocks }: { mocks: ApolloErgonoMockMap }) => {
const handleChangeMock = jest.fn();
const handleDeleteModalOpenMock = jest.fn();
const handleChangePrimaryMock = jest.fn();
const toDelete = [] as PersonEmailAddressInput[];
const dataState = {
id: {
emailAddresses: testData.emailAddresses as EmailAddressData[],
toDelete,
},
} as { [key: string]: PersonEmailAddresses };

return (
<ThemeProvider theme={theme}>
<TestWrapper>
Expand All @@ -58,10 +67,11 @@ const TestComponent = ({ mocks }: { mocks: ApolloErgonoMockMap }) => {
mocks={mocks}
>
<FixEmailAddressPerson
toDelete={[]}
toDelete={toDelete}
name={testData.name}
key={testData.name}
personId={testData.personId}
dataState={dataState}
contactId={testData.contactId}
emailAddresses={testData.emailAddresses}
handleChange={handleChangeMock}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { dateFormatShort } from 'src/lib/intlFormat';
import theme from '../../../theme';
import { ConfirmButtonIcon } from '../ConfirmButtonIcon';
import EmailValidationForm from './EmailValidationForm';
import { EmailAddressData } from './FixEmailAddresses';
import { EmailAddressData, PersonEmailAddresses } from './FixEmailAddresses';

const PersonCard = styled(Box)(({ theme }) => ({
[theme.breakpoints.up('md')]: {
Expand Down Expand Up @@ -96,6 +96,7 @@ export interface FixEmailAddressPersonProps {
name: string;
emailAddresses?: EmailAddressData[];
personId: string;
dataState: { [key: string]: PersonEmailAddresses };
toDelete: PersonEmailAddressInput[];
contactId: string;
handleChange: (
Expand All @@ -112,6 +113,7 @@ export const FixEmailAddressPerson: React.FC<FixEmailAddressPersonProps> = ({
name,
emailAddresses,
personId,
dataState,
contactId,
handleChange,
handleDelete,
Expand All @@ -130,7 +132,7 @@ export const FixEmailAddressPerson: React.FC<FixEmailAddressPersonProps> = ({
personId: personId,
isPrimary: email.primary,
})) || [],
[emailAddresses],
[emailAddresses, dataState],
);

const handleContactNameClick = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,16 @@ describe('FixPhoneNumbers-Home', () => {
).toBeInTheDocument();
});

//TODO: Fix during MPDX-7946
it.skip('should modify first email of first contact', async () => {
it('should modify first email of first contact', async () => {
const { getByTestId } = render(<Components />);
await waitFor(() => {
expect(getByTestId('textfield-testid-0')).toBeInTheDocument();
});
const firstInput = getByTestId('textfield-testid-0') as HTMLInputElement;
const firstInput = getByTestId('textfield-testid-0');

expect(firstInput.value).toBe('[email protected]');
expect(firstInput).toHaveValue('[email protected]');
userEvent.type(firstInput, '123');
expect(firstInput.value).toBe('[email protected]');
expect(firstInput).toHaveValue('[email protected]');
});

describe('setContactFocus()', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Tool/FixEmailAddresses/FixEmailAddresses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export interface EmailAddressData {
destroy?: boolean;
}

interface PersonEmailAddresses {
export interface PersonEmailAddresses {
emailAddresses: EmailAddressData[];
toDelete: PersonEmailAddressInput[];
}
Expand Down Expand Up @@ -279,6 +279,7 @@ export const FixEmailAddresses: React.FC<FixEmailAddressesProps> = ({
name={`${person.firstName} ${person.lastName}`}
key={person.id}
personId={person.id}
dataState={dataState}
emailAddresses={dataState[person.id]?.emailAddresses}
toDelete={dataState[person.id]?.toDelete}
contactId={person.contactId}
Expand Down

0 comments on commit 17b3df4

Please sign in to comment.