files-trash-action.cy.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*!
  2. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. import type { User } from '@nextcloud/cypress'
  6. import { deleteFileWithRequest, getRowForFile, triggerActionForFile, triggerFileListAction } from '../files/FilesUtils.ts'
  7. const FILE_COUNT = 5
  8. describe('files_trashbin: Empty trashbin action', { testIsolation: true }, () => {
  9. let user: User
  10. beforeEach(() => {
  11. cy.createRandomUser().then(($user) => {
  12. user = $user
  13. // create 10 fake files
  14. new Array(FILE_COUNT).fill(0).forEach((_, index) => {
  15. cy.uploadContent(user, new Blob(['<content>']), 'text/plain', `/file${index}.txt`)
  16. })
  17. cy.login(user)
  18. cy.visit('/apps/files')
  19. })
  20. })
  21. it('Can delete files', () => {
  22. for (let i = 0; i < FILE_COUNT; i++) {
  23. getRowForFile(`file${i}.txt`).should('be.visible')
  24. }
  25. cy.intercept('DELETE', '**/remote.php/dav/files/**').as('deleteFile')
  26. // Delete all files one by one
  27. for (let i = 0; i < FILE_COUNT; i++) {
  28. triggerActionForFile(`file${i}.txt`, 'delete')
  29. cy.wait('@deleteFile').its('response.statusCode').should('eq', 204)
  30. }
  31. cy.get('@deleteFile.all').should('have.length', FILE_COUNT)
  32. for (let i = 0; i < FILE_COUNT; i++) {
  33. getRowForFile(`file${i}.txt`).should('not.exist')
  34. }
  35. })
  36. it('Can empty trashbin', () => {
  37. // Delete files from home
  38. new Array(FILE_COUNT).fill(0).forEach((_, index) => {
  39. deleteFileWithRequest(user, `/file${index}.txt`)
  40. })
  41. // Home have no files (or the default welcome file)
  42. cy.visit('/apps/files')
  43. cy.get('[data-cy-files-list-row-fileid]').should('have.length', 1)
  44. cy.get('[data-cy-files-list-action="empty-trash"]').should('not.exist')
  45. // Go to trashbin, and see our deleted files
  46. cy.visit('/apps/files/trashbin')
  47. cy.get('[data-cy-files-list-row-fileid]').should('have.length', FILE_COUNT)
  48. // Empty trashbin
  49. cy.intercept('DELETE', '**/remote.php/dav/trashbin/**').as('emptyTrash')
  50. triggerFileListAction('empty-trash')
  51. // Confirm dialog
  52. cy.get('[role=dialog]').should('be.visible')
  53. .findByRole('button', { name: 'Empty deleted files' }).click()
  54. // Wait for the request to finish
  55. cy.wait('@emptyTrash').its('response.statusCode').should('eq', 204)
  56. cy.get('@emptyTrash.all').should('have.length', 1)
  57. // Trashbin should be empty
  58. cy.get('[data-cy-files-list-row-fileid]').should('not.exist')
  59. })
  60. it('Cancelling empty trashbin action does not delete anything', () => {
  61. // Delete files from home
  62. new Array(FILE_COUNT).fill(0).forEach((_, index) => {
  63. deleteFileWithRequest(user, `/file${index}.txt`)
  64. })
  65. // Go to trashbin, and see our deleted files
  66. cy.visit('/apps/files/trashbin')
  67. cy.get('[data-cy-files-list-row-fileid]').should('have.length', FILE_COUNT)
  68. // Empty trashbin
  69. cy.intercept('DELETE', '**/remote.php/dav/trashbin/**').as('emptyTrash')
  70. triggerFileListAction('empty-trash')
  71. // Cancel dialog
  72. cy.get('[role=dialog]').should('be.visible')
  73. .findByRole('button', { name: 'Cancel' }).click()
  74. // request was never sent
  75. cy.get('@emptyTrash').should('not.exist')
  76. cy.get('[data-cy-files-list-row-fileid]').should('have.length', FILE_COUNT)
  77. })
  78. })