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
Showing
6 changed files
with
89 additions
and
34 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
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,61 @@ | ||
import { render, fireEvent, screen, waitFor } from '@testing-library/react'; | ||
import { UploadDropzone } from './UploadDropzone'; | ||
import { FunnelType } from 'src/funnel.types'; | ||
|
||
const mockFunnel: FunnelType = { | ||
name: 'My Custom Funnel', | ||
bgColor: '#ffffff', | ||
pages: [ | ||
{ | ||
id: 'page-1', | ||
blocks: [ | ||
{ | ||
id: 'image-1', | ||
type: 'image', | ||
src: 'https://example.com/image.jpg', | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
// Create a Blob that looks like a File. | ||
const invalidFunnelFile = new File(['(⌐□_□)'], 'funnel.json', { type: 'application/json' }); | ||
const validFunnelFile = new File([JSON.stringify(mockFunnel)], 'funnel.json', { | ||
type: 'application/json', | ||
}); | ||
|
||
describe('UploadDropzone', () => { | ||
it('handles invalid files', async () => { | ||
// prepare | ||
const onUploadSuccess = jest.fn(); | ||
const { getByLabelText } = render(<UploadDropzone onUploadSuccess={onUploadSuccess} />); | ||
|
||
// act | ||
fireEvent.change(getByLabelText(/upload your own JSON file/i), { | ||
target: { files: [invalidFunnelFile] }, | ||
}); | ||
|
||
// assert | ||
expect(await screen.findByText('Oops!')).toBeVisible(); | ||
expect(onUploadSuccess).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('handles valid json and previews them right away', async () => { | ||
// prepare | ||
const onUploadSuccess = jest.fn(); | ||
render(<UploadDropzone onUploadSuccess={onUploadSuccess} />); | ||
|
||
//act | ||
fireEvent.change(screen.getByLabelText(/upload your own JSON file/i), { | ||
target: { files: [validFunnelFile] }, | ||
}); | ||
|
||
// assert | ||
await waitFor(() => { | ||
expect(onUploadSuccess).toHaveBeenCalledWith(expect.objectContaining(mockFunnel)); | ||
}); | ||
|
||
expect(screen.queryByText('Oops!')).not.toBeInTheDocument(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"jsx": "react-jsx" // this is necessary for Jest to run properly, but Nextjs doesnt like it | ||
} | ||
} |
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