From bf28576a982f11c855c807e04a0af13dfed6df6b Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Thu, 1 Dec 2022 15:14:00 +0100 Subject: [PATCH] Fix and add unit tests --- .../upload/useUploadHelpers.spec.ts | 2 ++ .../helpers/resource/actions/upload.spec.ts | 30 ++++++++++++++++--- tests/unit/config/jest.config.js | 3 +- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/packages/web-app-files/tests/unit/composables/upload/useUploadHelpers.spec.ts b/packages/web-app-files/tests/unit/composables/upload/useUploadHelpers.spec.ts index 8d905a9a2b1..6c2e14d3338 100644 --- a/packages/web-app-files/tests/unit/composables/upload/useUploadHelpers.spec.ts +++ b/packages/web-app-files/tests/unit/composables/upload/useUploadHelpers.spec.ts @@ -3,6 +3,7 @@ import { createWrapper } from './spec' import { mockDeep } from 'jest-mock-extended' import { SpaceResource } from 'web-client/src/helpers' import { ComputedRef, computed } from 'vue' +import { UppyService } from 'web-runtime/src/services/uppyService' describe('useUploadHelpers', () => { const currentPathMock = 'path' @@ -17,6 +18,7 @@ describe('useUploadHelpers', () => { () => { const fileName = 'filename' const { inputFilesToUppyFiles } = useUploadHelpers({ + uppyService: mockDeep(), space: mockDeep>(), currentFolder: computed(() => '') }) diff --git a/packages/web-app-files/tests/unit/helpers/resource/actions/upload.spec.ts b/packages/web-app-files/tests/unit/helpers/resource/actions/upload.spec.ts index 8077d078902..3f5aaae41ad 100644 --- a/packages/web-app-files/tests/unit/helpers/resource/actions/upload.spec.ts +++ b/packages/web-app-files/tests/unit/helpers/resource/actions/upload.spec.ts @@ -10,7 +10,7 @@ const getResourcesUploadInstance = ({ currentFiles = [mockDeep()], spaces = [mockDeep()], showMessage = jest.fn(), - uppyService = mockDeep(), + uppyService = mockDeep({ getFailedFiles: jest.fn(() => []) }), createDirectoryTree = jest.fn().mockImplementation(() => ({ failed: [], successful: [] })) }: { space?: SpaceResource @@ -157,7 +157,8 @@ describe('upload helper', () => { const publishStub = jest.fn() const uppyService = mockDeep({ uploadFiles: uploadFilesStub, - publish: publishStub + publish: publishStub, + getFailedFiles: jest.fn(() => []) }) const filesToUpload = [mockDeep()] const resourcesUpload = getResourcesUploadInstance({ uppyService }) @@ -172,7 +173,8 @@ describe('upload helper', () => { const publishStub = jest.fn() const uppyService = mockDeep({ uploadFiles: uploadFilesStub, - publish: publishStub + publish: publishStub, + getFailedFiles: jest.fn(() => []) }) const filesToUpload = [] const resourcesUpload = getResourcesUploadInstance({ uppyService }) @@ -190,7 +192,8 @@ describe('upload helper', () => { const publishStub = jest.fn() const uppyService = mockDeep({ uploadFiles: uploadFilesStub, - publish: publishStub + publish: publishStub, + getFailedFiles: jest.fn(() => []) }) const filesToUpload = [mockDeep({ meta: { relativeFolder: '/parent' } })] const resourcesUpload = getResourcesUploadInstance({ @@ -203,6 +206,25 @@ describe('upload helper', () => { expect(publishStub).toHaveBeenCalledTimes(2) expect(uploadFilesStub).toHaveBeenCalledTimes(0) }) + it('should filter out retries', async () => { + const uploadFilesStub = jest.fn() + const publishStub = jest.fn() + const retryUploadStub = jest.fn() + const filesToUpload = [mockDeep()] + const uppyService = mockDeep({ + uploadFiles: uploadFilesStub, + publish: publishStub, + retryUpload: retryUploadStub, + getFailedFiles: jest.fn(() => filesToUpload) + }) + const resourcesUpload = getResourcesUploadInstance({ uppyService }) + await resourcesUpload.handleUppyFileUpload(mockDeep(), '/', filesToUpload) + + expect(publishStub).toHaveBeenCalledWith('uploadStarted') + expect(publishStub).toHaveBeenCalledTimes(2) + expect(retryUploadStub).toHaveBeenCalled() + expect(uploadFilesStub).not.toHaveBeenCalled() + }) }) describe('method "displayOverwriteDialog"', () => { diff --git a/tests/unit/config/jest.config.js b/tests/unit/config/jest.config.js index a248db0ca36..c824b123b9c 100644 --- a/tests/unit/config/jest.config.js +++ b/tests/unit/config/jest.config.js @@ -24,7 +24,8 @@ module.exports = { '@uppy/core': 'tests/unit/stubs/uppy', '@uppy/xhr-upload': 'tests/unit/stubs/uppy', '@uppy/drop-target': 'tests/unit/stubs/uppy', - '@uppy/tus': 'tests/unit/stubs/uppy' + '@uppy/tus': 'tests/unit/stubs/uppy', + '@uppy/utils': 'tests/unit/stubs/uppy' }, modulePathIgnorePatterns: ['packages/design-system/docs/utils/statusLabels.spec.js'], testEnvironment: 'jsdom',