aboutsummaryrefslogtreecommitdiffstats
path: root/cypress/e2e/files
diff options
context:
space:
mode:
authorLouis <louis@chmn.me>2024-12-04 17:02:56 +0100
committerGitHub <noreply@github.com>2024-12-04 17:02:56 +0100
commit1ef3e3e753aa1e1e767f6e1ed6576a0c00b27030 (patch)
tree2dad217ec9bacefec0813f81818f4da8d415588d /cypress/e2e/files
parent27331d48e377d5e908439cfdef8950b4b5ec47b2 (diff)
parent8be6a7c7dd51b018a20fb4f1c7e530999bc10faf (diff)
downloadnextcloud-server-1ef3e3e753aa1e1e767f6e1ed6576a0c00b27030.tar.gz
nextcloud-server-1ef3e3e753aa1e1e767f6e1ed6576a0c00b27030.zip
Merge pull request #49293 from nextcloud/artonge/fix/handle_folders_copy_live_photos
fix: Handle copy of folders containing live photos
Diffstat (limited to 'cypress/e2e/files')
-rw-r--r--cypress/e2e/files/FilesUtils.ts2
-rw-r--r--cypress/e2e/files/LivePhotosUtils.ts107
-rw-r--r--cypress/e2e/files/live_photos.cy.ts120
3 files changed, 160 insertions, 69 deletions
diff --git a/cypress/e2e/files/FilesUtils.ts b/cypress/e2e/files/FilesUtils.ts
index f435272b9a2..6a62ff77e86 100644
--- a/cypress/e2e/files/FilesUtils.ts
+++ b/cypress/e2e/files/FilesUtils.ts
@@ -159,7 +159,7 @@ export const createFolder = (folderName: string) => {
// TODO: replace by proper data-cy selectors
cy.get('[data-cy-upload-picker] .action-item__menutoggle').first().click()
- cy.contains('.upload-picker__menu-entry button', 'New folder').click()
+ cy.get('[data-cy-upload-picker-menu-entry="newFolder"] button').click()
cy.get('[data-cy-files-new-node-dialog]').should('be.visible')
cy.get('[data-cy-files-new-node-dialog-input]').type(`{selectall}${folderName}`)
cy.get('[data-cy-files-new-node-dialog-submit]').click()
diff --git a/cypress/e2e/files/LivePhotosUtils.ts b/cypress/e2e/files/LivePhotosUtils.ts
new file mode 100644
index 00000000000..6b0015affce
--- /dev/null
+++ b/cypress/e2e/files/LivePhotosUtils.ts
@@ -0,0 +1,107 @@
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import type { User } from '@nextcloud/cypress'
+
+type SetupInfo = {
+ snapshot: string
+ jpgFileId: number
+ movFileId: number
+ fileName: string
+ user: User
+}
+
+/**
+ *
+ * @param user
+ * @param fileName
+ * @param domain
+ * @param requesttoken
+ * @param metadata
+ */
+function setMetadata(user: User, fileName: string, requesttoken: string, metadata: object) {
+ cy.url().then(url => {
+ const hostname = new URL(url).hostname
+ cy.request({
+ method: 'PROPPATCH',
+ url: `http://${hostname}/remote.php/dav/files/${user.userId}/${fileName}`,
+ auth: { user: user.userId, pass: user.password },
+ headers: {
+ requesttoken,
+ },
+ body: `<?xml version="1.0"?>
+ <d:propertyupdate xmlns:d="DAV:" xmlns:nc="http://nextcloud.org/ns">
+ <d:set>
+ <d:prop>
+ ${Object.entries(metadata).map(([key, value]) => `<${key}>${value}</${key}>`).join('\n')}
+ </d:prop>
+ </d:set>
+ </d:propertyupdate>`,
+ })
+ })
+
+}
+
+/**
+ *
+ * @param enable
+ */
+export function setShowHiddenFiles(enable: boolean) {
+ cy.get('[data-cy-files-navigation-settings-button]').click()
+ // Force:true because the checkbox is hidden by the pretty UI.
+ if (enable) {
+ cy.get('[data-cy-files-settings-setting="show_hidden"] input').check({ force: true })
+ } else {
+ cy.get('[data-cy-files-settings-setting="show_hidden"] input').uncheck({ force: true })
+ }
+ cy.get('[data-cy-files-navigation-settings]').type('{esc}')
+}
+
+/**
+ *
+ */
+export function setupLivePhotos(): Cypress.Chainable<SetupInfo> {
+ return cy.task('getVariable', { key: 'live-photos-data' })
+ .then((_setupInfo) => {
+ const setupInfo = _setupInfo as SetupInfo || {}
+ if (setupInfo.snapshot) {
+ cy.restoreState(setupInfo.snapshot)
+ } else {
+ let requesttoken: string
+
+ setupInfo.fileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
+
+ cy.createRandomUser().then(_user => { setupInfo.user = _user })
+
+ cy.then(() => {
+ cy.uploadContent(setupInfo.user, new Blob(['jpg file'], { type: 'image/jpg' }), 'image/jpg', `/${setupInfo.fileName}.jpg`)
+ .then(response => { setupInfo.jpgFileId = parseInt(response.headers['oc-fileid']) })
+ cy.uploadContent(setupInfo.user, new Blob(['mov file'], { type: 'video/mov' }), 'video/mov', `/${setupInfo.fileName}.mov`)
+ .then(response => { setupInfo.movFileId = parseInt(response.headers['oc-fileid']) })
+
+ cy.login(setupInfo.user)
+ })
+
+ cy.visit('/apps/files')
+
+ cy.get('head').invoke('attr', 'data-requesttoken').then(_requesttoken => { requesttoken = _requesttoken as string })
+
+ cy.then(() => {
+ setMetadata(setupInfo.user, `${setupInfo.fileName}.jpg`, requesttoken, { 'nc:metadata-files-live-photo': setupInfo.movFileId })
+ setMetadata(setupInfo.user, `${setupInfo.fileName}.mov`, requesttoken, { 'nc:metadata-files-live-photo': setupInfo.jpgFileId })
+ })
+
+ cy.then(() => {
+ cy.saveState().then((value) => { setupInfo.snapshot = value })
+ cy.task('setVariable', { key: 'live-photos-data', value: setupInfo })
+ })
+ }
+ return cy.then(() => {
+ cy.login(setupInfo.user)
+ cy.visit('/apps/files')
+ return cy.wrap(setupInfo)
+ })
+ })
+}
diff --git a/cypress/e2e/files/live_photos.cy.ts b/cypress/e2e/files/live_photos.cy.ts
index 659cdc544ed..8eb4efaaec0 100644
--- a/cypress/e2e/files/live_photos.cy.ts
+++ b/cypress/e2e/files/live_photos.cy.ts
@@ -4,75 +4,34 @@
*/
import type { User } from '@nextcloud/cypress'
-import { clickOnBreadcrumbs, closeSidebar, copyFile, getRowForFile, getRowForFileId, renameFile, triggerActionForFile, triggerInlineActionForFileId } from './FilesUtils'
-
-/**
- *
- * @param user
- * @param fileName
- * @param domain
- * @param requesttoken
- * @param metadata
- */
-function setMetadata(user: User, fileName: string, domain: string, requesttoken: string, metadata: object) {
- cy.request({
- method: 'PROPPATCH',
- url: `http://${domain}/remote.php/dav/files/${user.userId}/${fileName}`,
- auth: { user: user.userId, pass: user.password },
- headers: {
- requesttoken,
- },
- body: `<?xml version="1.0"?>
- <d:propertyupdate xmlns:d="DAV:" xmlns:nc="http://nextcloud.org/ns">
- <d:set>
- <d:prop>
- ${Object.entries(metadata).map(([key, value]) => `<${key}>${value}</${key}>`).join('\n')}
- </d:prop>
- </d:set>
- </d:propertyupdate>`,
- })
-}
+import {
+ clickOnBreadcrumbs,
+ copyFile,
+ createFolder,
+ getRowForFile,
+ getRowForFileId,
+ moveFile,
+ navigateToFolder,
+ renameFile,
+ triggerActionForFile,
+ triggerInlineActionForFileId,
+} from './FilesUtils'
+import { setShowHiddenFiles, setupLivePhotos } from './LivePhotosUtils'
describe('Files: Live photos', { testIsolation: true }, () => {
- let currentUser: User
+ let user: User
let randomFileName: string
let jpgFileId: number
let movFileId: number
- let hostname: string
- let requesttoken: string
-
- before(() => {
- cy.createRandomUser().then((user) => {
- currentUser = user
- cy.login(currentUser)
- cy.visit('/apps/files')
- })
-
- cy.url().then(url => { hostname = new URL(url).hostname })
- })
beforeEach(() => {
- randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10)
-
- cy.uploadContent(currentUser, new Blob(['jpg file'], { type: 'image/jpg' }), 'image/jpg', `/${randomFileName}.jpg`)
- .then(response => { jpgFileId = parseInt(response.headers['oc-fileid']) })
- cy.uploadContent(currentUser, new Blob(['mov file'], { type: 'video/mov' }), 'video/mov', `/${randomFileName}.mov`)
- .then(response => { movFileId = parseInt(response.headers['oc-fileid']) })
-
- cy.login(currentUser)
- cy.visit('/apps/files')
-
- cy.get('head').invoke('attr', 'data-requesttoken').then(_requesttoken => { requesttoken = _requesttoken as string })
-
- cy.then(() => {
- setMetadata(currentUser, `${randomFileName}.jpg`, hostname, requesttoken, { 'nc:metadata-files-live-photo': movFileId })
- setMetadata(currentUser, `${randomFileName}.mov`, hostname, requesttoken, { 'nc:metadata-files-live-photo': jpgFileId })
- })
-
- cy.then(() => {
- cy.visit(`/apps/files/files/${jpgFileId}`) // Refresh and scroll to the .jpg file.
- closeSidebar()
- })
+ setupLivePhotos()
+ .then((setupInfo) => {
+ user = setupInfo.user
+ randomFileName = setupInfo.fileName
+ jpgFileId = setupInfo.jpgFileId
+ movFileId = setupInfo.movFileId
+ })
})
it('Only renders the .jpg file', () => {
@@ -81,12 +40,8 @@ describe('Files: Live photos', { testIsolation: true }, () => {
})
context("'Show hidden files' is enabled", () => {
- before(() => {
- cy.login(currentUser)
- cy.visit('/apps/files')
- cy.get('[data-cy-files-navigation-settings-button]').click()
- // Force:true because the checkbox is hidden by the pretty UI.
- cy.get('[data-cy-files-settings-setting="show_hidden"] input').check({ force: true })
+ beforeEach(() => {
+ setShowHiddenFiles(true)
})
it("Shows both files when 'Show hidden files' is enabled", () => {
@@ -113,6 +68,35 @@ describe('Files: Live photos', { testIsolation: true }, () => {
getRowForFile(`${randomFileName} (copy).mov`).should('have.length', 1)
})
+ it('Keeps live photo link when copying folder', () => {
+ createFolder('folder')
+ moveFile(`${randomFileName}.jpg`, 'folder')
+ copyFile('folder', '.')
+ navigateToFolder('folder (copy)')
+
+ getRowForFile(`${randomFileName}.jpg`).should('have.length', 1)
+ getRowForFile(`${randomFileName}.mov`).should('have.length', 1)
+
+ setShowHiddenFiles(false)
+
+ getRowForFile(`${randomFileName}.jpg`).should('have.length', 1)
+ getRowForFile(`${randomFileName}.mov`).should('have.length', 0)
+ })
+
+ it('Block copying live photo in a folder containing a mov file with the same name', () => {
+ createFolder('folder')
+ cy.uploadContent(user, new Blob(['mov file'], { type: 'video/mov' }), 'video/mov', `/folder/${randomFileName}.mov`)
+ cy.login(user)
+ cy.visit('/apps/files')
+ copyFile(`${randomFileName}.jpg`, 'folder')
+ navigateToFolder('folder')
+
+ cy.get('[data-cy-files-list-row-fileid]').should('have.length', 1)
+ getRowForFile(`${randomFileName}.mov`).should('have.length', 1)
+ getRowForFile(`${randomFileName}.jpg`).should('have.length', 0)
+ getRowForFile(`${randomFileName} (copy).jpg`).should('have.length', 0)
+ })
+
it('Moves files when moving the .jpg', () => {
renameFile(`${randomFileName}.jpg`, `${randomFileName}_moved.jpg`)
clickOnBreadcrumbs('All files')