1
0

files_copy-move.cy.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /**
  2. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. import { getRowForFile, moveFile, copyFile, navigateToFolder } from './FilesUtils.ts'
  6. describe('Files: Move or copy files', { testIsolation: true }, () => {
  7. let currentUser
  8. beforeEach(() => {
  9. cy.createRandomUser().then((user) => {
  10. currentUser = user
  11. cy.login(user)
  12. })
  13. })
  14. afterEach(() => {
  15. // nice to have cleanup
  16. cy.deleteUser(currentUser)
  17. })
  18. it('Can copy a file to new folder', () => {
  19. // Prepare initial state
  20. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  21. .mkdir(currentUser, '/new-folder')
  22. cy.login(currentUser)
  23. cy.visit('/apps/files')
  24. copyFile('original.txt', 'new-folder')
  25. navigateToFolder('new-folder')
  26. cy.url().should('contain', 'dir=/new-folder')
  27. getRowForFile('original.txt').should('be.visible')
  28. getRowForFile('new-folder').should('not.exist')
  29. })
  30. it('Can move a file to new folder', () => {
  31. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  32. .mkdir(currentUser, '/new-folder')
  33. cy.login(currentUser)
  34. cy.visit('/apps/files')
  35. moveFile('original.txt', 'new-folder')
  36. // wait until visible again
  37. getRowForFile('new-folder').should('be.visible')
  38. // original should be moved -> not exist anymore
  39. getRowForFile('original.txt').should('not.exist')
  40. navigateToFolder('new-folder')
  41. cy.url().should('contain', 'dir=/new-folder')
  42. getRowForFile('original.txt').should('be.visible')
  43. getRowForFile('new-folder').should('not.exist')
  44. })
  45. /**
  46. * Test for https://github.com/nextcloud/server/issues/41768
  47. */
  48. it('Can move a file to folder with similar name', () => {
  49. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original')
  50. .mkdir(currentUser, '/original folder')
  51. cy.login(currentUser)
  52. cy.visit('/apps/files')
  53. moveFile('original', 'original folder')
  54. // wait until visible again
  55. getRowForFile('original folder').should('be.visible')
  56. // original should be moved -> not exist anymore
  57. getRowForFile('original').should('not.exist')
  58. navigateToFolder('original folder')
  59. cy.url().should('contain', 'dir=/original%20folder')
  60. getRowForFile('original').should('be.visible')
  61. getRowForFile('original folder').should('not.exist')
  62. })
  63. it('Can move a file to its parent folder', () => {
  64. cy.mkdir(currentUser, '/new-folder')
  65. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/new-folder/original.txt')
  66. cy.login(currentUser)
  67. cy.visit('/apps/files')
  68. navigateToFolder('new-folder')
  69. cy.url().should('contain', 'dir=/new-folder')
  70. moveFile('original.txt', '/')
  71. // wait until visible again
  72. cy.get('main').contains('No files in here').should('be.visible')
  73. // original should be moved -> not exist anymore
  74. getRowForFile('original.txt').should('not.exist')
  75. cy.visit('/apps/files')
  76. getRowForFile('new-folder').should('be.visible')
  77. getRowForFile('original.txt').should('be.visible')
  78. })
  79. it('Can copy a file to same folder', () => {
  80. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  81. cy.login(currentUser)
  82. cy.visit('/apps/files')
  83. copyFile('original.txt', '.')
  84. getRowForFile('original.txt').should('be.visible')
  85. getRowForFile('original (copy).txt').should('be.visible')
  86. })
  87. it('Can copy a file multiple times to same folder', () => {
  88. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  89. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original (copy).txt')
  90. cy.login(currentUser)
  91. cy.visit('/apps/files')
  92. copyFile('original.txt', '.')
  93. getRowForFile('original.txt').should('be.visible')
  94. getRowForFile('original (copy 2).txt').should('be.visible')
  95. })
  96. /**
  97. * Test that a copied folder with a dot will be renamed correctly ('foo.bar' -> 'foo.bar (copy)')
  98. * Test for: https://github.com/nextcloud/server/issues/43843
  99. */
  100. it('Can copy a folder to same folder', () => {
  101. cy.mkdir(currentUser, '/foo.bar')
  102. cy.login(currentUser)
  103. cy.visit('/apps/files')
  104. copyFile('foo.bar', '.')
  105. getRowForFile('foo.bar').should('be.visible')
  106. getRowForFile('foo.bar (copy)').should('be.visible')
  107. })
  108. /** Test for https://github.com/nextcloud/server/issues/43329 */
  109. context('escaping file and folder names', () => {
  110. it('Can handle files with special characters', () => {
  111. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  112. .mkdir(currentUser, '/can\'t say')
  113. cy.login(currentUser)
  114. cy.visit('/apps/files')
  115. copyFile('original.txt', 'can\'t say')
  116. navigateToFolder('can\'t say')
  117. cy.url().should('contain', 'dir=/can%27t%20say')
  118. getRowForFile('original.txt').should('be.visible')
  119. getRowForFile('can\'t say').should('not.exist')
  120. })
  121. /**
  122. * If escape is set to false (required for test above) then "<a>foo" would result in "<a>foo</a>" if sanitizing is not disabled
  123. * We should disable it as vue already escapes the text when using v-text
  124. */
  125. it('does not incorrectly sanitize file names', () => {
  126. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  127. .mkdir(currentUser, '/<a href="#">foo')
  128. cy.login(currentUser)
  129. cy.visit('/apps/files')
  130. copyFile('original.txt', '<a href="#">foo')
  131. navigateToFolder('<a href="#">foo')
  132. cy.url().should('contain', 'dir=/%3Ca%20href%3D%22%23%22%3Efoo')
  133. getRowForFile('original.txt').should('be.visible')
  134. getRowForFile('<a href="#">foo').should('not.exist')
  135. })
  136. })
  137. })