Skip to content

Commit

Permalink
refactor: updated snapshots & fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BilalQamar95 committed Jan 26, 2024
1 parent e905543 commit fcc9a05
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 598 deletions.
43 changes: 24 additions & 19 deletions src/editors/containers/VideoUploadEditor/VideoUploader.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,41 @@ describe('VideoUploader', () => {
it('calls onURLUpload when URL submit button is clicked', async () => {
const onVideoUploadSpy = jest.spyOn(hooks, 'onVideoUpload').mockImplementation(() => onURLUploadMock);

const { getByPlaceholderText, getAllByRole } = await renderComponent(store, setLoadingMock);
act(async () => {
const { findByPlaceholderText, findAllByRole } = await renderComponent(store, setLoadingMock);

const urlInput = getByPlaceholderText('Paste your video ID or URL');
const urlSubmitButton = getAllByRole('button', { name: /submit/i });
expect(urlSubmitButton).toHaveLength(1);
const urlInput = await findByPlaceholderText('Paste your video ID or URL');
const urlSubmitButton = await findAllByRole('button', { name: /submit/i });
expect(urlSubmitButton).toHaveLength(1);

fireEvent.change(urlInput, { target: { value: 'https://example.com/video.mp4' } });
urlSubmitButton.forEach((button) => fireEvent.click(button));
expect(onURLUploadMock).toHaveBeenCalledWith('https://example.com/video.mp4');
fireEvent.change(urlInput, { target: { value: 'https://example.com/video.mp4' } });
urlSubmitButton.forEach((button) => fireEvent.click(button));
expect(onURLUploadMock).toHaveBeenCalledWith('https://example.com/video.mp4');

onVideoUploadSpy.mockRestore();
onVideoUploadSpy.mockRestore();
});
});

it('calls handleProcessUpload when file is selected', async () => {
const useDispatchSpy = jest.spyOn(redux, 'useDispatch');
const mockDispatchFn = jest.fn();
useDispatchSpy.mockReturnValue(mockDispatchFn);

const { getByTestId } = await renderComponent(store, setLoadingMock);
act(async () => {
const { findByTestId } = await renderComponent(store, setLoadingMock);

const fileInput = getByTestId('dropzone-container');
const file = new File(['file'], 'video.mp4', {
type: 'video/mp4',
});
Object.defineProperty(fileInput, 'files', {
value: [file],
const fileInput = await findByTestId('dropzone-container');
const file = new File(['file'], 'video.mp4', {
type: 'video/mp4',
});
Object.defineProperty(fileInput, 'files', {
value: [file],
});
fireEvent.drop(fileInput);

// Test dispacting thunkAction
expect(mockDispatchFn).toHaveBeenCalledWith(expect.any(Function));
useDispatchSpy.mockRestore();
});
await act(async () => fireEvent.drop(fileInput));
// Test dispacting thunkAction
expect(mockDispatchFn).toHaveBeenCalledWith(expect.any(Function));
useDispatchSpy.mockRestore();
});
});
Loading

0 comments on commit fcc9a05

Please sign in to comment.