files_copy-move.cy.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * @copyright Copyright (c) 2023 Ferdinand Thiessen <opensource@fthiessen.de>
  3. *
  4. * @author Ferdinand Thiessen <opensource@fthiessen.de>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. const getRowForFile = (filename: string) => cy.get(`[data-cy-files-list-row-name="${filename}"]`)
  23. const getActionsForFile = (filename: string) => getRowForFile(filename).find('[data-cy-files-list-row-actions]')
  24. const getActionButtonForFile = (filename: string) => getActionsForFile(filename).find('button[aria-label="Actions"]')
  25. const triggerActionForFile = (filename: string, actionId: string) => {
  26. getActionButtonForFile(filename).click()
  27. cy.get(`[data-cy-files-list-row-action="${actionId}"] > button`).should('exist').click()
  28. }
  29. describe('Files: Move or copy files', { testIsolation: true }, () => {
  30. let currentUser
  31. beforeEach(() => {
  32. cy.createRandomUser().then((user) => {
  33. currentUser = user
  34. cy.login(user)
  35. })
  36. })
  37. afterEach(() => {
  38. // nice to have cleanup
  39. cy.deleteUser(currentUser)
  40. })
  41. it('Can copy a file to new folder', () => {
  42. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  43. .mkdir(currentUser, '/new-folder')
  44. cy.login(currentUser)
  45. cy.visit('/apps/files')
  46. getRowForFile('original.txt').should('be.visible')
  47. triggerActionForFile('original.txt', 'move-copy')
  48. // select new folder
  49. cy.get('.file-picker [data-filename="new-folder"]').should('be.visible').click()
  50. // click copy
  51. cy.get('.file-picker').contains('button', 'Copy to new-folder').should('be.visible').click()
  52. getRowForFile('new-folder').find('[data-cy-files-list-row-name-link]').click()
  53. cy.url().should('contain', 'dir=/new-folder')
  54. getRowForFile('original.txt').should('be.visible')
  55. getRowForFile('new-folder').should('not.exist')
  56. })
  57. it('Can move a file to new folder', () => {
  58. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  59. .mkdir(currentUser, '/new-folder')
  60. cy.login(currentUser)
  61. cy.visit('/apps/files')
  62. getRowForFile('original.txt').should('be.visible')
  63. triggerActionForFile('original.txt', 'move-copy')
  64. // select new folder
  65. cy.get('.file-picker [data-filename="new-folder"]').should('be.visible').click()
  66. // click copy
  67. cy.get('.file-picker').contains('button', 'Move to new-folder').should('be.visible').click()
  68. // wait until visible again
  69. getRowForFile('new-folder').should('be.visible')
  70. // original should be moved -> not exist anymore
  71. getRowForFile('original.txt').should('not.exist')
  72. getRowForFile('new-folder').should('be.visible').find('[data-cy-files-list-row-name-link]').click()
  73. cy.url().should('contain', 'dir=/new-folder')
  74. getRowForFile('original.txt').should('be.visible')
  75. getRowForFile('new-folder').should('not.exist')
  76. })
  77. it('Can move a file to its parent folder', () => {
  78. cy.mkdir(currentUser, '/new-folder')
  79. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/new-folder/original.txt')
  80. cy.login(currentUser)
  81. cy.visit('/apps/files')
  82. getRowForFile('new-folder').should('be.visible').find('[data-cy-files-list-row-name-link]').click()
  83. cy.url().should('contain', 'dir=/new-folder')
  84. getRowForFile('original.txt').should('be.visible')
  85. triggerActionForFile('original.txt', 'move-copy')
  86. // select new folder
  87. cy.get('.file-picker a[title="Home"]').should('be.visible').click()
  88. // click move
  89. cy.get('.file-picker').contains('button', 'Move').should('be.visible').click()
  90. // wait until visible again
  91. cy.get('main').contains('No files in here').should('be.visible')
  92. // original should be moved -> not exist anymore
  93. getRowForFile('original.txt').should('not.exist')
  94. cy.visit('/apps/files')
  95. getRowForFile('new-folder').should('be.visible')
  96. getRowForFile('original.txt').should('be.visible')
  97. })
  98. })