files_copy-move.cy.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. import { getRowForFile, triggerActionForFile } from './FilesUtils.ts'
  23. describe('Files: Move or copy files', { testIsolation: true }, () => {
  24. let currentUser
  25. beforeEach(() => {
  26. cy.createRandomUser().then((user) => {
  27. currentUser = user
  28. cy.login(user)
  29. })
  30. })
  31. afterEach(() => {
  32. // nice to have cleanup
  33. cy.deleteUser(currentUser)
  34. })
  35. it('Can copy a file to new folder', () => {
  36. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  37. .mkdir(currentUser, '/new-folder')
  38. cy.login(currentUser)
  39. cy.visit('/apps/files')
  40. // intercept the move so we can wait for it
  41. cy.intercept('COPY', /\/remote.php\/dav\/files\//).as('copyFile')
  42. getRowForFile('original.txt').should('be.visible')
  43. triggerActionForFile('original.txt', 'move-copy')
  44. // select new folder
  45. cy.get('.file-picker [data-filename="new-folder"]').should('be.visible').click()
  46. // click copy
  47. cy.get('.file-picker').contains('button', 'Copy to new-folder').should('be.visible').click()
  48. // wait for copy to finish
  49. cy.wait('@copyFile')
  50. getRowForFile('new-folder').find('[data-cy-files-list-row-name-link]').click()
  51. cy.url().should('contain', 'dir=/new-folder')
  52. getRowForFile('original.txt').should('be.visible')
  53. getRowForFile('new-folder').should('not.exist')
  54. })
  55. it('Can move a file to new folder', () => {
  56. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  57. .mkdir(currentUser, '/new-folder')
  58. cy.login(currentUser)
  59. cy.visit('/apps/files')
  60. // intercept the move so we can wait for it
  61. cy.intercept('MOVE', /\/remote.php\/dav\/files\//).as('moveFile')
  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 for move to finish
  69. cy.wait('@moveFile')
  70. // wait until visible again
  71. getRowForFile('new-folder').should('be.visible')
  72. // original should be moved -> not exist anymore
  73. getRowForFile('original.txt').should('not.exist')
  74. getRowForFile('new-folder').should('be.visible').find('[data-cy-files-list-row-name-link]').click()
  75. cy.url().should('contain', 'dir=/new-folder')
  76. getRowForFile('original.txt').should('be.visible')
  77. getRowForFile('new-folder').should('not.exist')
  78. })
  79. // This was a bug previously
  80. it('Can move a file to folder with similar name', () => {
  81. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original')
  82. .mkdir(currentUser, '/original folder')
  83. cy.login(currentUser)
  84. cy.visit('/apps/files')
  85. // intercept the move so we can wait for it
  86. cy.intercept('MOVE', /\/remote.php\/dav\/files\//).as('moveFile')
  87. getRowForFile('original').should('be.visible')
  88. triggerActionForFile('original', 'move-copy')
  89. // select new folder
  90. cy.get('.file-picker [data-filename="original folder"]').should('be.visible').click()
  91. // click copy
  92. cy.get('.file-picker').contains('button', 'Move to original folder').should('be.visible').click()
  93. cy.wait('@moveFile')
  94. // wait until visible again
  95. getRowForFile('original folder').should('be.visible')
  96. // original should be moved -> not exist anymore
  97. getRowForFile('original').should('not.exist')
  98. getRowForFile('original folder').should('be.visible').find('[data-cy-files-list-row-name-link]').click()
  99. cy.url().should('contain', 'dir=/original%20folder')
  100. getRowForFile('original').should('be.visible')
  101. getRowForFile('original folder').should('not.exist')
  102. })
  103. it('Can move a file to its parent folder', () => {
  104. cy.mkdir(currentUser, '/new-folder')
  105. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/new-folder/original.txt')
  106. cy.login(currentUser)
  107. cy.visit('/apps/files')
  108. // intercept the move so we can wait for it
  109. cy.intercept('MOVE', /\/remote.php\/dav\/files\//).as('moveFile')
  110. getRowForFile('new-folder').should('be.visible').find('[data-cy-files-list-row-name-link]').click()
  111. cy.url().should('contain', 'dir=/new-folder')
  112. getRowForFile('original.txt').should('be.visible')
  113. triggerActionForFile('original.txt', 'move-copy')
  114. // select new folder
  115. cy.get('.file-picker button[title="Home"]').should('be.visible').click()
  116. // click move
  117. cy.get('.file-picker').contains('button', 'Move').should('be.visible').click()
  118. // wait for move to finish
  119. cy.wait('@moveFile')
  120. // wait until visible again
  121. cy.get('main').contains('No files in here').should('be.visible')
  122. // original should be moved -> not exist anymore
  123. getRowForFile('original.txt').should('not.exist')
  124. cy.visit('/apps/files')
  125. getRowForFile('new-folder').should('be.visible')
  126. getRowForFile('original.txt').should('be.visible')
  127. })
  128. it('Can copy a file to same folder', () => {
  129. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  130. cy.login(currentUser)
  131. cy.visit('/apps/files')
  132. // intercept the copy so we can wait for it
  133. cy.intercept('COPY', /\/remote.php\/dav\/files\//).as('copyFile')
  134. getRowForFile('original.txt').should('be.visible')
  135. triggerActionForFile('original.txt', 'move-copy')
  136. // click copy
  137. cy.get('.file-picker').contains('button', 'Copy').should('be.visible').click()
  138. cy.wait('@copyFile')
  139. getRowForFile('original.txt').should('be.visible')
  140. getRowForFile('original (copy).txt').should('be.visible')
  141. })
  142. it('Can copy a file multiple times to same folder', () => {
  143. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  144. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original (copy).txt')
  145. cy.login(currentUser)
  146. cy.visit('/apps/files')
  147. // intercept the copy so we can wait for it
  148. cy.intercept('COPY', /\/remote.php\/dav\/files\//).as('copyFile')
  149. getRowForFile('original.txt').should('be.visible')
  150. triggerActionForFile('original.txt', 'move-copy')
  151. // click copy
  152. cy.get('.file-picker').contains('button', 'Copy').should('be.visible').click()
  153. cy.wait('@copyFile')
  154. getRowForFile('original.txt').should('be.visible')
  155. getRowForFile('original (copy 2).txt').should('be.visible')
  156. })
  157. })