From fcc9a054ce5dd39f3bb12555066388194bd468b6 Mon Sep 17 00:00:00 2001 From: Bilal Qamar <59555732+BilalQamar95@users.noreply.github.com> Date: Fri, 26 Jan 2024 18:23:43 +0500 Subject: [PATCH] refactor: updated snapshots & fixed failing tests --- .../VideoUploadEditor/VideoUploader.test.jsx | 43 +-- .../__snapshots__/VideoUploader.test.jsx.snap | 312 ++---------------- .../__snapshots__/index.test.jsx.snap | 308 ++--------------- .../VideoUploadEditor/index.test.jsx | 20 +- 4 files changed, 85 insertions(+), 598 deletions(-) diff --git a/src/editors/containers/VideoUploadEditor/VideoUploader.test.jsx b/src/editors/containers/VideoUploadEditor/VideoUploader.test.jsx index 06376c7f7..a456a068f 100644 --- a/src/editors/containers/VideoUploadEditor/VideoUploader.test.jsx +++ b/src/editors/containers/VideoUploadEditor/VideoUploader.test.jsx @@ -59,17 +59,19 @@ 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 () => { @@ -77,18 +79,21 @@ describe('VideoUploader', () => { 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(); }); }); diff --git a/src/editors/containers/VideoUploadEditor/__snapshots__/VideoUploader.test.jsx.snap b/src/editors/containers/VideoUploadEditor/__snapshots__/VideoUploader.test.jsx.snap index 5a4f1efbc..17dacd830 100644 --- a/src/editors/containers/VideoUploadEditor/__snapshots__/VideoUploader.test.jsx.snap +++ b/src/editors/containers/VideoUploadEditor/__snapshots__/VideoUploader.test.jsx.snap @@ -6,312 +6,56 @@ Object { "baseElement":
+ An unexpected error occurred. Please click the button below to refresh the page. +
+ An unexpected error occurred. Please click the button below to refresh the page. +