-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f054079
commit 25dc1d0
Showing
1 changed file
with
104 additions
and
104 deletions.
There are no files selected for viewing
208 changes: 104 additions & 104 deletions
208
frontend/src/components/dashboard/create/email/tests/EmailRecipients.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 |
---|---|---|
@@ -1,119 +1,119 @@ | ||
// import userEvent from '@testing-library/user-event' | ||
import userEvent from '@testing-library/user-event' | ||
|
||
// import { Route, Routes } from 'react-router-dom' | ||
import { Route, Routes } from 'react-router-dom' | ||
|
||
// import EmailRecipients from '../EmailRecipients' | ||
import EmailRecipients from '../EmailRecipients' | ||
|
||
// import { EmailCampaign } from 'classes' | ||
// import CampaignContextProvider from 'contexts/campaign.context' | ||
// import FinishLaterModalContextProvider from 'contexts/finish-later.modal.context' | ||
// import { | ||
// screen, | ||
// mockCommonApis, | ||
// server, | ||
// render, | ||
// Campaign, | ||
// USER_EMAIL, | ||
// DEFAULT_FROM, | ||
// INVALID_EMAIL_CSV_FILE, | ||
// } from 'test-utils' | ||
import { EmailCampaign } from 'classes' | ||
import CampaignContextProvider from 'contexts/campaign.context' | ||
import FinishLaterModalContextProvider from 'contexts/finish-later.modal.context' | ||
import { | ||
screen, | ||
mockCommonApis, | ||
server, | ||
render, | ||
Campaign, | ||
USER_EMAIL, | ||
DEFAULT_FROM, | ||
INVALID_EMAIL_CSV_FILE, | ||
} from 'test-utils' | ||
|
||
// const TEST_EMAIL_CAMPAIGN: Campaign = { | ||
// id: 1, | ||
// name: 'Test email campaign', | ||
// type: 'EMAIL', | ||
// created_at: new Date(), | ||
// valid: false, | ||
// protect: false, | ||
// demo_message_limit: null, | ||
// csv_filename: null, | ||
// is_csv_processing: false, | ||
// num_recipients: null, | ||
// job_queue: [], | ||
// halted: false, | ||
// email_templates: { | ||
// body: 'Test body', | ||
// subject: 'Test subject', | ||
// params: [], | ||
// reply_to: USER_EMAIL, | ||
// from: DEFAULT_FROM, | ||
// }, | ||
// has_credential: false, | ||
// } | ||
const TEST_EMAIL_CAMPAIGN: Campaign = { | ||
id: 1, | ||
name: 'Test email campaign', | ||
type: 'EMAIL', | ||
created_at: new Date(), | ||
valid: false, | ||
protect: false, | ||
demo_message_limit: null, | ||
csv_filename: null, | ||
is_csv_processing: false, | ||
num_recipients: null, | ||
job_queue: [], | ||
halted: false, | ||
email_templates: { | ||
body: 'Test body', | ||
subject: 'Test subject', | ||
params: [], | ||
reply_to: USER_EMAIL, | ||
from: DEFAULT_FROM, | ||
}, | ||
has_credential: false, | ||
} | ||
|
||
// function mockApis() { | ||
// const { handlers } = mockCommonApis({ | ||
// curUserId: 1, // Start authenticated | ||
function mockApis() { | ||
const { handlers } = mockCommonApis({ | ||
curUserId: 1, // Start authenticated | ||
|
||
// // Start with an email campaign with a saved template | ||
// campaigns: [{ ...TEST_EMAIL_CAMPAIGN }], | ||
// }) | ||
// return handlers | ||
// } | ||
// Start with an email campaign with a saved template | ||
campaigns: [{ ...TEST_EMAIL_CAMPAIGN }], | ||
}) | ||
return handlers | ||
} | ||
|
||
// function renderRecipients() { | ||
// const setActiveStep = jest.fn() | ||
function renderRecipients() { | ||
const setActiveStep = jest.fn() | ||
|
||
// render( | ||
// <Routes> | ||
// <Route | ||
// path="/campaigns/:id" | ||
// element={ | ||
// <CampaignContextProvider | ||
// initialCampaign={new EmailCampaign({ ...TEST_EMAIL_CAMPAIGN })} | ||
// > | ||
// <FinishLaterModalContextProvider> | ||
// <EmailRecipients setActiveStep={setActiveStep} /> | ||
// </FinishLaterModalContextProvider> | ||
// </CampaignContextProvider> | ||
// } | ||
// /> | ||
// </Routes>, | ||
// { | ||
// router: { initialIndex: 0, initialEntries: ['/campaigns/1'] }, | ||
// } | ||
// ) | ||
// } | ||
render( | ||
<Routes> | ||
<Route | ||
path="/campaigns/:id" | ||
element={ | ||
<CampaignContextProvider | ||
initialCampaign={new EmailCampaign({ ...TEST_EMAIL_CAMPAIGN })} | ||
> | ||
<FinishLaterModalContextProvider> | ||
<EmailRecipients setActiveStep={setActiveStep} /> | ||
</FinishLaterModalContextProvider> | ||
</CampaignContextProvider> | ||
} | ||
/> | ||
</Routes>, | ||
{ | ||
router: { initialIndex: 0, initialEntries: ['/campaigns/1'] }, | ||
} | ||
) | ||
} | ||
|
||
// test('displays the necessary elements', async () => { | ||
// // Setup | ||
// server.use(...mockApis()) | ||
// renderRecipients() | ||
test('displays the necessary elements', async () => { | ||
// Setup | ||
server.use(...mockApis()) | ||
renderRecipients() | ||
|
||
// // Wait for the component to fully load | ||
// const uploadButton = await screen.findByRole('button', { | ||
// name: /upload file/i, | ||
// }) | ||
// Wait for the component to fully load | ||
const uploadButton = await screen.findByRole('button', { | ||
name: /upload file/i, | ||
}) | ||
|
||
// /** | ||
// * Assert that the following elements are present: | ||
// * 1. "Upload File" button | ||
// * 2. "Download a sample .csv file" button | ||
// */ | ||
// expect(uploadButton).toBeInTheDocument() | ||
// expect( | ||
// screen.getByRole('button', { name: /download a sample/i }) | ||
// ).toBeInTheDocument() | ||
// }) | ||
/** | ||
* Assert that the following elements are present: | ||
* 1. "Upload File" button | ||
* 2. "Download a sample .csv file" button | ||
*/ | ||
expect(uploadButton).toBeInTheDocument() | ||
expect( | ||
screen.getByRole('button', { name: /download a sample/i }) | ||
).toBeInTheDocument() | ||
}) | ||
|
||
// test('displays an error message after uploading an invalid recipients list', async () => { | ||
// // Setup | ||
// server.use(...mockApis()) | ||
// renderRecipients() | ||
test('displays an error message after uploading an invalid recipients list', async () => { | ||
// Setup | ||
server.use(...mockApis()) | ||
renderRecipients() | ||
|
||
// // Wait for the component to fully load | ||
// const fileUploadInput = (await screen.findByLabelText( | ||
// /upload file/i | ||
// )) as HTMLInputElement | ||
// Wait for the component to fully load | ||
const fileUploadInput = (await screen.findByLabelText( | ||
/upload file/i | ||
)) as HTMLInputElement | ||
|
||
// // Upload the file | ||
// // Note: we cannot select files via the file picker | ||
// await userEvent.upload(fileUploadInput, INVALID_EMAIL_CSV_FILE) | ||
// expect(fileUploadInput?.files).toHaveLength(1) | ||
// expect(fileUploadInput?.files?.[0]).toBe(INVALID_EMAIL_CSV_FILE) | ||
// Upload the file | ||
// Note: we cannot select files via the file picker | ||
await userEvent.upload(fileUploadInput, INVALID_EMAIL_CSV_FILE) | ||
expect(fileUploadInput?.files).toHaveLength(1) | ||
expect(fileUploadInput?.files?.[0]).toBe(INVALID_EMAIL_CSV_FILE) | ||
|
||
// // Assert that an error message is displayed | ||
// expect( | ||
// await screen.findByText(/error: invalid recipient file/i) | ||
// ).toBeInTheDocument() | ||
// }) | ||
// Assert that an error message is displayed | ||
expect( | ||
await screen.findByText(/error: invalid recipient file/i) | ||
).toBeInTheDocument() | ||
}) |