diff options
author | skjnldsv <skjnldsv@protonmail.com> | 2024-12-12 11:52:43 +0100 |
---|---|---|
committer | Christopher Ng <chrng8@gmail.com> | 2024-12-12 10:08:38 -0800 |
commit | 46573b75a6ca3157b0eaa1b4e2ee0624697b723d (patch) | |
tree | 30572c73dc999a343f33d86ef0ef11a919dba281 /cypress | |
parent | 34299e6a5d9bcbdb6af0d49da26e85f236701349 (diff) | |
download | nextcloud-server-46573b75a6ca3157b0eaa1b4e2ee0624697b723d.tar.gz nextcloud-server-46573b75a6ca3157b0eaa1b4e2ee0624697b723d.zip |
feat(files_trashbin): add cypress tests
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
Diffstat (limited to 'cypress')
-rw-r--r-- | cypress/e2e/files/FilesUtils.ts | 32 | ||||
-rw-r--r-- | cypress/e2e/files_trashbin/files-list-action.cy.ts | 99 |
2 files changed, 127 insertions, 4 deletions
diff --git a/cypress/e2e/files/FilesUtils.ts b/cypress/e2e/files/FilesUtils.ts index 6a62ff77e86..932897918de 100644 --- a/cypress/e2e/files/FilesUtils.ts +++ b/cypress/e2e/files/FilesUtils.ts @@ -3,6 +3,8 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ +import type { User } from "@nextcloud/cypress" + export const getRowForFileId = (fileid: number) => cy.get(`[data-cy-files-list-row-fileid="${fileid}"]`) export const getRowForFile = (filename: string) => cy.get(`[data-cy-files-list-row-name="${CSS.escape(filename)}"]`) @@ -13,16 +15,16 @@ export const getActionButtonForFileId = (fileid: number) => getActionsForFileId( export const getActionButtonForFile = (filename: string) => getActionsForFile(filename).findByRole('button', { name: 'Actions' }) export const triggerActionForFileId = (fileid: number, actionId: string) => { - getActionButtonForFileId(fileid).click() + getActionButtonForFileId(fileid).click({ force: true }) // Getting the last button to avoid the one from popup fading out cy.get(`[data-cy-files-list-row-action="${CSS.escape(actionId)}"] > button`).last() - .should('exist').click() + .should('exist').click({ force: true }) } export const triggerActionForFile = (filename: string, actionId: string) => { - getActionButtonForFile(filename).click() + getActionButtonForFile(filename).click({ force: true }) // Getting the last button to avoid the one from popup fading out cy.get(`[data-cy-files-list-row-action="${CSS.escape(actionId)}"] > button`).last() - .should('exist').click() + .should('exist').click({ force: true }) } export const triggerInlineActionForFileId = (fileid: number, actionId: string) => { @@ -184,3 +186,25 @@ export const haveValidity = (validity: string | RegExp) => { } return (el: JQuery<HTMLElement>) => expect((el.get(0) as HTMLInputElement).validationMessage).to.match(validity) } + +export const deleteFileWithRequest = (user: User, path: string) => { + // Ensure path starts with a slash and has no double slashes + path = `/${path}`.replace(/\/+/g, '/') + + cy.request('/csrftoken').then(({ body }) => { + const requestToken = body.token + cy.request({ + method: 'DELETE', + url: `${Cypress.env('baseUrl')}/remote.php/dav/files/${user.userId}` + path, + headers: { + requestToken, + }, + retryOnStatusCodeFailure: true, + }) + }) +} + +export const triggerFileListAction = (actionId: string) => { + cy.get(`button[data-cy-files-list-action="${CSS.escape(actionId)}"]`).last() + .should('exist').click({ force: true }) +} diff --git a/cypress/e2e/files_trashbin/files-list-action.cy.ts b/cypress/e2e/files_trashbin/files-list-action.cy.ts new file mode 100644 index 00000000000..e1fe2364e12 --- /dev/null +++ b/cypress/e2e/files_trashbin/files-list-action.cy.ts @@ -0,0 +1,99 @@ +/*! + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import type { User } from '@nextcloud/cypress' +import { deleteFileWithRequest, getRowForFile, triggerActionForFile, triggerFileListAction } from '../files/FilesUtils.ts' + +const FILE_COUNT = 5 +describe('files_trashbin: Empty trashbin action', { testIsolation: true }, () => { + let user: User + + beforeEach(() => { + cy.createRandomUser().then(($user) => { + user = $user + // create 10 fake files + new Array(FILE_COUNT).fill(0).forEach((_, index) => { + cy.uploadContent(user, new Blob(['<content>']), 'text/plain', `/file${index}.txt`) + }) + + cy.login(user) + cy.visit('/apps/files') + }) + }) + + it('Can delete files', () => { + for (let i = 0; i < FILE_COUNT; i++) { + getRowForFile(`file${i}.txt`).should('be.visible') + } + + cy.intercept('DELETE', '**/remote.php/dav/files/**').as('deleteFile') + + // Delete all files one by one + for (let i = 0; i < FILE_COUNT; i++) { + triggerActionForFile(`file${i}.txt`, 'delete') + cy.wait('@deleteFile').its('response.statusCode').should('eq', 204) + } + + cy.get('@deleteFile.all').should('have.length', FILE_COUNT) + + for (let i = 0; i < FILE_COUNT; i++) { + getRowForFile(`file${i}.txt`).should('not.exist') + } + }) + + it('Can empty trashbin', () => { + // Delete files from home + new Array(FILE_COUNT).fill(0).forEach((_, index) => { + deleteFileWithRequest(user, `/file${index}.txt`) + }) + + // Home have no files (or the default welcome file) + cy.visit('/apps/files') + cy.get('[data-cy-files-list-row-fileid]').should('have.length', 1) + cy.get('[data-cy-files-list-action="empty-trash"]').should('not.exist') + + // Go to trashbin, and see our deleted files + cy.visit('/apps/files/trashbin') + cy.get('[data-cy-files-list-row-fileid]').should('have.length', FILE_COUNT) + + // Empty trashbin + cy.intercept('DELETE', '**/remote.php/dav/trashbin/**').as('emptyTrash') + triggerFileListAction('empty-trash') + + // Confirm dialog + cy.get('[role=dialog]').should('be.visible') + .findByRole('button', { name: 'Empty deleted files' }).click() + + // Wait for the request to finish + cy.wait('@emptyTrash').its('response.statusCode').should('eq', 204) + cy.get('@emptyTrash.all').should('have.length', FILE_COUNT) + + // Trashbin should be empty + cy.get('[data-cy-files-list-row-fileid]').should('not.exist') + }) + + it('Cancelling empty trashbin action does not delete anything', () => { + // Delete files from home + new Array(FILE_COUNT).fill(0).forEach((_, index) => { + deleteFileWithRequest(user, `/file${index}.txt`) + }) + + // Go to trashbin, and see our deleted files + cy.visit('/apps/files/trashbin') + cy.get('[data-cy-files-list-row-fileid]').should('have.length', FILE_COUNT) + + // Empty trashbin + cy.intercept('DELETE', '**/remote.php/dav/trashbin/**').as('emptyTrash') + triggerFileListAction('empty-trash') + + // Cancel dialog + cy.get('[role=dialog]').should('be.visible') + .findByRole('button', { name: 'Cancel' }).click() + + // request was never sent + cy.get('@emptyTrash').should('not.exist') + cy.get('[data-cy-files-list-row-fileid]').should('have.length', FILE_COUNT) + }) + +}) |