Skip to content

Commit

Permalink
Add unittests for edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
lookacat committed May 17, 2023
1 parent 317930a commit 47f3d49
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
Expand Up @@ -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)
Expand Down
Expand Up @@ -27,7 +27,8 @@ describe('resourcesTransfer', () => {
{
id: 'a',
name: 'a',
path: '/a'
path: '/a',
type: 'folder'
},
{
id: 'b',
Expand Down Expand Up @@ -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()
})
})

0 comments on commit 47f3d49

Please sign in to comment.