Skip to content

Commit

Permalink
Merge pull request #2807 from nextcloud/enh/fix-deletion-from-trashbin
Browse files Browse the repository at this point in the history
chore: Add cypress test for deletion from trashbin
  • Loading branch information
susnux authored Jul 24, 2024
2 parents b2f7638 + 21a7470 commit 9549ba8
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cypress/e2e/groupfolders.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import {
createGroupFolder,
deleteGroupFolder,
deleteFile,
deleteFileFromTrashbin,
deleteFolder,
deleteFolderFromTrashbin,
enableACLPermissions,
enterFolder,
enterFolderInTrashbin,
Expand Down Expand Up @@ -276,4 +278,42 @@ describe('Groupfolders ACLs and trashbin behavior', () => {
cy.visit('/apps/files/trashbin')
fileOrFolderDoesNotExistInTrashbin('file1.txt')
})

it('ACL, delete and delete from trash', () => {
// Create two subfolders and two files as manager
cy.login(managerUser)
cy.mkdir(managerUser, `/${groupFolderName}/subfolder1`)
cy.mkdir(managerUser, `/${groupFolderName}/subfolder1/subfolder2`)
cy.uploadContent(managerUser, new Blob(['Content of the file']), 'text/plain', `/${groupFolderName}/subfolder1/file1.txt`)
cy.uploadContent(managerUser, new Blob(['Content of the file']), 'text/plain', `/${groupFolderName}/subfolder1/subfolder2/file2.txt`)

// Set ACL permissions
setACLPermissions(groupFolderId, '/subfolder1', [`+${PERMISSION_READ}`,`-${PERMISSION_WRITE}`], undefined, user1.userId)
setACLPermissions(groupFolderId, '/subfolder1', [`-${PERMISSION_READ}`], undefined, user2.userId)

// Delete files
cy.log('Deleting the files')
cy.logout()
cy.login(managerUser)
cy.visit('/apps/files')
enterFolder(groupFolderName)
enterFolder('subfolder1')
deleteFile('file1.txt')
cy.visit('/apps/files')
enterFolder(groupFolderName)
enterFolder('subfolder1')
deleteFolder('subfolder2')

// Delete files from trash
cy.log('Deleting the files permanently')
cy.logout()
cy.login(managerUser)
cy.visit('/apps/files/trashbin')
fileOrFolderExistsInTrashbin('file1.txt')
deleteFileFromTrashbin('file1.txt')
fileOrFolderExistsInTrashbin('subfolder2')
deleteFolderFromTrashbin('subfolder2')
fileOrFolderDoesNotExistInTrashbin('file1.txt')
fileOrFolderDoesNotExistInTrashbin('subfolder2')
})
})
25 changes: 25 additions & 0 deletions cypress/e2e/groupfoldersUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ export function deleteFolder(name: string) {
cy.wait('@delete').its('response.statusCode').should('eq', 204)
}

export function deleteFolderFromTrashbin(name: string) {
cy.intercept({ times: 1, method: 'DELETE', url: `**/dav/trashbin/**/${name}.d*` }).as('delete')
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name^="${name}.d"] [data-cy-files-list-row-actions] button:not([data-cy-files-list-row-action])`).click()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-action="delete"]`).should('be.visible')
cy.get(`[data-cy-files-list] [data-cy-files-list-row-action="delete"]`).scrollIntoView()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-action="delete"]`).click()
cy.wait('@delete').its('response.statusCode').should('eq', 204)
}

export function deleteFile(name: string) {
cy.intercept({ times: 1, method: 'DELETE', url: `**/dav/files/**/${name}` }).as('delete')
// For files wait for preview to load and release lock
Expand All @@ -135,6 +144,22 @@ export function deleteFile(name: string) {
cy.wait('@delete').its('response.statusCode').should('eq', 204)
}

export function deleteFileFromTrashbin(name: string) {
cy.intercept({ times: 1, method: 'DELETE', url: `**/dav/trashbin/**/${name}.d*` }).as('delete')
// For files wait for preview to load and release lock
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name^="${name}.d"] .files-list__row-icon img`)
.should('be.visible')
.and(($img) => {
// "naturalWidth" and "naturalHeight" are set when the image loads
expect($img[0].naturalWidth, 'image has natural width').to.be.greaterThan(0)
})
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name^="${name}.d"] [data-cy-files-list-row-actions] button:not([data-cy-files-list-row-action])`).click()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-action="delete"]`).should('be.visible')
cy.get(`[data-cy-files-list] [data-cy-files-list-row-action="delete"]`).scrollIntoView()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-action="delete"]`).click()
cy.wait('@delete').its('response.statusCode').should('eq', 204)
}

export function restoreFile(name: string) {
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name^="${name}.d"] [data-cy-files-list-row-action="restore"]`).click()
}

0 comments on commit 9549ba8

Please sign in to comment.