From edf645038345b62709bcc457be5acf9e0ab83dd1 Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Wed, 20 Nov 2024 15:19:45 +0100 Subject: [PATCH] test: Copying a folder containing live photos Signed-off-by: Louis Chemineau --- cypress/e2e/files/LivePhotosUtils.ts | 102 +++++++++++++++++++++++++ cypress/e2e/files/live_photos.cy.ts | 108 ++++++++++----------------- 2 files changed, 142 insertions(+), 68 deletions(-) create mode 100644 cypress/e2e/files/LivePhotosUtils.ts diff --git a/cypress/e2e/files/LivePhotosUtils.ts b/cypress/e2e/files/LivePhotosUtils.ts new file mode 100644 index 0000000000000..57e0021595aca --- /dev/null +++ b/cypress/e2e/files/LivePhotosUtils.ts @@ -0,0 +1,102 @@ +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: ` + + + + ${Object.entries(metadata).map(([key, value]) => `<${key}>${value}`).join('\n')} + + + `, + }) + }) + +} + +/** + * + * @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 { + 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 659cdc544ed97..04c6775a39800 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: ` - - - - ${Object.entries(metadata).map(([key, value]) => `<${key}>${value}`).join('\n')} - - - `, - }) -} +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,23 @@ describe('Files: Live photos', { testIsolation: true }, () => { getRowForFile(`${randomFileName} (copy).mov`).should('have.length', 1) }) + it.only('Keeps live photo link when copying folder', () => { + setShowHiddenFiles(false) + + createFolder('folder') + moveFile(`${randomFileName}.jpg`, 'folder') + copyFile('folder', '.') + navigateToFolder('folder (copy)') + + getRowForFile(`${randomFileName}.jpg`).should('have.length', 1) + getRowForFile(`${randomFileName}.mov`).should('have.length', 0) + + setShowHiddenFiles(true) + + getRowForFile(`${randomFileName}.jpg`).should('have.length', 1) + getRowForFile(`${randomFileName}.mov`).should('have.length', 1) + }) + it('Moves files when moving the .jpg', () => { renameFile(`${randomFileName}.jpg`, `${randomFileName}_moved.jpg`) clickOnBreadcrumbs('All files')