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 26, 2023
1 parent 6625b78 commit 86dbc77
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 86dbc77

Please sign in to comment.