live_photos.cy.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. import type { User } from '@nextcloud/cypress'
  6. import {
  7. clickOnBreadcrumbs,
  8. copyFile,
  9. createFolder,
  10. getRowForFile,
  11. getRowForFileId,
  12. moveFile,
  13. navigateToFolder,
  14. renameFile,
  15. triggerActionForFile,
  16. triggerInlineActionForFileId,
  17. } from './FilesUtils'
  18. import { setShowHiddenFiles, setupLivePhotos } from './LivePhotosUtils'
  19. describe('Files: Live photos', { testIsolation: true }, () => {
  20. let user: User
  21. let randomFileName: string
  22. let jpgFileId: number
  23. let movFileId: number
  24. beforeEach(() => {
  25. setupLivePhotos()
  26. .then((setupInfo) => {
  27. user = setupInfo.user
  28. randomFileName = setupInfo.fileName
  29. jpgFileId = setupInfo.jpgFileId
  30. movFileId = setupInfo.movFileId
  31. })
  32. })
  33. it('Only renders the .jpg file', () => {
  34. getRowForFileId(jpgFileId).should('have.length', 1)
  35. getRowForFileId(movFileId).should('have.length', 0)
  36. })
  37. context("'Show hidden files' is enabled", () => {
  38. beforeEach(() => {
  39. setShowHiddenFiles(true)
  40. })
  41. it("Shows both files when 'Show hidden files' is enabled", () => {
  42. getRowForFileId(jpgFileId).should('have.length', 1).invoke('attr', 'data-cy-files-list-row-name').should('equal', `${randomFileName}.jpg`)
  43. getRowForFileId(movFileId).should('have.length', 1).invoke('attr', 'data-cy-files-list-row-name').should('equal', `${randomFileName}.mov`)
  44. })
  45. it('Copies both files when copying the .jpg', () => {
  46. copyFile(`${randomFileName}.jpg`, '.')
  47. clickOnBreadcrumbs('All files')
  48. getRowForFile(`${randomFileName}.jpg`).should('have.length', 1)
  49. getRowForFile(`${randomFileName}.mov`).should('have.length', 1)
  50. getRowForFile(`${randomFileName} (copy).jpg`).should('have.length', 1)
  51. getRowForFile(`${randomFileName} (copy).mov`).should('have.length', 1)
  52. })
  53. it('Copies both files when copying the .mov', () => {
  54. copyFile(`${randomFileName}.mov`, '.')
  55. clickOnBreadcrumbs('All files')
  56. getRowForFile(`${randomFileName}.mov`).should('have.length', 1)
  57. getRowForFile(`${randomFileName} (copy).jpg`).should('have.length', 1)
  58. getRowForFile(`${randomFileName} (copy).mov`).should('have.length', 1)
  59. })
  60. it('Keeps live photo link when copying folder', () => {
  61. createFolder('folder')
  62. moveFile(`${randomFileName}.jpg`, 'folder')
  63. copyFile('folder', '.')
  64. navigateToFolder('folder (copy)')
  65. getRowForFile(`${randomFileName}.jpg`).should('have.length', 1)
  66. getRowForFile(`${randomFileName}.mov`).should('have.length', 1)
  67. setShowHiddenFiles(false)
  68. getRowForFile(`${randomFileName}.jpg`).should('have.length', 1)
  69. getRowForFile(`${randomFileName}.mov`).should('have.length', 0)
  70. })
  71. it('Block copying live photo in a folder containing a mov file with the same name', () => {
  72. createFolder('folder')
  73. cy.uploadContent(user, new Blob(['mov file'], { type: 'video/mov' }), 'video/mov', `/folder/${randomFileName}.mov`)
  74. cy.login(user)
  75. cy.visit('/apps/files')
  76. copyFile(`${randomFileName}.jpg`, 'folder')
  77. navigateToFolder('folder')
  78. cy.get('[data-cy-files-list-row-fileid]').should('have.length', 1)
  79. getRowForFile(`${randomFileName}.mov`).should('have.length', 1)
  80. getRowForFile(`${randomFileName}.jpg`).should('have.length', 0)
  81. getRowForFile(`${randomFileName} (copy).jpg`).should('have.length', 0)
  82. })
  83. it('Moves files when moving the .jpg', () => {
  84. renameFile(`${randomFileName}.jpg`, `${randomFileName}_moved.jpg`)
  85. clickOnBreadcrumbs('All files')
  86. getRowForFileId(jpgFileId).invoke('attr', 'data-cy-files-list-row-name').should('equal', `${randomFileName}_moved.jpg`)
  87. getRowForFileId(movFileId).invoke('attr', 'data-cy-files-list-row-name').should('equal', `${randomFileName}_moved.mov`)
  88. })
  89. it('Moves files when moving the .mov', () => {
  90. renameFile(`${randomFileName}.mov`, `${randomFileName}_moved.mov`)
  91. clickOnBreadcrumbs('All files')
  92. getRowForFileId(jpgFileId).invoke('attr', 'data-cy-files-list-row-name').should('equal', `${randomFileName}_moved.jpg`)
  93. getRowForFileId(movFileId).invoke('attr', 'data-cy-files-list-row-name').should('equal', `${randomFileName}_moved.mov`)
  94. })
  95. it('Deletes files when deleting the .jpg', () => {
  96. triggerActionForFile(`${randomFileName}.jpg`, 'delete')
  97. clickOnBreadcrumbs('All files')
  98. getRowForFile(`${randomFileName}.jpg`).should('have.length', 0)
  99. getRowForFile(`${randomFileName}.mov`).should('have.length', 0)
  100. cy.visit('/apps/files/trashbin')
  101. getRowForFileId(jpgFileId).invoke('attr', 'data-cy-files-list-row-name').should('to.match', new RegExp(`^${randomFileName}.jpg\\.d[0-9]+$`))
  102. getRowForFileId(movFileId).invoke('attr', 'data-cy-files-list-row-name').should('to.match', new RegExp(`^${randomFileName}.mov\\.d[0-9]+$`))
  103. })
  104. it('Block deletion when deleting the .mov', () => {
  105. triggerActionForFile(`${randomFileName}.mov`, 'delete')
  106. clickOnBreadcrumbs('All files')
  107. getRowForFile(`${randomFileName}.jpg`).should('have.length', 1)
  108. getRowForFile(`${randomFileName}.mov`).should('have.length', 1)
  109. cy.visit('/apps/files/trashbin')
  110. getRowForFileId(jpgFileId).should('have.length', 0)
  111. getRowForFileId(movFileId).should('have.length', 0)
  112. })
  113. it('Restores files when restoring the .jpg', () => {
  114. triggerActionForFile(`${randomFileName}.jpg`, 'delete')
  115. cy.visit('/apps/files/trashbin')
  116. triggerInlineActionForFileId(jpgFileId, 'restore')
  117. clickOnBreadcrumbs('Deleted files')
  118. getRowForFile(`${randomFileName}.jpg`).should('have.length', 0)
  119. getRowForFile(`${randomFileName}.mov`).should('have.length', 0)
  120. cy.visit('/apps/files')
  121. getRowForFile(`${randomFileName}.jpg`).should('have.length', 1)
  122. getRowForFile(`${randomFileName}.mov`).should('have.length', 1)
  123. })
  124. it('Blocks restoration when restoring the .mov', () => {
  125. triggerActionForFile(`${randomFileName}.jpg`, 'delete')
  126. cy.visit('/apps/files/trashbin')
  127. triggerInlineActionForFileId(movFileId, 'restore')
  128. clickOnBreadcrumbs('Deleted files')
  129. getRowForFileId(jpgFileId).should('have.length', 1)
  130. getRowForFileId(movFileId).should('have.length', 1)
  131. cy.visit('/apps/files')
  132. getRowForFile(`${randomFileName}.jpg`).should('have.length', 0)
  133. getRowForFile(`${randomFileName}.mov`).should('have.length', 0)
  134. })
  135. })
  136. })