-
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
9ca0e3a
commit f054079
Showing
6 changed files
with
878 additions
and
869 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
198 changes: 99 additions & 99 deletions
198
frontend/src/components/dashboard/create/sms/tests/SMSRecipients.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,114 +1,114 @@ | ||
// 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 SMSRecipients from '../SMSRecipients' | ||
import SMSRecipients from '../SMSRecipients' | ||
|
||
// import { SMSCampaign } from 'classes' | ||
// import CampaignContextProvider from 'contexts/campaign.context' | ||
// import FinishLaterModalContextProvider from 'contexts/finish-later.modal.context' | ||
// import { | ||
// screen, | ||
// mockCommonApis, | ||
// server, | ||
// render, | ||
// Campaign, | ||
// INVALID_MOBILE_CSV_FILE, | ||
// } from 'test-utils' | ||
import { SMSCampaign } from 'classes' | ||
import CampaignContextProvider from 'contexts/campaign.context' | ||
import FinishLaterModalContextProvider from 'contexts/finish-later.modal.context' | ||
import { | ||
screen, | ||
mockCommonApis, | ||
server, | ||
render, | ||
Campaign, | ||
INVALID_MOBILE_CSV_FILE, | ||
} from 'test-utils' | ||
|
||
// const TEST_SMS_CAMPAIGN: Campaign = { | ||
// id: 1, | ||
// name: 'Test SMS campaign', | ||
// type: 'SMS', | ||
// 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, | ||
// sms_templates: { | ||
// body: 'Test body', | ||
// params: [], | ||
// }, | ||
// has_credential: false, | ||
// } | ||
const TEST_SMS_CAMPAIGN: Campaign = { | ||
id: 1, | ||
name: 'Test SMS campaign', | ||
type: 'SMS', | ||
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, | ||
sms_templates: { | ||
body: 'Test body', | ||
params: [], | ||
}, | ||
has_credential: false, | ||
} | ||
|
||
// function mockApis() { | ||
// const { handlers } = mockCommonApis({ | ||
// curUserId: 1, // Start authenticated | ||
function mockApis() { | ||
const { handlers } = mockCommonApis({ | ||
curUserId: 1, // Start authenticated | ||
|
||
// // Start with an SMS campaign with a saved template | ||
// campaigns: [{ ...TEST_SMS_CAMPAIGN }], | ||
// }) | ||
// return handlers | ||
// } | ||
// Start with an SMS campaign with a saved template | ||
campaigns: [{ ...TEST_SMS_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 SMSCampaign({ ...TEST_SMS_CAMPAIGN })} | ||
// > | ||
// <FinishLaterModalContextProvider> | ||
// <SMSRecipients setActiveStep={setActiveStep} /> | ||
// </FinishLaterModalContextProvider> | ||
// </CampaignContextProvider> | ||
// } | ||
// /> | ||
// </Routes>, | ||
// { | ||
// router: { initialIndex: 0, initialEntries: ['/campaigns/1'] }, | ||
// } | ||
// ) | ||
// } | ||
render( | ||
<Routes> | ||
<Route | ||
path="/campaigns/:id" | ||
element={ | ||
<CampaignContextProvider | ||
initialCampaign={new SMSCampaign({ ...TEST_SMS_CAMPAIGN })} | ||
> | ||
<FinishLaterModalContextProvider> | ||
<SMSRecipients 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_MOBILE_CSV_FILE) | ||
// expect(fileUploadInput?.files).toHaveLength(1) | ||
// expect(fileUploadInput?.files?.[0]).toBe(INVALID_MOBILE_CSV_FILE) | ||
// Upload the file | ||
// Note: we cannot select files via the file picker | ||
await userEvent.upload(fileUploadInput, INVALID_MOBILE_CSV_FILE) | ||
expect(fileUploadInput?.files).toHaveLength(1) | ||
expect(fileUploadInput?.files?.[0]).toBe(INVALID_MOBILE_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() | ||
}) |
Oops, something went wrong.