Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add cypress test for deletion from trashbin #2807

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
Loading