From 380932cc784d2de633dd888c0f1eda439e76d677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Mon, 4 May 2026 11:27:52 +0200 Subject: [PATCH] test: Add E2E tests for trashbin columns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- cypress/e2e/files_trashbin/files.cy.ts | 68 ++++++++++++++++++++++++++ cypress/support/commands.ts | 30 ++++++++++++ 2 files changed, 98 insertions(+) diff --git a/cypress/e2e/files_trashbin/files.cy.ts b/cypress/e2e/files_trashbin/files.cy.ts index c51ad27879f..d5290b6d6a2 100644 --- a/cypress/e2e/files_trashbin/files.cy.ts +++ b/cypress/e2e/files_trashbin/files.cy.ts @@ -5,7 +5,9 @@ import type { User } from '@nextcloud/e2e-test-server/cypress' +import { ShareType } from '@nextcloud/sharing' import { deleteDownloadsFolderBeforeEach } from '../../support/utils/deleteDownloadsFolder.ts' +import { randomString } from '../../support/utils/randomString.ts' import { deleteFileWithRequest, getRowForFileId, selectAllFiles, triggerActionForFileId } from '../files/FilesUtils.ts' describe('files_trashbin: download files', { testIsolation: true }, () => { @@ -67,3 +69,69 @@ describe('files_trashbin: download files', { testIsolation: true }, () => { cy.get('[data-cy-files-list-selection-action="download"]').should('not.exist') }) }) + +describe('files_trashbin: file row', { testIsolation: true }, () => { + let alice: User + let bob: User + let randomGroupName: string + let fileId: number + + before(() => { + randomGroupName = randomString(10) + cy.runOccCommand(`group:add ${randomGroupName}`) + + cy.createRandomUser().then((user) => { + alice = user + + cy.modifyUser(alice, 'display', 'Alice') + + cy.mkdir(alice, '/Shared') + }) + + cy.createRandomUser().then((user) => { + bob = user + + cy.modifyUser(bob, 'display', 'Bob') + + cy.runOccCommand(`group:adduser ${randomGroupName} ${bob.userId}`) + }) + }) + + it('shows data for file deleted by owner', () => { + cy.uploadContent(alice, new Blob(['']), 'text/plain', '/test-file.txt') + .then(({ headers }) => fileId = Number.parseInt(headers['oc-fileid'])) + .then(() => deleteFileWithRequest(alice, '/test-file.txt')) + + cy.login(alice) + cy.visit('/apps/files/trashbin') + + getRowForFileId(fileId).should('be.visible') + // The full name includes one span for the name and one span for the + // extension, so text() returns a space when composing them even if it + // will not be visible when rendered in the browser. + getRowForFileId(fileId).find('[data-cy-files-list-row-name]').should((element) => expect(element.text().trim()).to.equal('test-file .txt')) + getRowForFileId(fileId).find('[data-cy-files-list-row-column-custom="files_trashbin--original-location"]').should('have.text', 'All files') + getRowForFileId(fileId).find('[data-cy-files-list-row-column-custom="files_trashbin--deleted-by"]').should('have.text', 'You') + getRowForFileId(fileId).find('[data-cy-files-list-row-column-custom="files_trashbin--deleted"]').should('have.text', 'few seconds ago') + }) + + it('shows data for file deleted by sharee in a folder shared with a group', () => { + cy.createShare(alice, '/Shared', ShareType.Group, randomGroupName) + + cy.uploadContent(alice, new Blob(['']), 'text/plain', '/Shared/test-file.txt') + .then(({ headers }) => fileId = Number.parseInt(headers['oc-fileid'])) + .then(() => deleteFileWithRequest(bob, '/Shared/test-file.txt')) + + cy.login(alice) + cy.visit('/apps/files/trashbin') + + getRowForFileId(fileId).should('be.visible') + // The full name includes one span for the name and one span for the + // extension, so text() returns a space when composing them even if it + // will not be visible when rendered in the browser. + getRowForFileId(fileId).find('[data-cy-files-list-row-name]').should((element) => expect(element.text().trim()).to.equal('test-file .txt')) + getRowForFileId(fileId).find('[data-cy-files-list-row-column-custom="files_trashbin--original-location"]').should('have.text', 'Shared') + getRowForFileId(fileId).find('[data-cy-files-list-row-column-custom="files_trashbin--deleted-by"]').should('have.text', 'Bob') + getRowForFileId(fileId).find('[data-cy-files-list-row-column-custom="files_trashbin--deleted"]').should('have.text', 'few seconds ago') + }) +}) diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 49a95e8f132..e8e66b2b714 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -181,6 +181,36 @@ Cypress.Commands.add('uploadContent', (user: User, blob: Blob, mimeType: string, }) }) +Cypress.Commands.add('createShare', (sharer: User, path: string, shareType: number, shareWith: string) => { + return cy.clearCookies() + .then(async () => { + try { + const url = `${Cypress.env('baseUrl')}/ocs/v2.php/apps/files_sharing/api/v1/shares` + const response = await axios({ + url, + method: 'POST', + auth: { + username: sharer.userId, + password: sharer.password, + }, + headers: { + 'OCS-ApiRequest': 'true', + }, + data: { + path, + shareType, + shareWith, + }, + }) + cy.log(`Created share for ${path} of type ${shareType} with ${shareWith}`, response) + return response + } catch (cause) { + cy.log('error', cause) + throw new Error(`Unable to create share for ${path} of type ${shareType} with ${shareWith}`, { cause }) + } + }) +}) + /** * Reset the admin theming entirely */