live_photos.cy.ts 6.9 KB

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