1
0

files_copy-move.cy.ts 6.9 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. // 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. // intercept the copy so we can wait for it
  42. cy.intercept('COPY', /\/remote.php\/dav\/files\//).as('copyFile')
  43. // Open actions and trigger copy-move action
  44. getRowForFile('original.txt').should('be.visible')
  45. triggerActionForFile('original.txt', 'move-copy')
  46. // select new folder
  47. cy.get('.file-picker [data-filename="new-folder"]').should('be.visible').click()
  48. // click copy
  49. cy.get('.file-picker').contains('button', 'Copy to new-folder').should('be.visible').click()
  50. // wait for copy to finish
  51. cy.wait('@copyFile')
  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. // intercept the copy so we can wait for it
  63. cy.intercept('MOVE', /\/remote.php\/dav\/files\//).as('moveFile')
  64. getRowForFile('original.txt').should('be.visible')
  65. triggerActionForFile('original.txt', 'move-copy')
  66. // select new folder
  67. cy.get('.file-picker [data-filename="new-folder"]').should('be.visible').click()
  68. // click copy
  69. cy.get('.file-picker').contains('button', 'Move to new-folder').should('be.visible').click()
  70. cy.wait('@moveFile')
  71. // wait until visible again
  72. getRowForFile('new-folder').should('be.visible')
  73. // original should be moved -> not exist anymore
  74. getRowForFile('original.txt').should('not.exist')
  75. getRowForFile('new-folder').should('be.visible').find('[data-cy-files-list-row-name-link]').click()
  76. cy.url().should('contain', 'dir=/new-folder')
  77. getRowForFile('original.txt').should('be.visible')
  78. getRowForFile('new-folder').should('not.exist')
  79. })
  80. // This was a bug previously
  81. it('Can move a file to folder with similar name', () => {
  82. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original')
  83. .mkdir(currentUser, '/original folder')
  84. cy.login(currentUser)
  85. cy.visit('/apps/files')
  86. // intercept the copy so we can wait for it
  87. cy.intercept('MOVE', /\/remote.php\/dav\/files\//).as('moveFile')
  88. getRowForFile('original').should('be.visible')
  89. triggerActionForFile('original', 'move-copy')
  90. // select new folder
  91. cy.get('.file-picker [data-filename="original folder"]').should('be.visible').click()
  92. // click copy
  93. cy.get('.file-picker').contains('button', 'Move to original folder').should('be.visible').click()
  94. cy.wait('@moveFile')
  95. // wait until visible again
  96. getRowForFile('original folder').should('be.visible')
  97. // original should be moved -> not exist anymore
  98. getRowForFile('original').should('not.exist')
  99. getRowForFile('original folder').should('be.visible').find('[data-cy-files-list-row-name-link]').click()
  100. cy.url().should('contain', 'dir=/original%20folder')
  101. getRowForFile('original').should('be.visible')
  102. getRowForFile('original folder').should('not.exist')
  103. })
  104. it('Can move a file to its parent folder', () => {
  105. cy.mkdir(currentUser, '/new-folder')
  106. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/new-folder/original.txt')
  107. cy.login(currentUser)
  108. cy.visit('/apps/files')
  109. // intercept the copy so we can wait for it
  110. cy.intercept('MOVE', /\/remote.php\/dav\/files\//).as('moveFile')
  111. getRowForFile('new-folder').should('be.visible').find('[data-cy-files-list-row-name-link]').click()
  112. cy.url().should('contain', 'dir=/new-folder')
  113. getRowForFile('original.txt').should('be.visible')
  114. triggerActionForFile('original.txt', 'move-copy')
  115. // select new folder
  116. cy.get('.file-picker button[title="Home"]').should('be.visible').click()
  117. // click move
  118. cy.get('.file-picker').contains('button', 'Move').should('be.visible').click()
  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. })