files_copy-move.cy.ts 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 { copyFile, getRowForFile, navigateToFolder, 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. /**
  80. * Test for https://github.com/nextcloud/server/issues/41768
  81. */
  82. it('Can move a file to folder with similar name', () => {
  83. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original')
  84. .mkdir(currentUser, '/original folder')
  85. cy.login(currentUser)
  86. cy.visit('/apps/files')
  87. // intercept the move so we can wait for it
  88. cy.intercept('MOVE', /\/remote.php\/dav\/files\//).as('moveFile')
  89. getRowForFile('original').should('be.visible')
  90. triggerActionForFile('original', 'move-copy')
  91. // select new folder
  92. cy.get('.file-picker [data-filename="original folder"]').should('be.visible').click()
  93. // click copy
  94. cy.get('.file-picker').contains('button', 'Move to original folder').should('be.visible').click()
  95. cy.wait('@moveFile')
  96. // wait until visible again
  97. getRowForFile('original folder').should('be.visible')
  98. // original should be moved -> not exist anymore
  99. getRowForFile('original').should('not.exist')
  100. getRowForFile('original folder').should('be.visible').find('[data-cy-files-list-row-name-link]').click()
  101. cy.url().should('contain', 'dir=/original%20folder')
  102. getRowForFile('original').should('be.visible')
  103. getRowForFile('original folder').should('not.exist')
  104. })
  105. it('Can move a file to its parent folder', () => {
  106. cy.mkdir(currentUser, '/new-folder')
  107. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/new-folder/original.txt')
  108. cy.login(currentUser)
  109. cy.visit('/apps/files')
  110. // intercept the move so we can wait for it
  111. cy.intercept('MOVE', /\/remote.php\/dav\/files\//).as('moveFile')
  112. getRowForFile('new-folder').should('be.visible').find('[data-cy-files-list-row-name-link]').click()
  113. cy.url().should('contain', 'dir=/new-folder')
  114. getRowForFile('original.txt').should('be.visible')
  115. triggerActionForFile('original.txt', 'move-copy')
  116. // select new folder
  117. cy.get('.file-picker button[title="Home"]').should('be.visible').click()
  118. // click move
  119. cy.get('.file-picker').contains('button', 'Move').should('be.visible').click()
  120. // wait for move to finish
  121. cy.wait('@moveFile')
  122. // wait until visible again
  123. cy.get('main').contains('No files in here').should('be.visible')
  124. // original should be moved -> not exist anymore
  125. getRowForFile('original.txt').should('not.exist')
  126. cy.visit('/apps/files')
  127. getRowForFile('new-folder').should('be.visible')
  128. getRowForFile('original.txt').should('be.visible')
  129. })
  130. it('Can copy a file to same folder', () => {
  131. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  132. cy.login(currentUser)
  133. cy.visit('/apps/files')
  134. copyFile('original.txt', '.')
  135. getRowForFile('original.txt').should('be.visible')
  136. getRowForFile('original (copy).txt').should('be.visible')
  137. })
  138. it('Can copy a file multiple times to same folder', () => {
  139. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  140. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original (copy).txt')
  141. cy.login(currentUser)
  142. cy.visit('/apps/files')
  143. copyFile('original.txt', '.')
  144. getRowForFile('original.txt').should('be.visible')
  145. getRowForFile('original (copy 2).txt').should('be.visible')
  146. })
  147. /**
  148. * Test that a copied folder with a dot will be renamed correctly ('foo.bar' -> 'foo.bar (copy)')
  149. * Test for: https://github.com/nextcloud/server/issues/43843
  150. */
  151. it('Can copy a folder to same folder', () => {
  152. cy.mkdir(currentUser, '/foo.bar')
  153. cy.login(currentUser)
  154. cy.visit('/apps/files')
  155. // intercept the copy so we can wait for it
  156. cy.intercept('COPY', /\/remote.php\/dav\/files\//).as('copyFile')
  157. getRowForFile('foo.bar').should('be.visible')
  158. triggerActionForFile('foo.bar', 'move-copy')
  159. // click copy
  160. cy.get('.file-picker').contains('button', 'Copy').should('be.visible').click()
  161. cy.wait('@copyFile')
  162. getRowForFile('foo.bar').should('be.visible')
  163. getRowForFile('foo.bar (copy)').should('be.visible')
  164. })
  165. /** Test for https://github.com/nextcloud/server/issues/43329 */
  166. context('escaping file and folder names', () => {
  167. it('Can handle files with special characters', () => {
  168. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  169. .mkdir(currentUser, '/can\'t say')
  170. cy.login(currentUser)
  171. cy.visit('/apps/files')
  172. copyFile('original.txt', 'can\'t say')
  173. navigateToFolder('can\'t say')
  174. cy.url().should('contain', 'dir=/can%27t%20say')
  175. getRowForFile('original.txt').should('be.visible')
  176. getRowForFile('can\'t say').should('not.exist')
  177. })
  178. /**
  179. * If escape is set to false (required for test above) then "<a>foo" would result in "<a>foo</a>" if sanitizing is not disabled
  180. * We should disable it as vue already escapes the text when using v-text
  181. */
  182. it('does not incorrectly sanitize file names', () => {
  183. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  184. .mkdir(currentUser, '/<a href="#">foo')
  185. cy.login(currentUser)
  186. cy.visit('/apps/files')
  187. copyFile('original.txt', '<a href="#">foo')
  188. navigateToFolder('<a href="#">foo')
  189. cy.url().should('contain', 'dir=/%3Ca%20href%3D%22%23%22%3Efoo')
  190. getRowForFile('original.txt').should('be.visible')
  191. getRowForFile('<a href="#">foo').should('not.exist')
  192. })
  193. })
  194. })