FilesUtils.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * @copyright Copyright (c) 2024 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. export const getRowForFile = (filename: string) => cy.get(`[data-cy-files-list-row-name="${CSS.escape(filename)}"]`)
  23. export const getActionsForFile = (filename: string) => getRowForFile(filename).find('[data-cy-files-list-row-actions]')
  24. export const getActionButtonForFile = (filename: string) => getActionsForFile(filename).find('button[aria-label="Actions"]')
  25. export const triggerActionForFile = (filename: string, actionId: string) => {
  26. getActionButtonForFile(filename).click()
  27. cy.get(`[data-cy-files-list-row-action="${CSS.escape(actionId)}"] > button`).should('exist').click()
  28. }
  29. export const moveFile = (fileName: string, dirName: string) => {
  30. getRowForFile(fileName).should('be.visible')
  31. triggerActionForFile(fileName, 'move-copy')
  32. cy.get('.file-picker').within(() => {
  33. // intercept the copy so we can wait for it
  34. cy.intercept('MOVE', /\/remote.php\/dav\/files\//).as('moveFile')
  35. if (dirName === '/') {
  36. // select home folder
  37. cy.get('button[title="Home"]').should('be.visible').click()
  38. // click move
  39. cy.contains('button', 'Move').should('be.visible').click()
  40. } else if (dirName === '.') {
  41. // click move
  42. cy.contains('button', 'Copy').should('be.visible').click()
  43. } else {
  44. // select the folder
  45. cy.get(`[data-filename="${dirName}"]`).should('be.visible').click()
  46. // click move
  47. cy.contains('button', `Move to ${dirName}`).should('be.visible').click()
  48. }
  49. cy.wait('@moveFile')
  50. })
  51. }
  52. export const copyFile = (fileName: string, dirName: string) => {
  53. getRowForFile(fileName).should('be.visible')
  54. triggerActionForFile(fileName, 'move-copy')
  55. cy.get('.file-picker').within(() => {
  56. // intercept the copy so we can wait for it
  57. cy.intercept('COPY', /\/remote.php\/dav\/files\//).as('copyFile')
  58. if (dirName === '/') {
  59. // select home folder
  60. cy.get('button[title="Home"]').should('be.visible').click()
  61. // click copy
  62. cy.contains('button', 'Copy').should('be.visible').click()
  63. } else if (dirName === '.') {
  64. // click copy
  65. cy.contains('button', 'Copy').should('be.visible').click()
  66. } else {
  67. // select folder
  68. cy.get(`[data-filename="${dirName}"]`).should('be.visible').click()
  69. // click copy
  70. cy.contains('button', `Copy to ${dirName}`).should('be.visible').click()
  71. }
  72. cy.wait('@copyFile')
  73. })
  74. }
  75. export const navigateToFolder = (folderName: string) => {
  76. getRowForFile(folderName).should('be.visible').find('[data-cy-files-list-row-name-link]').click()
  77. }