aboutsummaryrefslogtreecommitdiffstats
path: root/cypress/e2e/files_trashbin
diff options
context:
space:
mode:
Diffstat (limited to 'cypress/e2e/files_trashbin')
-rw-r--r--cypress/e2e/files_trashbin/files-trash-action.cy.ts69
-rw-r--r--cypress/e2e/files_trashbin/files.cy.ts70
2 files changed, 139 insertions, 0 deletions
diff --git a/cypress/e2e/files_trashbin/files-trash-action.cy.ts b/cypress/e2e/files_trashbin/files-trash-action.cy.ts
new file mode 100644
index 00000000000..090a7ed8d5d
--- /dev/null
+++ b/cypress/e2e/files_trashbin/files-trash-action.cy.ts
@@ -0,0 +1,69 @@
+/*!
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+import type { User } from '@nextcloud/cypress'
+import { deleteFileWithRequest, 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 5 fake files and move them to trash
+ for (let index = 0; index < FILE_COUNT; index++) {
+ cy.uploadContent(user, new Blob(['<content>']), 'text/plain', `/file${index}.txt`)
+ deleteFileWithRequest(user, `/file${index}.txt`)
+ }
+ // login
+ cy.login(user)
+ })
+ })
+
+ it('Can empty trashbin', () => {
+ cy.visit('/apps/files')
+ // Home have no files (or the default welcome file)
+ 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', 1)
+
+ // Trashbin should be empty
+ cy.get('[data-cy-files-list-row-fileid]').should('not.exist')
+ })
+
+ it('Cancelling empty trashbin action does not delete anything', () => {
+ // 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)
+ })
+
+})
diff --git a/cypress/e2e/files_trashbin/files.cy.ts b/cypress/e2e/files_trashbin/files.cy.ts
new file mode 100644
index 00000000000..4c2bce7df7a
--- /dev/null
+++ b/cypress/e2e/files_trashbin/files.cy.ts
@@ -0,0 +1,70 @@
+/*!
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import type { User } from '@nextcloud/cypress'
+
+// @ts-expect-error package has wrong typings
+import { deleteDownloadsFolderBeforeEach } from 'cypress-delete-downloads-folder'
+import { deleteFileWithRequest, getRowForFileId, selectAllFiles, triggerActionForFileId } from '../files/FilesUtils.ts'
+
+describe('files_trashbin: download files', { testIsolation: true }, () => {
+ let user: User
+ const fileids: number[] = []
+
+ deleteDownloadsFolderBeforeEach()
+
+ before(() => {
+ cy.createRandomUser().then(($user) => {
+ user = $user
+
+ cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/file.txt')
+ .then(({ headers }) => fileids.push(Number.parseInt(headers['oc-fileid'])))
+ .then(() => deleteFileWithRequest(user, '/file.txt'))
+ cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/other-file.txt')
+ .then(({ headers }) => fileids.push(Number.parseInt(headers['oc-fileid'])))
+ .then(() => deleteFileWithRequest(user, '/other-file.txt'))
+ })
+ })
+
+ beforeEach(() => {
+ cy.login(user)
+ cy.visit('/apps/files/trashbin')
+ })
+
+ it('can download file', () => {
+ getRowForFileId(fileids[0]).should('be.visible')
+ getRowForFileId(fileids[1]).should('be.visible')
+
+ triggerActionForFileId(fileids[0], 'download')
+
+ const downloadsFolder = Cypress.config('downloadsFolder')
+ cy.readFile(`${downloadsFolder}/file.txt`, { timeout: 15000 })
+ .should('exist')
+ .and('have.length.gt', 8)
+ .and('equal', '<content>')
+ })
+
+ it('can download a file using default action', () => {
+ getRowForFileId(fileids[0])
+ .should('be.visible')
+ .findByRole('button', { name: 'Download' })
+ .click({ force: true })
+
+ const downloadsFolder = Cypress.config('downloadsFolder')
+ cy.readFile(`${downloadsFolder}/file.txt`, { timeout: 15000 })
+ .should('exist')
+ .and('have.length.gt', 8)
+ .and('equal', '<content>')
+ })
+
+ // TODO: Fix this as this dependens on the webdav zip folder plugin not working for trashbin (and never worked with old NC legacy download ajax as well)
+ it('does not offer bulk download', () => {
+ cy.get('[data-cy-files-list-row-checkbox]').should('have.length', 2)
+ selectAllFiles()
+ cy.get('.files-list__selected').should('contain.text', '2 selected')
+ cy.get('[data-cy-files-list-selection-action="restore"]').should('be.visible')
+ cy.get('[data-cy-files-list-selection-action="download"]').should('not.exist')
+ })
+})