Skip to content

Commit

Permalink
Fix and add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Dec 2, 2022
1 parent 141e755 commit 995e08c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -17,6 +18,7 @@ describe('useUploadHelpers', () => {
() => {
const fileName = 'filename'
const { inputFilesToUppyFiles } = useUploadHelpers({
uppyService: mockDeep<UppyService>(),
space: mockDeep<ComputedRef<SpaceResource>>(),
currentFolder: computed(() => '')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const getResourcesUploadInstance = ({
currentFiles = [mockDeep<Resource>()],
spaces = [mockDeep<SpaceResource>()],
showMessage = jest.fn(),
uppyService = mockDeep<UppyService>(),
uppyService = mockDeep<UppyService>({ getFailedFiles: jest.fn(() => []) }),
createDirectoryTree = jest.fn().mockImplementation(() => ({ failed: [], successful: [] }))
}: {
space?: SpaceResource
Expand Down Expand Up @@ -157,7 +157,8 @@ describe('upload helper', () => {
const publishStub = jest.fn()
const uppyService = mockDeep<UppyService>({
uploadFiles: uploadFilesStub,
publish: publishStub
publish: publishStub,
getFailedFiles: jest.fn(() => [])
})
const filesToUpload = [mockDeep<UppyResource>()]
const resourcesUpload = getResourcesUploadInstance({ uppyService })
Expand All @@ -172,7 +173,8 @@ describe('upload helper', () => {
const publishStub = jest.fn()
const uppyService = mockDeep<UppyService>({
uploadFiles: uploadFilesStub,
publish: publishStub
publish: publishStub,
getFailedFiles: jest.fn(() => [])
})
const filesToUpload = []
const resourcesUpload = getResourcesUploadInstance({ uppyService })
Expand All @@ -190,7 +192,8 @@ describe('upload helper', () => {
const publishStub = jest.fn()
const uppyService = mockDeep<UppyService>({
uploadFiles: uploadFilesStub,
publish: publishStub
publish: publishStub,
getFailedFiles: jest.fn(() => [])
})
const filesToUpload = [mockDeep<UppyResource>({ meta: { relativeFolder: '/parent' } })]
const resourcesUpload = getResourcesUploadInstance({
Expand All @@ -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<UppyResource>()]
const uppyService = mockDeep<UppyService>({
uploadFiles: uploadFilesStub,
publish: publishStub,
retryUpload: retryUploadStub,
getFailedFiles: jest.fn(() => filesToUpload)
})
const resourcesUpload = getResourcesUploadInstance({ uppyService })
await resourcesUpload.handleUppyFileUpload(mockDeep<SpaceResource>(), '/', filesToUpload)

expect(publishStub).toHaveBeenCalledWith('uploadStarted')
expect(publishStub).toHaveBeenCalledTimes(2)
expect(retryUploadStub).toHaveBeenCalled()
expect(uploadFilesStub).not.toHaveBeenCalled()
})
})

describe('method "displayOverwriteDialog"', () => {
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ module.exports = {
'@uppy/core': '<rootDir>tests/unit/stubs/uppy',
'@uppy/xhr-upload': '<rootDir>tests/unit/stubs/uppy',
'@uppy/drop-target': '<rootDir>tests/unit/stubs/uppy',
'@uppy/tus': '<rootDir>tests/unit/stubs/uppy'
'@uppy/tus': '<rootDir>tests/unit/stubs/uppy',
'@uppy/utils': '<rootDir>tests/unit/stubs/uppy'
},
modulePathIgnorePatterns: ['packages/design-system/docs/utils/statusLabels.spec.js'],
testEnvironment: 'jsdom',
Expand Down

0 comments on commit 995e08c

Please sign in to comment.