files_copy-move.cy.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. // This was a bug previously
  63. it('Can move a file to folder with similar name', () => {
  64. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original')
  65. .mkdir(currentUser, '/original folder')
  66. cy.login(currentUser)
  67. cy.visit('/apps/files')
  68. moveFile('original', 'original folder')
  69. // wait until visible again
  70. getRowForFile('original folder').should('be.visible')
  71. // original should be moved -> not exist anymore
  72. getRowForFile('original').should('not.exist')
  73. navigateToFolder('original folder')
  74. cy.url().should('contain', 'dir=/original%20folder')
  75. getRowForFile('original').should('be.visible')
  76. getRowForFile('original folder').should('not.exist')
  77. })
  78. it('Can move a file to its parent folder', () => {
  79. cy.mkdir(currentUser, '/new-folder')
  80. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/new-folder/original.txt')
  81. cy.login(currentUser)
  82. cy.visit('/apps/files')
  83. navigateToFolder('new-folder')
  84. cy.url().should('contain', 'dir=/new-folder')
  85. moveFile('original.txt', '/')
  86. // wait until visible again
  87. cy.get('main').contains('No files in here').should('be.visible')
  88. // original should be moved -> not exist anymore
  89. getRowForFile('original.txt').should('not.exist')
  90. cy.visit('/apps/files')
  91. getRowForFile('new-folder').should('be.visible')
  92. getRowForFile('original.txt').should('be.visible')
  93. })
  94. it('Can copy a file to same folder', () => {
  95. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  96. cy.login(currentUser)
  97. cy.visit('/apps/files')
  98. copyFile('original.txt', '.')
  99. getRowForFile('original.txt').should('be.visible')
  100. getRowForFile('original (copy).txt').should('be.visible')
  101. })
  102. it('Can copy a file multiple times to same folder', () => {
  103. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt')
  104. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original (copy).txt')
  105. cy.login(currentUser)
  106. cy.visit('/apps/files')
  107. copyFile('original.txt', '.')
  108. getRowForFile('original.txt').should('be.visible')
  109. getRowForFile('original (copy 2).txt').should('be.visible')
  110. })
  111. })