live_photos.cy.ts 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /**
  2. * @copyright Copyright (c) 2024 Louis Chmn <louis@chmn.me>
  3. *
  4. * @author Louis Chmn <louis@chmn.me>
  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. import { clickOnBreadcrumbs, closeSidebar, copyFile, getRowForFile, getRowForFileId, renameFile, triggerActionForFile, triggerInlineActionForFileId } from './FilesUtils'
  24. /**
  25. *
  26. * @param user
  27. * @param fileName
  28. * @param domain
  29. * @param requesttoken
  30. * @param metadata
  31. */
  32. function setMetadata(user: User, fileName: string, domain: string, requesttoken: string, metadata: object) {
  33. cy.request({
  34. method: 'PROPPATCH',
  35. url: `http://${domain}/remote.php/dav/files/${user.userId}/${fileName}`,
  36. auth: { user: user.userId, pass: user.password },
  37. headers: {
  38. requesttoken,
  39. },
  40. body: `<?xml version="1.0"?>
  41. <d:propertyupdate xmlns:d="DAV:" xmlns:nc="http://nextcloud.org/ns">
  42. <d:set>
  43. <d:prop>
  44. ${Object.entries(metadata).map(([key, value]) => `<${key}>${value}</${key}>`).join('\n')}
  45. </d:prop>
  46. </d:set>
  47. </d:propertyupdate>`,
  48. })
  49. }
  50. describe('Files: Live photos', { testIsolation: true }, () => {
  51. let currentUser: User
  52. let randomFileName: string
  53. let jpgFileId: number
  54. let movFileId: number
  55. let hostname: string
  56. let requesttoken: string
  57. before(() => {
  58. cy.createRandomUser().then((user) => {
  59. currentUser = user
  60. cy.login(currentUser)
  61. cy.visit('/apps/files')
  62. })
  63. cy.url().then(url => { hostname = new URL(url).hostname })
  64. })
  65. beforeEach(() => {
  66. randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
  67. cy.uploadContent(currentUser, new Blob(['jpg file'], { type: 'image/jpg' }), 'image/jpg', `/${randomFileName}.jpg`)
  68. .then(response => { jpgFileId = parseInt(response.headers['oc-fileid']) })
  69. cy.uploadContent(currentUser, new Blob(['mov file'], { type: 'video/mov' }), 'video/mov', `/${randomFileName}.mov`)
  70. .then(response => { movFileId = parseInt(response.headers['oc-fileid']) })
  71. cy.login(currentUser)
  72. cy.visit('/apps/files')
  73. cy.get('head').invoke('attr', 'data-requesttoken').then(_requesttoken => { requesttoken = _requesttoken as string })
  74. cy.then(() => {
  75. setMetadata(currentUser, `${randomFileName}.jpg`, hostname, requesttoken, { 'nc:metadata-files-live-photo': movFileId })
  76. setMetadata(currentUser, `${randomFileName}.mov`, hostname, requesttoken, { 'nc:metadata-files-live-photo': jpgFileId })
  77. })
  78. cy.then(() => {
  79. cy.visit(`/apps/files/files/${jpgFileId}`) // Refresh and scroll to the .jpg file.
  80. closeSidebar()
  81. })
  82. })
  83. it('Only renders the .jpg file', () => {
  84. getRowForFileId(jpgFileId).should('have.length', 1)
  85. getRowForFileId(movFileId).should('have.length', 0)
  86. })
  87. context("'Show hidden files' is enabled", () => {
  88. before(() => {
  89. cy.login(currentUser)
  90. cy.visit('/apps/files')
  91. cy.get('[data-cy-files-navigation-settings-button]').click()
  92. // Force:true because the checkbox is hidden by the pretty UI.
  93. cy.get('[data-cy-files-settings-setting="show_hidden"] input').check({ force: true })
  94. })
  95. it("Shows both files when 'Show hidden files' is enabled", () => {
  96. getRowForFileId(jpgFileId).should('have.length', 1).invoke('attr', 'data-cy-files-list-row-name').should('equal', `${randomFileName}.jpg`)
  97. getRowForFileId(movFileId).should('have.length', 1).invoke('attr', 'data-cy-files-list-row-name').should('equal', `${randomFileName}.mov`)
  98. })
  99. it('Copies both files when copying the .jpg', () => {
  100. copyFile(`${randomFileName}.jpg`, '.')
  101. clickOnBreadcrumbs('All files')
  102. getRowForFile(`${randomFileName}.jpg`).should('have.length', 1)
  103. getRowForFile(`${randomFileName}.mov`).should('have.length', 1)
  104. getRowForFile(`${randomFileName} (copy).jpg`).should('have.length', 1)
  105. getRowForFile(`${randomFileName} (copy).mov`).should('have.length', 1)
  106. })
  107. it('Copies both files when copying the .mov', () => {
  108. copyFile(`${randomFileName}.mov`, '.')
  109. clickOnBreadcrumbs('All files')
  110. getRowForFile(`${randomFileName}.mov`).should('have.length', 1)
  111. getRowForFile(`${randomFileName} (copy).jpg`).should('have.length', 1)
  112. getRowForFile(`${randomFileName} (copy).mov`).should('have.length', 1)
  113. })
  114. it('Moves files when moving the .jpg', () => {
  115. renameFile(`${randomFileName}.jpg`, `${randomFileName}_moved.jpg`)
  116. clickOnBreadcrumbs('All files')
  117. getRowForFileId(jpgFileId).invoke('attr', 'data-cy-files-list-row-name').should('equal', `${randomFileName}_moved.jpg`)
  118. getRowForFileId(movFileId).invoke('attr', 'data-cy-files-list-row-name').should('equal', `${randomFileName}_moved.mov`)
  119. })
  120. it('Moves files when moving the .mov', () => {
  121. renameFile(`${randomFileName}.mov`, `${randomFileName}_moved.mov`)
  122. clickOnBreadcrumbs('All files')
  123. getRowForFileId(jpgFileId).invoke('attr', 'data-cy-files-list-row-name').should('equal', `${randomFileName}_moved.jpg`)
  124. getRowForFileId(movFileId).invoke('attr', 'data-cy-files-list-row-name').should('equal', `${randomFileName}_moved.mov`)
  125. })
  126. it('Deletes files when deleting the .jpg', () => {
  127. triggerActionForFile(`${randomFileName}.jpg`, 'delete')
  128. clickOnBreadcrumbs('All files')
  129. getRowForFile(`${randomFileName}.jpg`).should('have.length', 0)
  130. getRowForFile(`${randomFileName}.mov`).should('have.length', 0)
  131. cy.visit('/apps/files/trashbin')
  132. getRowForFileId(jpgFileId).invoke('attr', 'data-cy-files-list-row-name').should('to.match', new RegExp(`^${randomFileName}.jpg\\.d[0-9]+$`))
  133. getRowForFileId(movFileId).invoke('attr', 'data-cy-files-list-row-name').should('to.match', new RegExp(`^${randomFileName}.mov\\.d[0-9]+$`))
  134. })
  135. it('Block deletion when deleting the .mov', () => {
  136. triggerActionForFile(`${randomFileName}.mov`, 'delete')
  137. clickOnBreadcrumbs('All files')
  138. getRowForFile(`${randomFileName}.jpg`).should('have.length', 1)
  139. getRowForFile(`${randomFileName}.mov`).should('have.length', 1)
  140. cy.visit('/apps/files/trashbin')
  141. getRowForFileId(jpgFileId).should('have.length', 0)
  142. getRowForFileId(movFileId).should('have.length', 0)
  143. })
  144. it('Restores files when restoring the .jpg', () => {
  145. triggerActionForFile(`${randomFileName}.jpg`, 'delete')
  146. cy.visit('/apps/files/trashbin')
  147. triggerInlineActionForFileId(jpgFileId, 'restore')
  148. clickOnBreadcrumbs('Deleted files')
  149. getRowForFile(`${randomFileName}.jpg`).should('have.length', 0)
  150. getRowForFile(`${randomFileName}.mov`).should('have.length', 0)
  151. cy.visit('/apps/files')
  152. getRowForFile(`${randomFileName}.jpg`).should('have.length', 1)
  153. getRowForFile(`${randomFileName}.mov`).should('have.length', 1)
  154. })
  155. it('Blocks restoration when restoring the .mov', () => {
  156. triggerActionForFile(`${randomFileName}.jpg`, 'delete')
  157. cy.visit('/apps/files/trashbin')
  158. triggerInlineActionForFileId(movFileId, 'restore')
  159. clickOnBreadcrumbs('Deleted files')
  160. getRowForFileId(jpgFileId).should('have.length', 1)
  161. getRowForFileId(movFileId).should('have.length', 1)
  162. cy.visit('/apps/files')
  163. getRowForFile(`${randomFileName}.jpg`).should('have.length', 0)
  164. getRowForFile(`${randomFileName}.mov`).should('have.length', 0)
  165. })
  166. })
  167. })