-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MPDX-8091 Preferences Setup steps UI (#1002)
* Preferences Setup steps UI * userOptions query, mutation and setup step logic * Add tests * Notifications Welcome tour * Integrations Setup Welcome tour * Add Reset Welcome Tour Button
- Loading branch information
1 parent
e3e6a5a
commit af2818c
Showing
34 changed files
with
916 additions
and
94 deletions.
There are no files selected for viewing
175 changes: 175 additions & 0 deletions
175
pages/accountLists/[accountListId]/settings/integrations/index.page.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
import React from 'react'; | ||
import { ThemeProvider } from '@mui/material/styles'; | ||
import { render, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import TestRouter from '__tests__/util/TestRouter'; | ||
import { GqlMockedProvider } from '__tests__/util/graphqlMocking'; | ||
import { GetUserOptionsQuery } from 'src/components/Contacts/ContactFlow/GetUserOptions.generated'; | ||
import { MailchimpAccountQuery } from 'src/components/Settings/integrations/Mailchimp/MailchimpAccount.generated'; | ||
import { GetUsersOrganizationsAccountsQuery } from 'src/components/Settings/integrations/Organization/Organizations.generated'; | ||
import { PrayerlettersAccountQuery } from 'src/components/Settings/integrations/Prayerletters/PrayerlettersAccount.generated'; | ||
import useGetAppSettings from 'src/hooks/useGetAppSettings'; | ||
import theme from 'src/theme'; | ||
import Integrations from './index.page'; | ||
|
||
const accountListId = 'account-list-1'; | ||
|
||
const mockEnqueue = jest.fn(); | ||
const mutationSpy = jest.fn(); | ||
const push = jest.fn(); | ||
|
||
const router = { | ||
query: { accountListId }, | ||
isReady: true, | ||
push, | ||
}; | ||
|
||
jest.mock('src/hooks/useGetAppSettings'); | ||
jest.mock('notistack', () => ({ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
...jest.requireActual('notistack'), | ||
useSnackbar: () => { | ||
return { | ||
enqueueSnackbar: mockEnqueue, | ||
}; | ||
}, | ||
})); | ||
interface MocksProvidersProps { | ||
children: JSX.Element; | ||
setup?: string; | ||
} | ||
|
||
const MocksProviders: React.FC<MocksProvidersProps> = ({ children, setup }) => ( | ||
<ThemeProvider theme={theme}> | ||
<TestRouter router={router}> | ||
<GqlMockedProvider<{ | ||
GetUsersOrganizationsAccounts: GetUsersOrganizationsAccountsQuery; | ||
MailchimpAccount: MailchimpAccountQuery; | ||
PrayerlettersAccount: PrayerlettersAccountQuery; | ||
GetUserOptions: GetUserOptionsQuery; | ||
}> | ||
mocks={{ | ||
GetUsersOrganizationsAccounts: { | ||
userOrganizationAccounts: [ | ||
{ | ||
organization: {}, | ||
}, | ||
{ | ||
organization: {}, | ||
}, | ||
], | ||
}, | ||
MailchimpAccount: { mailchimpAccount: [] }, | ||
PrayerlettersAccount: { prayerlettersAccount: [] }, | ||
GetUserOptions: { | ||
userOptions: [ | ||
{ | ||
id: '1', | ||
key: 'setup_position', | ||
value: setup || 'finish', | ||
}, | ||
], | ||
}, | ||
}} | ||
onCall={mutationSpy} | ||
> | ||
{children} | ||
</GqlMockedProvider> | ||
</TestRouter> | ||
</ThemeProvider> | ||
); | ||
|
||
describe('Connect Services page', () => { | ||
beforeEach(() => { | ||
(useGetAppSettings as jest.Mock).mockReturnValue({ | ||
appName: 'MPDX', | ||
}); | ||
}); | ||
it('should render', async () => { | ||
const { findByText } = render( | ||
<MocksProviders> | ||
<Integrations /> | ||
</MocksProviders>, | ||
); | ||
expect(await findByText('Connect Services')).toBeInTheDocument(); | ||
expect(await findByText('Organization')).toBeInTheDocument(); | ||
}); | ||
|
||
describe('Setup Tour', () => { | ||
it('should not show setup banner and accordions should not be disabled', async () => { | ||
const { queryByText, queryByRole, findByText, getByText } = render( | ||
<MocksProviders setup="start"> | ||
<Integrations /> | ||
</MocksProviders>, | ||
); | ||
|
||
await waitFor(() => { | ||
expect( | ||
queryByText('Make MPDX a part of your everyday life'), | ||
).not.toBeInTheDocument(); | ||
expect( | ||
queryByRole('button', { name: 'Next Step' }), | ||
).not.toBeInTheDocument(); | ||
}); | ||
|
||
//Accordions should be clickable | ||
userEvent.click(await findByText('Organization')); | ||
await waitFor(() => { | ||
expect( | ||
getByText( | ||
'Add or change the organizations that sync donation information with this MPDX account. Removing an organization will not remove past information, but will prevent future donations and contacts from syncing.', | ||
), | ||
).toBeVisible(); | ||
}); | ||
}); | ||
|
||
it('should show setup banner and open google', async () => { | ||
const { findByText, getByRole, getByText } = render( | ||
<MocksProviders setup="preferences.integrations"> | ||
<Integrations /> | ||
</MocksProviders>, | ||
); | ||
expect( | ||
await findByText('Make MPDX a part of your everyday life'), | ||
).toBeInTheDocument(); | ||
|
||
//Accordions should be disabled | ||
await waitFor(() => { | ||
const label = getByText('Organization'); | ||
expect(() => userEvent.click(label)).toThrow(); | ||
}); | ||
|
||
const nextButton = getByRole('button', { name: 'Next Step' }); | ||
|
||
// Start with Google | ||
expect(await findByText(/Add Account/i)).toBeInTheDocument(); | ||
|
||
// Moves to MailChimp | ||
userEvent.click(nextButton); | ||
expect(await findByText(/Connect MailChimp/i)).toBeInTheDocument(); | ||
|
||
// PrayerLetters.com | ||
await waitFor(() => userEvent.click(nextButton)); | ||
await waitFor(() => | ||
expect( | ||
getByText( | ||
'prayerletters.com is a significant way to save valuable ministry time while more effectively connecting with your partners. Keep your physical newsletter list up to date in MPDX and then sync it to your prayerletters.com account with this integration.', | ||
), | ||
).toBeInTheDocument(), | ||
); | ||
|
||
// Move to finish | ||
userEvent.click(nextButton); | ||
await waitFor(() => { | ||
expect(mutationSpy).toHaveGraphqlOperation('UpdateUserOptions', { | ||
key: 'setup_position', | ||
value: 'finish', | ||
}); | ||
expect(push).toHaveBeenCalledWith( | ||
'/accountLists/account-list-1/setup/finish', | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
81 changes: 77 additions & 4 deletions
81
pages/accountLists/[accountListId]/settings/integrations/index.page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.