1
0

files_copy-move.cy.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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, moveFile, copyFile, navigateToFolder } 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. // Prepare initial state
  37. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  38. .mkdir(currentUser, '/new-folder')
  39. cy.login(currentUser)
  40. cy.visit('/apps/files')
  41. copyFile('original.txt', 'new-folder')
  42. navigateToFolder('new-folder')
  43. cy.url().should('contain', 'dir=/new-folder')
  44. getRowForFile('original.txt').should('be.visible')
  45. getRowForFile('new-folder').should('not.exist')
  46. })
  47. it('Can move a file to new folder', () => {
  48. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  49. .mkdir(currentUser, '/new-folder')
  50. cy.login(currentUser)
  51. cy.visit('/apps/files')
  52. moveFile('original.txt', 'new-folder')
  53. // wait until visible again
  54. getRowForFile('new-folder').should('be.visible')
  55. // original should be moved -> not exist anymore
  56. getRowForFile('original.txt').should('not.exist')
  57. navigateToFolder('new-folder')
  58. cy.url().should('contain', 'dir=/new-folder')
  59. getRowForFile('original.txt').should('be.visible')
  60. getRowForFile('new-folder').should('not.exist')
  61. })
  62. /**
  63. * Test for https://github.com/nextcloud/server/issues/41768
  64. */
  65. it('Can move a file to folder with similar name', () => {
  66. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original')
  67. .mkdir(currentUser, '/original folder')
  68. cy.login(currentUser)
  69. cy.visit('/apps/files')
  70. moveFile('original', 'original folder')
  71. // wait until visible again
  72. getRowForFile('original folder').should('be.visible')
  73. // original should be moved -> not exist anymore
  74. getRowForFile('original').should('not.exist')
  75. navigateToFolder('original folder')
  76. cy.url().should('contain', 'dir=/original%20folder')
  77. getRowForFile('original').should('be.visible')
  78. getRowForFile('original folder').should('not.exist')
  79. })
  80. it('Can move a file to its parent folder', () => {
  81. cy.mkdir(currentUser, '/new-folder')
  82. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/new-folder/original.txt')
  83. cy.login(currentUser)
  84. cy.visit('/apps/files')
  85. navigateToFolder('new-folder')
  86. cy.url().should('contain', 'dir=/new-folder')
  87. moveFile('original.txt', '/')
  88. // wait until visible again
  89. cy.get('main').contains('No files in here').should('be.visible')
  90. // original should be moved -> not exist anymore
  91. getRowForFile('original.txt').should('not.exist')
  92. cy.visit('/apps/files')
  93. getRowForFile('new-folder').should('be.visible')
  94. getRowForFile('original.txt').should('be.visible')
  95. })
  96. it('Can copy a file to same folder', () => {
  97. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  98. cy.login(currentUser)
  99. cy.visit('/apps/files')
  100. copyFile('original.txt', '.')
  101. getRowForFile('original.txt').should('be.visible')
  102. getRowForFile('original (copy).txt').should('be.visible')
  103. })
  104. it('Can copy a file multiple times to same folder', () => {
  105. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  106. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original (copy).txt')
  107. cy.login(currentUser)
  108. cy.visit('/apps/files')
  109. copyFile('original.txt', '.')
  110. getRowForFile('original.txt').should('be.visible')
  111. getRowForFile('original (copy 2).txt').should('be.visible')
  112. })
  113. /**
  114. * Test that a copied folder with a dot will be renamed correctly ('foo.bar' -> 'foo.bar (copy)')
  115. * Test for: https://github.com/nextcloud/server/issues/43843
  116. */
  117. it('Can copy a folder to same folder', () => {
  118. cy.mkdir(currentUser, '/foo.bar')
  119. cy.login(currentUser)
  120. cy.visit('/apps/files')
  121. copyFile('foo.bar', '.')
  122. getRowForFile('foo.bar').should('be.visible')
  123. getRowForFile('foo.bar (copy)').should('be.visible')
  124. })
  125. /** Test for https://github.com/nextcloud/server/issues/43329 */
  126. context('escaping file and folder names', () => {
  127. it('Can handle files with special characters', () => {
  128. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  129. .mkdir(currentUser, '/can\'t say')
  130. cy.login(currentUser)
  131. cy.visit('/apps/files')
  132. copyFile('original.txt', 'can\'t say')
  133. navigateToFolder('can\'t say')
  134. cy.url().should('contain', 'dir=/can%27t%20say')
  135. getRowForFile('original.txt').should('be.visible')
  136. getRowForFile('can\'t say').should('not.exist')
  137. })
  138. /**
  139. * If escape is set to false (required for test above) then "<a>foo" would result in "<a>foo</a>" if sanitizing is not disabled
  140. * We should disable it as vue already escapes the text when using v-text
  141. */
  142. it('does not incorrectly sanitize file names', () => {
  143. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  144. .mkdir(currentUser, '/<a href="#">foo')
  145. cy.login(currentUser)
  146. cy.visit('/apps/files')
  147. copyFile('original.txt', '<a href="#">foo')
  148. navigateToFolder('<a href="#">foo')
  149. cy.url().should('contain', 'dir=/%3Ca%20href%3D%22%23%22%3Efoo')
  150. getRowForFile('original.txt').should('be.visible')
  151. getRowForFile('<a href="#">foo').should('not.exist')
  152. })
  153. })
  154. })