1
0

files.cy.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /**
  2. * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
  3. *
  4. * @author John Molakvoæ <skjnldsv@protonmail.com>
  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 type { User } from '@nextcloud/cypress'
  23. const startCopyMove = (file: string) => {
  24. cy.get(`.files-fileList tr[data-file="${file}"`)
  25. .find('.fileactions [data-action="menu"]')
  26. .click()
  27. cy.get('.fileActionsMenu .action-movecopy').click()
  28. }
  29. describe('Login with a new user and open the files app', { testIsolation: false }, function() {
  30. before(function() {
  31. cy.createRandomUser().then((user) => {
  32. cy.login(user)
  33. })
  34. })
  35. Cypress.on('uncaught:exception', (err) => {
  36. // This can happen because of blink engine & skeleton animation, its not a bug just engine related.
  37. if (err.message.includes('ResizeObserver loop limit exceeded')) {
  38. return false
  39. }
  40. })
  41. it('See the default file welcome.txt in the files list', function() {
  42. cy.visit('/apps/files')
  43. cy.get('.files-fileList tr').should('contain', 'welcome.txt')
  44. })
  45. it('See the file list sorting order is saved', function() {
  46. cy.intercept('PUT', /api\/v1\/views\/files\/sorting_direction$/).as('sorting_direction')
  47. cy.intercept('PUT', /api\/v1\/views\/files\/sorting_mode$/).as('sorting_mode')
  48. cy.visit('/apps/files')
  49. // default to sorting by name
  50. cy.get('.files-filestable th.column-name .sort-indicator').should('be.visible')
  51. cy.get('.files-filestable th.column-size .sort-indicator').should('not.be.visible')
  52. // change to size
  53. cy.get('.files-filestable th').contains('Size').click()
  54. // size sorting should be active
  55. cy.get('.files-filestable th.column-name .sort-indicator').should('not.be.visible')
  56. cy.get('.files-filestable th.column-size .sort-indicator').should('be.visible')
  57. cy.wait('@sorting_direction')
  58. cy.wait('@sorting_mode')
  59. // Re-visit
  60. cy.reload()
  61. cy.get('.files-fileList tr').should('contain', 'welcome.txt')
  62. // now sorting by name should be disabled and sorting by size should be enabled
  63. cy.get('.files-filestable th.column-name .sort-indicator').should('not.be.visible')
  64. cy.get('.files-filestable th.column-size .sort-indicator').should('be.visible')
  65. })
  66. })
  67. describe('Testing the copy move action (FilePicker)', () => {
  68. let currentUser: User
  69. beforeEach(function() {
  70. cy.createRandomUser().then((user) => {
  71. currentUser = user
  72. cy.login(user)
  73. })
  74. })
  75. afterEach(function() {
  76. cy.deleteUser(currentUser)
  77. })
  78. it('Copy a file in its same folder', () => {
  79. cy.visit('/apps/files')
  80. cy.intercept('COPY', /\/remote.php\/dav\/files\//).as('copyFile')
  81. // When I start the move or copy operation for "welcome.txt"
  82. startCopyMove('welcome.txt')
  83. // And I copy to the last selected folder in the file picker
  84. cy.get('.dialog__actions button').contains('Copy').click()
  85. cy.wait('@copyFile')
  86. // Then I see that the file list contains a file named "welcome.txt"
  87. cy.get('.files-fileList tr').should('contain', 'welcome.txt')
  88. // And I see that the file list contains a file named "welcome (copy).txt"
  89. cy.get('.files-fileList tr').should('contain', 'welcome (copy).txt')
  90. })
  91. it('copy a file twice in its same folder', () => {
  92. cy.visit('/apps/files')
  93. cy.intercept('COPY', /\/remote.php\/dav\/files\//).as('copyFile')
  94. // When I start the move or copy operation for "welcome.txt"
  95. startCopyMove('welcome.txt')
  96. // And I copy to the last selected folder in the file picker
  97. cy.get('.dialog__actions button').contains('Copy').click()
  98. cy.wait('@copyFile')
  99. // When I start the move or copy operation for "welcome.txt"
  100. startCopyMove('welcome.txt')
  101. // And I copy to the last selected folder in the file picker
  102. cy.get('.dialog__actions button').contains('Copy').click()
  103. cy.wait('@copyFile')
  104. // Then I see that the file list contains a file named "welcome.txt"
  105. cy.get('.files-fileList tr').should('contain', 'welcome.txt')
  106. // And I see that the file list contains a file named "welcome (copy).txt"
  107. cy.get('.files-fileList tr').should('contain', 'welcome (copy).txt')
  108. // And I see that the file list contains a file named "welcome (copy 2).txt"
  109. cy.get('.files-fileList tr').should('contain', 'welcome (copy 2).txt')
  110. })
  111. it('copy a copy of a file in its same folder', () => {
  112. cy.visit('/apps/files')
  113. cy.intercept('COPY', /\/remote.php\/dav\/files\//).as('copyFile')
  114. // When I start the move or copy operation for "welcome.txt"
  115. startCopyMove('welcome.txt')
  116. // And I copy to the last selected folder in the file picker
  117. cy.get('.dialog__actions button').contains('Copy').click()
  118. cy.wait('@copyFile')
  119. // When I start the move or copy operation for "welcome (copy).txt"
  120. startCopyMove('welcome (copy).txt')
  121. // And I copy to the last selected folder in the file picker
  122. cy.get('.dialog__actions button').contains('Copy').click()
  123. cy.wait('@copyFile')
  124. // Then I see that the file list contains a file named "welcome.txt"
  125. cy.get('.files-fileList tr').should('contain', 'welcome.txt')
  126. // And I see that the file list contains a file named "welcome (copy).txt"
  127. cy.get('.files-fileList tr').should('contain', 'welcome (copy).txt')
  128. // And I see that the file list contains a file named "welcome (copy 2).txt"
  129. cy.get('.files-fileList tr').should('contain', 'welcome (copy 2).txt')
  130. })
  131. })