Skip to content

Commit

Permalink
chore: fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KishenKumarrrrr committed Feb 8, 2024
1 parent 9e51680 commit 9f9bf40
Show file tree
Hide file tree
Showing 6 changed files with 973 additions and 973 deletions.
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()
// })

0 comments on commit 9f9bf40

Please sign in to comment.