Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPDX-7419 - fix phone numbers - confirm individual #991

Merged
merged 6 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/components/Tool/FixPhoneNumbers/Contact.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('FixPhoneNumbers-Contact', () => {
const handleDeleteModalOpenMock = jest.fn();
const handleAddMock = jest.fn();
const handleChangePrimaryMock = jest.fn();
const updatePhoneNumber = jest.fn();

const { getByText, getByTestId, getByDisplayValue } = render(
<ThemeProvider theme={theme}>
Expand All @@ -50,6 +51,7 @@ describe('FixPhoneNumbers-Contact', () => {
handleAdd={handleAddMock}
handleChangePrimary={handleChangePrimaryMock}
setContactFocus={setContactFocus}
handleUpdate={updatePhoneNumber}
/>
</TestWrapper>
</ThemeProvider>,
Expand All @@ -67,6 +69,7 @@ describe('FixPhoneNumbers-Contact', () => {
const handleDeleteModalOpenMock = jest.fn();
const handleAddMock = jest.fn();
const handleChangePrimaryMock = jest.fn();
const updatePhoneNumber = jest.fn();

const { getByTestId } = render(
<ThemeProvider theme={theme}>
Expand All @@ -82,6 +85,7 @@ describe('FixPhoneNumbers-Contact', () => {
handleAdd={handleAddMock}
handleChangePrimary={handleChangePrimaryMock}
setContactFocus={setContactFocus}
handleUpdate={updatePhoneNumber}
/>
</TestWrapper>
</ThemeProvider>,
Expand All @@ -103,6 +107,7 @@ describe('FixPhoneNumbers-Contact', () => {
const handleDeleteModalOpenMock = jest.fn();
const handleAddMock = jest.fn();
const handleChangePrimaryMock = jest.fn();
const updatePhoneNumber = jest.fn();

const { getByTestId } = render(
<ThemeProvider theme={theme}>
Expand All @@ -118,6 +123,7 @@ describe('FixPhoneNumbers-Contact', () => {
handleAdd={handleAddMock}
handleChangePrimary={handleChangePrimaryMock}
setContactFocus={setContactFocus}
handleUpdate={updatePhoneNumber}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could test that this mock function gets called in thisshould call mock functions test block.

Copy link
Contributor Author

@wjames111 wjames111 Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I'll add that test in. Let me know if I missed any other things I should test for.

/>
</TestWrapper>
</ThemeProvider>,
Expand All @@ -131,5 +137,7 @@ describe('FixPhoneNumbers-Contact', () => {
expect(handleChangePrimaryMock).toHaveBeenCalled();
userEvent.click(getByTestId('delete-testid-1'));
expect(handleDeleteModalOpenMock).toHaveBeenCalled();
userEvent.click(getByTestId(`confirmButton-${testData.id}`));
expect(updatePhoneNumber).toHaveBeenCalled();
});
});
13 changes: 12 additions & 1 deletion src/components/Tool/FixPhoneNumbers/Contact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ interface Props {
handleAdd: (personId: string, number: string) => void;
handleChangePrimary: (personId: string, numberIndex: number) => void;
setContactFocus: SetContactFocus;
handleUpdate: (
personId: string,
name: string,
numbers: PhoneNumberData[],
) => void;
}

const Contact: React.FC<Props> = ({
Expand All @@ -127,6 +132,7 @@ const Contact: React.FC<Props> = ({
// Remove below line when function is being used.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
setContactFocus,
handleUpdate,
}) => {
const { t } = useTranslation();
const locale = useLocale();
Expand Down Expand Up @@ -349,7 +355,12 @@ const Contact: React.FC<Props> = ({
style={{ paddingLeft: theme.spacing(1) }}
>
<Box className={classes.buttonTop}>
<Button variant="contained" style={{ width: '100%' }}>
<Button
data-testid={`confirmButton-${personId}`}
onClick={() => handleUpdate(personId, name, numbers)}
variant="contained"
style={{ width: '100%' }}
>
<Icon
path={mdiCheckboxMarkedCircle}
size={0.8}
Expand Down
219 changes: 51 additions & 168 deletions src/components/Tool/FixPhoneNumbers/FixPhoneNumbers.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,32 +73,36 @@ const testData: ErgonoMockShape[] = [
},
];

const Components: React.FC<{ data?: ErgonoMockShape[] }> = ({
data = testData,
}) => (
<ThemeProvider theme={theme}>
<TestRouter router={router}>
<TestWrapper>
<GqlMockedProvider<{
GetInvalidPhoneNumbers: GetInvalidPhoneNumbersQuery;
}>
mocks={{
GetInvalidPhoneNumbers: {
people: {
nodes: data,
},
},
}}
>
<FixPhoneNumbers
accountListId={accountListId}
setContactFocus={setContactFocus}
/>
</GqlMockedProvider>
</TestWrapper>
</TestRouter>
</ThemeProvider>
);

describe('FixPhoneNumbers-Home', () => {
it('default with test data', async () => {
const { getByText, queryByTestId } = render(
<ThemeProvider theme={theme}>
<TestRouter router={router}>
<TestWrapper>
<GqlMockedProvider<{
GetInvalidPhoneNumbers: GetInvalidPhoneNumbersQuery;
}>
mocks={{
GetInvalidPhoneNumbers: {
people: {
nodes: testData,
},
},
}}
>
<FixPhoneNumbers
accountListId={accountListId}
setContactFocus={setContactFocus}
/>
</GqlMockedProvider>
</TestWrapper>
</TestRouter>
</ThemeProvider>,
);
const { getByText, queryByTestId } = render(<Components />);

await waitFor(() =>
expect(getByText('Fix Phone Numbers')).toBeInTheDocument(),
Expand All @@ -113,30 +117,7 @@ describe('FixPhoneNumbers-Home', () => {
});

it('change primary of first number', async () => {
const { getByTestId, queryByTestId } = render(
<ThemeProvider theme={theme}>
<TestRouter router={router}>
<TestWrapper>
<GqlMockedProvider<{
GetInvalidPhoneNumbers: GetInvalidPhoneNumbersQuery;
}>
mocks={{
GetInvalidPhoneNumbers: {
people: {
nodes: testData,
},
},
}}
>
<FixPhoneNumbers
accountListId={accountListId}
setContactFocus={setContactFocus}
/>
</GqlMockedProvider>
</TestWrapper>
</TestRouter>
</ThemeProvider>,
);
const { getByTestId, queryByTestId } = render(<Components />);

const star1 = await waitFor(() => getByTestId('starOutlineIcon-testid-1'));
userEvent.click(star1);
Expand All @@ -147,30 +128,7 @@ describe('FixPhoneNumbers-Home', () => {
});

it('delete third number from first person', async () => {
const { getByTestId, queryByTestId } = render(
<ThemeProvider theme={theme}>
<TestRouter router={router}>
<TestWrapper>
<GqlMockedProvider<{
GetInvalidPhoneNumbers: GetInvalidPhoneNumbersQuery;
}>
mocks={{
GetInvalidPhoneNumbers: {
people: {
nodes: testData,
},
},
}}
>
<FixPhoneNumbers
accountListId={accountListId}
setContactFocus={setContactFocus}
/>
</GqlMockedProvider>
</TestWrapper>
</TestRouter>
</ThemeProvider>,
);
const { getByTestId, queryByTestId } = render(<Components />);

const delete02 = await waitFor(() => getByTestId('delete-testid-2'));
userEvent.click(delete02);
Expand All @@ -182,30 +140,7 @@ describe('FixPhoneNumbers-Home', () => {
});

it('change second number for second person to primary then delete it', async () => {
const { getByTestId, queryByTestId } = render(
<ThemeProvider theme={theme}>
<TestRouter router={router}>
<TestWrapper>
<GqlMockedProvider<{
GetInvalidPhoneNumbers: GetInvalidPhoneNumbersQuery;
}>
mocks={{
GetInvalidPhoneNumbers: {
people: {
nodes: testData,
},
},
}}
>
<FixPhoneNumbers
accountListId={accountListId}
setContactFocus={setContactFocus}
/>
</GqlMockedProvider>
</TestWrapper>
</TestRouter>
</ThemeProvider>,
);
const { getByTestId, queryByTestId } = render(<Components />);

const star11 = await waitFor(() =>
getByTestId('starOutlineIcon-testid2-1'),
Expand All @@ -223,30 +158,7 @@ describe('FixPhoneNumbers-Home', () => {
});

it('add a phone number to first person', async () => {
const { getByTestId, getByDisplayValue } = render(
<ThemeProvider theme={theme}>
<TestRouter router={router}>
<TestWrapper>
<GqlMockedProvider<{
GetInvalidPhoneNumbers: GetInvalidPhoneNumbersQuery;
}>
mocks={{
GetInvalidPhoneNumbers: {
people: {
nodes: testData,
},
},
}}
>
<FixPhoneNumbers
accountListId={accountListId}
setContactFocus={setContactFocus}
/>
</GqlMockedProvider>
</TestWrapper>
</TestRouter>
</ThemeProvider>,
);
const { getByTestId, getByDisplayValue } = render(<Components />);
await waitFor(() =>
expect(getByTestId('starIcon-testid2-0')).toBeInTheDocument(),
);
Expand All @@ -265,30 +177,7 @@ describe('FixPhoneNumbers-Home', () => {
});

it('should render no contacts with no data', async () => {
const { getByText, getByTestId } = render(
<ThemeProvider theme={theme}>
<TestRouter router={router}>
<TestWrapper>
<GqlMockedProvider<{
GetInvalidPhoneNumbers: GetInvalidPhoneNumbersQuery;
}>
mocks={{
GetInvalidPhoneNumbers: {
people: {
nodes: [],
},
},
}}
>
<FixPhoneNumbers
accountListId={accountListId}
setContactFocus={setContactFocus}
/>
</GqlMockedProvider>
</TestWrapper>
</TestRouter>
</ThemeProvider>,
);
const { getByText, getByTestId } = render(<Components data={[]} />);
await waitFor(() =>
expect(getByTestId('fixPhoneNumbers-null-state')).toBeInTheDocument(),
);
Expand All @@ -298,30 +187,7 @@ describe('FixPhoneNumbers-Home', () => {
});

it('should modify first number of first contact', async () => {
const { getByTestId } = render(
<ThemeProvider theme={theme}>
<TestRouter router={router}>
<TestWrapper>
<GqlMockedProvider<{
GetInvalidPhoneNumbers: GetInvalidPhoneNumbersQuery;
}>
mocks={{
GetInvalidPhoneNumbers: {
people: {
nodes: testData,
},
},
}}
>
<FixPhoneNumbers
accountListId={accountListId}
setContactFocus={setContactFocus}
/>
</GqlMockedProvider>
</TestWrapper>
</TestRouter>
</ThemeProvider>,
);
const { getByTestId } = render(<Components />);
await waitFor(() => {
expect(getByTestId('textfield-testid-0')).toBeInTheDocument();
});
Expand All @@ -331,4 +197,21 @@ describe('FixPhoneNumbers-Home', () => {
userEvent.type(firstInput, '123');
expect(firstInput.value).toBe('+3533895895123');
});

it('should hide contact from view', async () => {
const { getByTestId, getByText, queryByText } = render(<Components />);
await waitFor(() => {
expect(
getByText(`${testData[0].firstName} ${testData[0].lastName}`),
).toBeInTheDocument();
});

userEvent.click(getByTestId('confirmButton-testid'));

await waitFor(() => {
expect(
queryByText(`${testData[0].firstName} ${testData[0].lastName}`),
).not.toBeInTheDocument();
});
});
});
Loading
Loading