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-7943 | Add Contacts Drawer to Tools #960

Merged
merged 11 commits into from
Jun 20, 2024
35 changes: 35 additions & 0 deletions pages/accountLists/[accountListId]/contacts/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,41 @@
'/accountLists/[accountListId]/reports/donations/[[...contactId]]'
) {
pathname = `/accountLists/${accountListId}/reports/donations`;
} else if (
routerPathname ===
'/accountLists/[accountListId]/tools/fixMailingAddresses/[[...contactId]]'
) {
pathname = `/accountLists/${accountListId}/tools/fixMailingAddresses`;

Check warning on line 57 in pages/accountLists/[accountListId]/contacts/helpers.ts

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/contacts/helpers.ts#L57

Added line #L57 was not covered by tests
} else if (
routerPathname ===
'/accountLists/[accountListId]/tools/fixCommitmentInfo/[[...contactId]]'
) {
pathname = `/accountLists/${accountListId}/tools/fixCommitmentInfo`;

Check warning on line 62 in pages/accountLists/[accountListId]/contacts/helpers.ts

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/contacts/helpers.ts#L62

Added line #L62 was not covered by tests
} else if (
routerPathname ===
'/accountLists/[accountListId]/tools/fixSendNewsletter/[[...contactId]]'
) {
pathname = `/accountLists/${accountListId}/tools/fixSendNewsletter`;

Check warning on line 67 in pages/accountLists/[accountListId]/contacts/helpers.ts

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/contacts/helpers.ts#L67

Added line #L67 was not covered by tests
} else if (
routerPathname ===
'/accountLists/[accountListId]/tools/mergeContacts/[[...contactId]]'
) {
pathname = `/accountLists/${accountListId}/tools/mergeContacts`;

Check warning on line 72 in pages/accountLists/[accountListId]/contacts/helpers.ts

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/contacts/helpers.ts#L72

Added line #L72 was not covered by tests
} else if (
routerPathname ===
'/accountLists/[accountListId]/tools/fixEmailAddresses/[[...contactId]]'
) {
pathname = `/accountLists/${accountListId}/tools/fixEmailAddresses`;

Check warning on line 77 in pages/accountLists/[accountListId]/contacts/helpers.ts

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/contacts/helpers.ts#L77

Added line #L77 was not covered by tests
} else if (
routerPathname ===
'/accountLists/[accountListId]/tools/fixPhoneNumbers/[[...contactId]]'
) {
pathname = `/accountLists/${accountListId}/tools/fixPhoneNumbers`;

Check warning on line 82 in pages/accountLists/[accountListId]/contacts/helpers.ts

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/contacts/helpers.ts#L82

Added line #L82 was not covered by tests
} else if (
routerPathname ===
'/accountLists/[accountListId]/tools/mergePeople/[[...contactId]]'
) {
pathname = `/accountLists/${accountListId}/tools/mergePeople`;

Check warning on line 87 in pages/accountLists/[accountListId]/contacts/helpers.ts

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/contacts/helpers.ts#L87

Added line #L87 was not covered by tests
}

if (contactId) {
Expand Down
56 changes: 56 additions & 0 deletions pages/accountLists/[accountListId]/tools/ToolsWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import Head from 'next/head';
import React, { JSXElementConstructor, ReactElement } from 'react';
import { DynamicContactsRightPanel } from 'src/components/Contacts/ContactsRightPanel/DynamicContactsRightPanel';
import { SidePanelsLayout } from 'src/components/Layouts/SidePanelsLayout';
import Loading from 'src/components/Loading';
import useGetAppSettings from 'src/hooks/useGetAppSettings';
import { ContactsWrapper } from '../contacts/ContactsWrapper';
import { useToolsHelper } from './useToolsHelper';

interface ToolsWrapperProps {
pageTitle: string;
pageUrl: string;
selectedMenuId: string; // for later use
children: ReactElement<unknown, string | JSXElementConstructor<unknown>>;
}

export const ToolsWrapper: React.FC<ToolsWrapperProps> = ({
pageTitle,
pageUrl,
children,
}) => {
const { appName } = useGetAppSettings();
const { accountListId, selectedContactId, handleSelectContact } =
useToolsHelper();

return (
<>
<Head>
<title>
{appName} | {pageTitle}
</title>
</Head>
{accountListId ? (
<SidePanelsLayout
leftOpen={false}
leftWidth="290px"
mainContent={children}
rightPanel={
selectedContactId ? (
<ContactsWrapper>

Check warning on line 40 in pages/accountLists/[accountListId]/tools/ToolsWrapper.tsx

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/tools/ToolsWrapper.tsx#L40

Added line #L40 was not covered by tests
<DynamicContactsRightPanel
onClose={() => handleSelectContact(pageUrl, '')}

Check warning on line 42 in pages/accountLists/[accountListId]/tools/ToolsWrapper.tsx

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/tools/ToolsWrapper.tsx#L42

Added line #L42 was not covered by tests
/>
</ContactsWrapper>
) : undefined
}
rightOpen={typeof selectedContactId !== 'undefined'}
rightWidth="60%"
headerHeight={'0px'}
/>
) : (
<Loading loading />

Check warning on line 52 in pages/accountLists/[accountListId]/tools/ToolsWrapper.tsx

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/tools/ToolsWrapper.tsx#L52

Added line #L52 was not covered by tests
)}
</>
);
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import FixCommitmentInfo from 'src/components/Tool/FixCommitmentInfo/FixCommitmentInfo';
import { ToolsWrapper } from '../ToolsWrapper';
import { SetContactFocus, useToolsHelper } from '../useToolsHelper';

Check warning on line 6 in pages/accountLists/[accountListId]/tools/fixCommitmentInfo/[[...contactId]].page.tsx

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/tools/fixCommitmentInfo/[[...contactId]].page.tsx#L1-L6

Added lines #L1 - L6 were not covered by tests

const FixCommitmentInfoPage: React.FC = () => {
const { t } = useTranslation();
const { accountListId, handleSelectContact } = useToolsHelper();
const pageUrl = 'tools/fixCommitmentInfo';

Check warning on line 11 in pages/accountLists/[accountListId]/tools/fixCommitmentInfo/[[...contactId]].page.tsx

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/tools/fixCommitmentInfo/[[...contactId]].page.tsx#L8-L11

Added lines #L8 - L11 were not covered by tests

const setContactFocus: SetContactFocus = (contactId) => {
handleSelectContact(pageUrl, contactId);

Check warning on line 14 in pages/accountLists/[accountListId]/tools/fixCommitmentInfo/[[...contactId]].page.tsx

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/tools/fixCommitmentInfo/[[...contactId]].page.tsx#L13-L14

Added lines #L13 - L14 were not covered by tests
};

return (

Check warning on line 17 in pages/accountLists/[accountListId]/tools/fixCommitmentInfo/[[...contactId]].page.tsx

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/tools/fixCommitmentInfo/[[...contactId]].page.tsx#L17

Added line #L17 was not covered by tests
<ToolsWrapper
pageTitle={t('Fix Commitment Info')}
pageUrl={pageUrl}
selectedMenuId="fixCommitmentInfo"
>
<FixCommitmentInfo
accountListId={accountListId || ''}
setContactFocus={setContactFocus}
/>
</ToolsWrapper>
);
};

export const getServerSideProps = loadSession;

Check warning on line 31 in pages/accountLists/[accountListId]/tools/fixCommitmentInfo/[[...contactId]].page.tsx

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/tools/fixCommitmentInfo/[[...contactId]].page.tsx#L31

Added line #L31 was not covered by tests

export default FixCommitmentInfoPage;

Check warning on line 33 in pages/accountLists/[accountListId]/tools/fixCommitmentInfo/[[...contactId]].page.tsx

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/tools/fixCommitmentInfo/[[...contactId]].page.tsx#L33

Added line #L33 was not covered by tests

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { FixEmailAddresses } from 'src/components/Tool/FixEmailAddresses/FixEmailAddresses';
import { ToolsWrapper } from '../ToolsWrapper';
import { SetContactFocus, useToolsHelper } from '../useToolsHelper';

Check warning on line 6 in pages/accountLists/[accountListId]/tools/fixEmailAddresses/[[...contactId]].page.tsx

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/tools/fixEmailAddresses/[[...contactId]].page.tsx#L1-L6

Added lines #L1 - L6 were not covered by tests

const FixEmailAddressesPage: React.FC = () => {
const { t } = useTranslation();
const { accountListId, handleSelectContact } = useToolsHelper();
const pageUrl = 'tools/fixEmailAddresses';

Check warning on line 11 in pages/accountLists/[accountListId]/tools/fixEmailAddresses/[[...contactId]].page.tsx

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/tools/fixEmailAddresses/[[...contactId]].page.tsx#L8-L11

Added lines #L8 - L11 were not covered by tests

const setContactFocus: SetContactFocus = (contactId) => {
handleSelectContact(pageUrl, contactId);

Check warning on line 14 in pages/accountLists/[accountListId]/tools/fixEmailAddresses/[[...contactId]].page.tsx

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/tools/fixEmailAddresses/[[...contactId]].page.tsx#L13-L14

Added lines #L13 - L14 were not covered by tests
};

return (

Check warning on line 17 in pages/accountLists/[accountListId]/tools/fixEmailAddresses/[[...contactId]].page.tsx

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/tools/fixEmailAddresses/[[...contactId]].page.tsx#L17

Added line #L17 was not covered by tests
<ToolsWrapper
pageTitle={t('Fix Email Addresses')}
pageUrl={pageUrl}
selectedMenuId="fixEmailAddresses"
>
<FixEmailAddresses
accountListId={accountListId || ''}
setContactFocus={setContactFocus}
/>
</ToolsWrapper>
);
};

export const getServerSideProps = loadSession;

Check warning on line 31 in pages/accountLists/[accountListId]/tools/fixEmailAddresses/[[...contactId]].page.tsx

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/tools/fixEmailAddresses/[[...contactId]].page.tsx#L31

Added line #L31 was not covered by tests

export default FixEmailAddressesPage;

Check warning on line 33 in pages/accountLists/[accountListId]/tools/fixEmailAddresses/[[...contactId]].page.tsx

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/tools/fixEmailAddresses/[[...contactId]].page.tsx#L33

Added line #L33 was not covered by tests

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { useRouter } from 'next/router';
import { ThemeProvider } from '@mui/material/styles';
import { render, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { ApolloErgonoMockMap } from 'graphql-ergonomock';
import { getSession } from 'next-auth/react';
import { SnackbarProvider } from 'notistack';
import { I18nextProvider } from 'react-i18next';
import TestRouter from '__tests__/util/TestRouter';
import { GqlMockedProvider } from '__tests__/util/graphqlMocking';
import { mockInvalidAddressesResponse } from 'src/components/Tool/FixMailingAddresses/FixMailingAddressesMock';
import { InvalidAddressesQuery } from 'src/components/Tool/FixMailingAddresses/GetInvalidAddresses.generated';
import i18n from 'src/lib/i18n';
import theme from 'src/theme';
import FixMailingAddressesPage from './[[...contactId]].page';

jest.mock('next-auth/react');
jest.mock('next/router', () => ({
useRouter: jest.fn(),
}));
jest.mock('src/lib/helpScout', () => ({
suggestArticles: jest.fn(),
}));
jest.mock('notistack', () => ({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
...jest.requireActual('notistack'),
useSnackbar: () => {
return {
enqueueSnackbar: jest.fn(),
};
},
}));

const pushFn = jest.fn();
const accountListId = 'account-list-1';
const contactId = 'contactId';
const session = {
expires: '2021-10-28T14:48:20.897Z',
user: {
email: 'Chair Library Bed',
image: null,
name: 'Dung Tapestry',
token: 'superLongJwtString',
},
};
const Components = ({ mocks }: { mocks: ApolloErgonoMockMap }) => (
<ThemeProvider theme={theme}>
<TestRouter>
<GqlMockedProvider<{
InvalidAddresses: InvalidAddressesQuery;
}>
mocks={mocks}
>
<I18nextProvider i18n={i18n}>
<SnackbarProvider>
<FixMailingAddressesPage />
</SnackbarProvider>
</I18nextProvider>
</GqlMockedProvider>
</TestRouter>
</ThemeProvider>
);

describe('FixMailingAddressesPage', () => {
beforeEach(() => {
(getSession as jest.Mock).mockResolvedValue(session);
(useRouter as jest.Mock).mockReturnValue({
query: {
accountListId,
},
isReady: true,
push: pushFn,
});
});

it('should open up contact details', async () => {
const { getByText, queryByTestId } = render(
<Components
mocks={{
InvalidAddresses: {
...mockInvalidAddressesResponse.InvalidAddresses,
},
}}
/>,
);
await waitFor(() =>
expect(queryByTestId('loading')).not.toBeInTheDocument(),
);

const contactName = getByText('Baggins, Frodo');

expect(contactName).toBeInTheDocument();
userEvent.click(contactName);

await waitFor(() => {
expect(pushFn).toHaveBeenCalledWith(
`/accountLists/${accountListId}/tools/fixMailingAddresses/${contactId}`,
);
});
});
});
Loading
Loading