-
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.
Merge pull request #1147 from CruGlobal/MPDX-8403
MPDX 8403 - Fix email exports to export the correct emails
- Loading branch information
Showing
7 changed files
with
127 additions
and
144 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -6,43 +6,20 @@ import { render, waitFor } from '@testing-library/react'; | |
import userEvent from '@testing-library/user-event'; | ||
import { SnackbarProvider } from 'notistack'; | ||
import { GqlMockedProvider } from '__tests__/util/graphqlMocking'; | ||
import { | ||
correctEmailsForExport, | ||
getEmailNewsletterContactsMocks as getEmailsForExportingMocks, | ||
} from 'src/components/Dashboard/ThisWeek/NewsletterMenu/MenuItems/ExportEmail/ExportEmailMocks'; | ||
import theme from 'src/theme'; | ||
import { GetEmailsForExportingQuery } from './GetEmailsForExporting.generated'; | ||
import { MassActionsExportEmailsModal } from './MassActionsExportEmailsModal'; | ||
|
||
const mockEnqueue = jest.fn(); | ||
const selectedIds: string[] = ['abc']; | ||
const accountListId = '123456789'; | ||
const accountListId = 'accountListId'; | ||
const handleClose = jest.fn(); | ||
const mocks = { | ||
GetEmailsForExporting: { | ||
contacts: { | ||
nodes: [ | ||
{ | ||
people: { | ||
nodes: [ | ||
{ | ||
primaryEmailAddress: { | ||
email: '[email protected]', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
people: { | ||
nodes: [ | ||
{ | ||
primaryEmailAddress: { | ||
email: '[email protected]', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
GetEmailsForExporting: getEmailsForExportingMocks, | ||
}; | ||
|
||
jest.mock('notistack', () => ({ | ||
|
@@ -96,7 +73,7 @@ describe('MassActionsExportEmailsModal', () => { | |
userEvent.click(queryAllByText('Copy All')[0]); | ||
await waitFor(() => | ||
expect(navigator.clipboard.writeText).toHaveBeenCalledWith( | ||
'[email protected],[email protected]', | ||
correctEmailsForExport, | ||
), | ||
); | ||
// Export Outlook emails | ||
|
@@ -114,7 +91,7 @@ describe('MassActionsExportEmailsModal', () => { | |
userEvent.click(queryAllByText('Copy All')[1]); | ||
await waitFor(() => | ||
expect(navigator.clipboard.writeText).toHaveBeenCalledWith( | ||
'[email protected];[email protected]', | ||
correctEmailsForExport, | ||
), | ||
); | ||
// Exit | ||
|
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
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 |
---|---|---|
|
@@ -5,73 +5,38 @@ import userEvent from '@testing-library/user-event'; | |
import { GqlMockedProvider } from '__tests__/util/graphqlMocking'; | ||
import theme from '../../../../../../theme'; | ||
import ExportEmail from './ExportEmail'; | ||
import { | ||
correctEmailsForExport, | ||
getEmailNewsletterContactsMocks, | ||
} from './ExportEmailMocks'; | ||
import { GetEmailNewsletterContactsQuery } from './GetNewsletterContacts.generated'; | ||
|
||
const accountListId = '111'; | ||
const handleClose = jest.fn(); | ||
|
||
const Components = () => ( | ||
<ThemeProvider theme={theme}> | ||
<GqlMockedProvider<{ | ||
GetEmailNewsletterContacts: GetEmailNewsletterContactsQuery; | ||
}> | ||
mocks={{ | ||
GetEmailNewsletterContacts: getEmailNewsletterContactsMocks, | ||
}} | ||
> | ||
<ExportEmail accountListId={accountListId} handleClose={handleClose} /> | ||
</GqlMockedProvider> | ||
</ThemeProvider> | ||
); | ||
describe('LogNewsletter', () => { | ||
it('default', () => { | ||
const { queryByText } = render( | ||
<ThemeProvider theme={theme}> | ||
<GqlMockedProvider> | ||
<ExportEmail | ||
accountListId={accountListId} | ||
handleClose={handleClose} | ||
/> | ||
</GqlMockedProvider> | ||
</ThemeProvider>, | ||
); | ||
const { queryByText } = render(<Components />); | ||
expect(queryByText('Digital Newsletter List')).toBeInTheDocument(); | ||
}); | ||
|
||
it('creates emailList string', async () => { | ||
const email1 = '[email protected]'; | ||
const email2 = '[email protected]'; | ||
const mocks = { | ||
GetEmailNewsletterContacts: { | ||
contacts: { | ||
nodes: [ | ||
{ | ||
primaryPerson: { | ||
primaryEmailAddress: { | ||
email: email1, | ||
}, | ||
}, | ||
}, | ||
{ | ||
primaryPerson: { | ||
primaryEmailAddress: { | ||
email: email2, | ||
}, | ||
}, | ||
}, | ||
{ | ||
primaryPerson: null, | ||
}, | ||
], | ||
pageInfo: { | ||
hasNextPage: false, | ||
}, | ||
}, | ||
}, | ||
}; | ||
const { queryByTestId } = render( | ||
<ThemeProvider theme={theme}> | ||
<GqlMockedProvider<{ | ||
GetEmailNewsletterContacts: GetEmailNewsletterContactsQuery; | ||
}> | ||
mocks={mocks} | ||
> | ||
<ExportEmail | ||
accountListId={accountListId} | ||
handleClose={handleClose} | ||
/> | ||
</GqlMockedProvider> | ||
</ThemeProvider>, | ||
); | ||
const { queryByTestId } = render(<Components />); | ||
await waitFor(() => expect(queryByTestId('emailList')).not.toBeNull()); | ||
expect(queryByTestId('emailList')).toHaveValue(`${email1},${email2}`); | ||
expect(queryByTestId('emailList')).toHaveValue(correctEmailsForExport); | ||
}); | ||
|
||
it('copies emailList to clipboard', async () => { | ||
|
@@ -80,54 +45,11 @@ describe('LogNewsletter', () => { | |
writeText: jest.fn(), | ||
}, | ||
}); | ||
const email1 = '[email protected]'; | ||
const email2 = '[email protected]'; | ||
const mocks = { | ||
GetEmailNewsletterContacts: { | ||
contacts: { | ||
nodes: [ | ||
{ | ||
primaryPerson: { | ||
primaryEmailAddress: { | ||
email: email1, | ||
}, | ||
}, | ||
}, | ||
{ | ||
primaryPerson: { | ||
primaryEmailAddress: { | ||
email: email2, | ||
}, | ||
}, | ||
}, | ||
{ | ||
primaryPerson: null, | ||
}, | ||
], | ||
pageInfo: { | ||
hasNextPage: false, | ||
}, | ||
}, | ||
}, | ||
}; | ||
const { queryByTestId, getByText } = render( | ||
<ThemeProvider theme={theme}> | ||
<GqlMockedProvider<{ | ||
GetEmailNewsletterContacts: GetEmailNewsletterContactsQuery; | ||
}> | ||
mocks={mocks} | ||
> | ||
<ExportEmail | ||
accountListId={accountListId} | ||
handleClose={handleClose} | ||
/> | ||
</GqlMockedProvider> | ||
</ThemeProvider>, | ||
); | ||
const { queryByTestId, getByText } = render(<Components />); | ||
await waitFor(() => expect(queryByTestId('emailList')).not.toBeNull()); | ||
userEvent.click(getByText('Copy All')); | ||
expect(navigator.clipboard.writeText).toHaveBeenCalledWith( | ||
`${email1},${email2}`, | ||
correctEmailsForExport, | ||
); | ||
}); | ||
}); |
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
71 changes: 71 additions & 0 deletions
71
src/components/Dashboard/ThisWeek/NewsletterMenu/MenuItems/ExportEmail/ExportEmailMocks.ts
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,71 @@ | ||
export const correctEmailsForExport = 'email1,email3,email4,email7'; | ||
|
||
export const getEmailNewsletterContactsMocks = { | ||
contacts: { | ||
nodes: [ | ||
{ | ||
people: { | ||
nodes: [ | ||
{ | ||
optoutEnewsletter: false, | ||
primaryEmailAddress: { | ||
email: 'email1', | ||
}, | ||
}, | ||
{ | ||
optoutEnewsletter: true, | ||
primaryEmailAddress: { | ||
email: 'email2', | ||
}, | ||
}, | ||
{ | ||
optoutEnewsletter: false, | ||
primaryEmailAddress: { | ||
email: 'email3', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
people: { | ||
nodes: [ | ||
{ | ||
optoutEnewsletter: false, | ||
primaryEmailAddress: { | ||
email: 'email4', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
people: { | ||
nodes: [ | ||
{ | ||
optoutEnewsletter: true, | ||
primaryEmailAddress: { | ||
email: 'email5', | ||
}, | ||
}, | ||
{ | ||
optoutEnewsletter: true, | ||
primaryEmailAddress: { | ||
email: 'email6', | ||
}, | ||
}, | ||
{ | ||
optoutEnewsletter: false, | ||
primaryEmailAddress: { | ||
email: 'email7', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
pageInfo: { | ||
hasNextPage: false, | ||
}, | ||
}, | ||
}; |
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