diff --git a/packages/web-app-files/src/helpers/resource/actions/transfer.ts b/packages/web-app-files/src/helpers/resource/actions/transfer.ts index 36fffdb180e..48fb1b8a08a 100644 --- a/packages/web-app-files/src/helpers/resource/actions/transfer.ts +++ b/packages/web-app-files/src/helpers/resource/actions/transfer.ts @@ -129,9 +129,9 @@ export class ResourceTransfer extends ConflictDialog { } // This is for an edge case if an user moves a subfolder with the same name as the parent folder into the parent of the parent folder (which is not possible because of the backend) - private isOverwritingParentFolder(resource, targetFolder, targetFolderResources) { + public isOverwritingParentFolder(resource, targetFolder, targetFolderResources) { if (resource.type !== 'folder') { - return + return false } const folderName = basename(resource.path) const newPath = join(targetFolder.path, folderName) diff --git a/packages/web-app-files/tests/unit/helpers/resource/resourcesTransfer.spec.ts b/packages/web-app-files/tests/unit/helpers/resource/resourcesTransfer.spec.ts index 5f501a0ae70..0dae7862a73 100644 --- a/packages/web-app-files/tests/unit/helpers/resource/resourcesTransfer.spec.ts +++ b/packages/web-app-files/tests/unit/helpers/resource/resourcesTransfer.spec.ts @@ -27,7 +27,8 @@ describe('resourcesTransfer', () => { { id: 'a', name: 'a', - path: '/a' + path: '/a', + type: 'folder' }, { id: 'b', @@ -149,4 +150,41 @@ describe('resourcesTransfer', () => { expect(resourcesTransfer.resolveFileExists).toHaveBeenCalled() }) + it('should show error message if trying to overwrite parent', async () => { + const targetFolderItems = [ + { + id: 'a', + path: 'target/a', + webDavPath: '/target/a', + name: '/target/a' + } + ] + const resourcesTransfer = new ResourceTransfer( + sourceSpace, + resourcesToMove, + targetSpace, + resourcesToMove[0], + clientServiceMock, + loadingServiceMock, + jest.fn(), + jest.fn(), + jest.fn(), + jest.fn(), + jest.fn(), + jest.fn() + ) + const namingClash = await resourcesTransfer.isOverwritingParentFolder( + resourcesToMove[0], + targetFolder, + targetFolderItems + ) + const noNamingClash = await resourcesTransfer.isOverwritingParentFolder( + resourcesToMove[1], + targetFolder, + targetFolderItems + ) + + expect(namingClash).toBeTruthy() + expect(noNamingClash).toBeFalsy() + }) })