Skip to content

Commit

Permalink
tests: Add E2E tests for copying and moving shared groupfolders
Browse files Browse the repository at this point in the history
filesUtils functions copied from server/cypress/e2e/files/FilesUtils.ts

[skip ci]

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
  • Loading branch information
danxuliu committed Sep 9, 2024
1 parent b8b4258 commit e04cf6e
Show file tree
Hide file tree
Showing 2 changed files with 286 additions and 2 deletions.
50 changes: 48 additions & 2 deletions cypress/e2e/files/filesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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) => {
Expand All @@ -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')
Expand Down
238 changes: 238 additions & 0 deletions cypress/e2e/sharing.cy.ts
Original file line number Diff line number Diff line change
@@ -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')
})
})

0 comments on commit e04cf6e

Please sign in to comment.