From e04cf6e5e79b38de7b46a2731049d05c495a04a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 22 Aug 2024 17:58:34 +0200 Subject: [PATCH] tests: Add E2E tests for copying and moving shared groupfolders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit filesUtils functions copied from server/cypress/e2e/files/FilesUtils.ts [skip ci] Signed-off-by: Daniel Calviño Sánchez --- cypress/e2e/files/filesUtils.ts | 50 ++++++- cypress/e2e/sharing.cy.ts | 238 ++++++++++++++++++++++++++++++++ 2 files changed, 286 insertions(+), 2 deletions(-) create mode 100644 cypress/e2e/sharing.cy.ts diff --git a/cypress/e2e/files/filesUtils.ts b/cypress/e2e/files/filesUtils.ts index 2ea28a8c5..781f7b933 100644 --- a/cypress/e2e/files/filesUtils.ts +++ b/cypress/e2e/files/filesUtils.ts @@ -34,7 +34,11 @@ export const moveFile = (fileName: string, dirPath: string) => { const directories = dirPath.split('/') directories.forEach((directory) => { // select the folder - cy.get(`[data-filename="${directory}"]`).should('be.visible').click() + if (directory === '') { + cy.get('button[title="Home"]').should('be.visible').click() + } else { + cy.get(`[data-filename="${directory}"]`).should('be.visible').click() + } }) // click move @@ -65,7 +69,11 @@ export const copyFile = (fileName: string, dirPath: string) => { const directories = dirPath.split('/') directories.forEach((directory) => { // select the folder - cy.get(`[data-filename="${directory}"]`).should('be.visible').click() + if (directory === '') { + cy.get('button[title="Home"]').should('be.visible').click() + } else { + cy.get(`[data-filename="${directory}"]`).should('be.visible').click() + } }) // click copy @@ -76,6 +84,29 @@ export const copyFile = (fileName: string, dirPath: string) => { }) } +export const createShare = (fileName: string, username: string) => { + openSharingPanel(fileName) + + cy.get('#app-sidebar-vue').within(() => { + cy.get('#sharing-search-input').clear() + cy.intercept({ times: 1, method: 'GET', url: '**/apps/files_sharing/api/v1/sharees?*' }).as('userSearch') + cy.get('#sharing-search-input').type(username) + cy.wait('@userSearch') + }) + + cy.get(`[user="${username}"]`).click() + + cy.get('[data-cy-files-sharing-share-editor-action="save"]').click({ scrollBehavior: 'nearest' }) +} + +export const openSharingPanel = (fileName: string) => { + triggerActionForFile(fileName, 'details') + + cy.get('#app-sidebar-vue') + .get('[aria-controls="tab-sharing"]') + .click() +} + export const navigateToFolder = (dirPath: string) => { const directories = dirPath.split('/') directories.forEach((directory) => { @@ -95,6 +126,21 @@ export const clickOnBreadcumbs = (label: string) => { cy.wait('@propfind') } +export const createFolder = (folderName: string) => { + cy.intercept('MKCOL', /\/remote.php\/dav\/files\//).as('createFolder') + + // 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-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() + + cy.wait('@createFolder') + + getRowForFile(folderName).should('be.visible') +} + export const assertFileContent = (fileName: string, expectedContent: string) => { cy.intercept({ method: 'GET', times: 1, url: 'remote.php/**' }).as('downloadFile') getRowForFile(fileName).should('be.visible') diff --git a/cypress/e2e/sharing.cy.ts b/cypress/e2e/sharing.cy.ts new file mode 100644 index 000000000..456c817c1 --- /dev/null +++ b/cypress/e2e/sharing.cy.ts @@ -0,0 +1,238 @@ +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { + addUserToGroup, + createGroup, + createGroupFolder, + deleteGroupFolder, + enterFolder, + fileOrFolderDoesNotExist, + fileOrFolderExists, + PERMISSION_DELETE, + PERMISSION_READ, + PERMISSION_SHARE, + PERMISSION_WRITE, +} from './groupfoldersUtils' + +import { + copyFile, + createFolder, + createShare, + moveFile, +} from './files/filesUtils' + +import { randHash } from '../utils' + +import type { User } from '@nextcloud/cypress' + +describe('Groupfolders sharing behavior', () => { + let user1: User + let user2: User + let groupFolderId1: string + let groupFolderId2: string + let groupName1: string + let groupName2: string + let groupFolderName1: string + let groupFolderName2: string + + beforeEach(() => { + if (groupFolderId1) { + deleteGroupFolder(groupFolderId1) + } + if (groupFolderId2) { + deleteGroupFolder(groupFolderId1) + } + groupName1 = `test_group_${randHash()}` + groupFolderName1 = `test_group_folder_${randHash()}` + groupName2 = `test_group_${randHash()}` + groupFolderName2 = `test_group_folder_${randHash()}` + + cy.createRandomUser() + .then(_user => { + user1 = _user + }) + cy.createRandomUser() + .then(_user => { + user2 = _user + }) + createGroup(groupName1) + .then(() => { + addUserToGroup(groupName1, user1.userId) + createGroupFolder(groupFolderName1, groupName1, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_SHARE, PERMISSION_DELETE]) + }) + createGroup(groupName2) + .then(() => { + addUserToGroup(groupName2, user2.userId) + createGroupFolder(groupFolderName2, groupName2, [PERMISSION_READ, PERMISSION_WRITE, PERMISSION_SHARE, PERMISSION_DELETE]) + }) + }) + + it('Copy shared groupfolder into another folder', () => { + cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', `/${groupFolderName1}/file1.txt`) + + cy.login(user1) + cy.visit('/apps/files') + + createShare(groupFolderName1, user2.userId) + + cy.login(user2) + cy.visit('/apps/files') + + createFolder('Target') + + copyFile(`${groupFolderName1}`, 'Target') + + cy.visit('/apps/files') + enterFolder(groupFolderName1) + fileOrFolderExists('file1.txt') + + cy.visit('/apps/files') + enterFolder('Target') + enterFolder(groupFolderName1) + fileOrFolderExists('file1.txt') + }) + + it('Copy shared groupfolder into another groupfolder', () => { + cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', `/${groupFolderName1}/file1.txt`) + + cy.login(user1) + cy.visit('/apps/files') + + createShare(groupFolderName1, user2.userId) + + cy.login(user2) + cy.visit('/apps/files') + + copyFile(`${groupFolderName1}`, `${groupFolderName2}`) + + cy.visit('/apps/files') + enterFolder(groupFolderName1) + fileOrFolderExists('file1.txt') + + cy.visit('/apps/files') + enterFolder(groupFolderName2) + enterFolder(groupFolderName1) + fileOrFolderExists('file1.txt') + }) + + it('Copy file from shared groupfolder into another folder', () => { + cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', `/${groupFolderName1}/file1.txt`) + + cy.login(user1) + cy.visit('/apps/files') + + createShare(groupFolderName1, user2.userId) + + cy.login(user2) + cy.visit('/apps/files') + + createFolder('Target') + + enterFolder(groupFolderName1) + copyFile('file1.txt', '/Target') + + cy.visit('/apps/files') + enterFolder(groupFolderName1) + fileOrFolderExists('file1.txt') + + cy.visit('/apps/files') + enterFolder('Target') + fileOrFolderExists('file1.txt') + }) + + it('Copy file from shared groupfolder into another groupfolder', () => { + cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', `/${groupFolderName1}/file1.txt`) + + cy.login(user1) + cy.visit('/apps/files') + + createShare(groupFolderName1, user2.userId) + + cy.login(user2) + cy.visit('/apps/files') + + enterFolder(groupFolderName1) + copyFile('file1.txt', `/${groupFolderName2}`) + + cy.visit('/apps/files') + enterFolder(groupFolderName1) + fileOrFolderExists('file1.txt') + + cy.visit('/apps/files') + enterFolder(groupFolderName2) + fileOrFolderExists('file1.txt') + }) + + it('Move shared groupfolder into another folder', () => { + cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', `/${groupFolderName1}/file1.txt`) + + cy.login(user1) + cy.visit('/apps/files') + + createShare(groupFolderName1, user2.userId) + + cy.login(user2) + cy.visit('/apps/files') + + createFolder('Target') + + moveFile(`${groupFolderName1}`, 'Target') + + cy.visit('/apps/files') + fileOrFolderDoesNotExist(groupFolderName1) + + enterFolder('Target') + enterFolder(groupFolderName1) + fileOrFolderExists('file1.txt') + }) + + it('Move file from shared groupfolder into another folder', () => { + cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', `/${groupFolderName1}/file1.txt`) + + cy.login(user1) + cy.visit('/apps/files') + + createShare(groupFolderName1, user2.userId) + + cy.login(user2) + cy.visit('/apps/files') + + createFolder('Target') + + enterFolder(groupFolderName1) + moveFile('file1.txt', '/Target') + + cy.visit('/apps/files') + enterFolder(groupFolderName1) + fileOrFolderDoesNotExist('file1.txt') + + cy.visit('/apps/files') + enterFolder('Target') + fileOrFolderExists('file1.txt') + }) + + it('Move file from shared groupfolder into another groupfolder', () => { + cy.uploadContent(user1, new Blob(['Content of the file']), 'text/plain', `/${groupFolderName1}/file1.txt`) + + cy.login(user1) + cy.visit('/apps/files') + + createShare(groupFolderName1, user2.userId) + + cy.login(user2) + cy.visit('/apps/files') + + enterFolder(groupFolderName1) + moveFile('file1.txt', `/${groupFolderName2}`) + + cy.visit('/apps/files') + enterFolder(groupFolderName1) + fileOrFolderDoesNotExist('file1.txt') + + cy.visit('/apps/files') + enterFolder(groupFolderName2) + fileOrFolderExists('file1.txt') + }) +})