Skip to content

Commit

Permalink
Merge pull request #8193 from owncloud/addCustomPermissionTests
Browse files Browse the repository at this point in the history
[tests-only][full-ci]Add custom permission e2e tests
  • Loading branch information
saw-jan authored Jan 23, 2023
2 parents c866480 + addcc6c commit ef42754
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 56 deletions.
12 changes: 6 additions & 6 deletions tests/e2e/cucumber/features/smoke/reshare.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Feature: reshare
And "Brian" opens the "files" app
And "Brian" navigates to the shared with me page
And "Brian" reshares the following resource
| resource | recipient | type | role |
| folder_to_shared | sales | group | viewer |
| resource | recipient | type | role | resourceType |
| folder_to_shared | sales | group | viewer | folder |

And "Carol" logs in
And "Carol" opens the "files" app
Expand All @@ -40,8 +40,8 @@ Feature: reshare
| name |
| folder_to_shared |
And "Carol" reshares the following resource
| resource | recipient | type | role |
| folder_to_shared | Alice | user | viewer |
| resource | recipient | type | role | resourceType |
| folder_to_shared | Alice | user | viewer | folder |

And "Alice" logs in
And "Alice" opens the "files" app
Expand All @@ -53,8 +53,8 @@ Feature: reshare
And "Alice" logs out

When "Brian" updates following sharee role
| resource | recipient | type | role |
| folder_to_shared | sales | group | custom_permissions:read |
| resource | recipient | type | role | resourceType |
| folder_to_shared | sales | group | custom_permissions:read | folder |
And "Brian" logs out

And "Carol" navigates to the shared with me page
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/cucumber/features/smoke/search.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Feature: Search
| resource |
| new-lorem-big.txt |
And "Brian" shares the following resource using the sidebar panel
| resource | recipient | type | role |
| new_share_from_brian | Alice | user | viewer |
| new-lorem-big.txt | Alice | user | viewer |
| resource | recipient | type | role | resourceType |
| new_share_from_brian | Alice | user | viewer | folder |
| new-lorem-big.txt | Alice | user | viewer | file |
And "Brian" logs out

When "Alice" logs in
Expand Down
46 changes: 30 additions & 16 deletions tests/e2e/cucumber/features/smoke/share.oc10.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,44 @@ Feature: share
| id |
| Alice |
| Brian |
When "Alice" logs in
And "Alice" logs in
And "Alice" opens the "files" app
And "Alice" navigates to the personal space page
And "Alice" creates the following resources
| resource | type |
| folder_to_shared | folder |
| resource | type |
| folder_to_shared | folder |
| folder_to_customShared | folder |
And "Alice" uploads the following resource
| resource | to |
| lorem.txt | folder_to_shared |
| resource | to |
| lorem.txt | folder_to_shared |
| lorem-big.txt | folder_to_customShared |
#Then "Alice" should see the following resource
# | folder_to_shared/lorem.txt |
When "Alice" shares the following resource using the sidebar panel
| resource | recipient | type | role |
| folder_to_shared | Brian | user | editor |
| resource | recipient | type | role | resourceType |
| folder_to_shared | Brian | user | editor | folder |
| folder_to_customShared | Brian | user | custom_permissions:read,create,delete | folder |
And "Brian" logs in
And "Brian" opens the "files" app
And "Brian" navigates to the shared with me page
And "Brian" accepts the following share
| name |
| folder_to_shared |
| name |
| folder_to_shared |
| folder_to_customShared |
And "Brian" navigates to the personal space page
And "Brian" renames the following resource
| resource | as |
| Shares/folder_to_shared/lorem.txt | lorem_new.txt |
And "Brian" uploads the following resource
| resource | to |
| simple.pdf | Shares/folder_to_shared |
| resource | to |
| simple.pdf | Shares/folder_to_shared |
| testavatar.jpeg | Shares/folder_to_customShared |
And "Brian" copies the following resource using dropdown-menu
| resource | to |
| Shares/folder_to_shared | Personal |
When "Brian" deletes the following resources
| resource |
| Shares/folder_to_customShared/lorem-big.txt |
When "Alice" opens the "files" app
#Then "Alice" should see the following resources
# | folder_to_shared/lorem_new.txt |
Expand All @@ -59,7 +67,7 @@ Feature: share
| folder_to_shared/lorem_new.txt |
| folder_to_shared |
And "Alice" logs out
And "Brian" opens the "files" app
#And "Brian" opens the "files" app
#Then "Brian" should not see the following resource
# | Shares/folder_to_shared |
And "Brian" logs out
Expand All @@ -77,15 +85,18 @@ Feature: share
And "Alice" uploads the following resource
| resource | to |
| testavatar.jpeg | folder_to_shared |
| lorem.txt | |
And "Alice" shares the following resource using the quick action
| resource | recipient | type | role |
| folder_to_shared/testavatar.jpeg | Brian | user | viewer |
| resource | recipient | type | role |
| folder_to_shared/testavatar.jpeg | Brian | user | viewer |
| lorem.txt | Brian | user | custom_permissions:read,update,share |
And "Brian" logs in
And "Brian" opens the "files" app
And "Brian" navigates to the shared with me page
And "Brian" accepts the following share
| name |
| testavatar.jpeg |
| lorem.txt |
And "Brian" navigates to the personal space page
And "Brian" copies the following resource using dropdown-menu
| resource | to |
Expand All @@ -94,11 +105,14 @@ Feature: share
| resource | from |
| testavatar.jpeg | Shares |
And "Alice" updates following sharee role
| resource | recipient | role |
| folder_to_shared/testavatar.jpeg | Brian | editor |
| resource | recipient | role | resourceType |
| folder_to_shared/testavatar.jpeg | Brian | editor | file |
And "Brian" renames the following resource
| resource | as |
| Shares/testavatar.jpeg | testavatar_new.jpeg |
And "Brian" edits the following resources
| resource | content |
| Shares/lorem.txt | new content |
And "Alice" removes following sharee
| resource | recipient |
| folder_to_shared/testavatar.jpeg | Brian |
Expand Down
28 changes: 16 additions & 12 deletions tests/e2e/cucumber/features/smoke/share.ocis.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ Feature: share
| lorem.txt | folder_to_shared |
| lorem-big.txt | folder_to_customShared |
When "Alice" shares the following resource using the sidebar panel
| resource | recipient | type | role |
| folder_to_shared | Brian | user | editor |
| shared_folder | Brian | user | editor |
| folder_to_customShared | Brian | user | editor |
| resource | recipient | type | role | resourceType |
| folder_to_shared | Brian | user | editor | folder |
| shared_folder | Brian | user | editor | folder |
| folder_to_customShared | Brian | user | custom_permissions:read,create,delete | folder |
And "Brian" logs in
And "Brian" opens the "files" app
And "Brian" navigates to the shared with me page
Expand All @@ -49,8 +49,12 @@ Feature: share
| resource | as |
| folder_to_shared/lorem.txt | lorem_new.txt |
And "Brian" uploads the following resource
| resource | to |
| simple.pdf | folder_to_shared |
| resource | to |
| simple.pdf | folder_to_shared |
| testavatar.jpeg | folder_to_customShared |
And "Brian" deletes the following resources
| resource |
| folder_to_customShared/lorem-big.txt |
And "Alice" opens the "files" app
And "Alice" uploads the following resource
| resource | to | option |
Expand Down Expand Up @@ -90,12 +94,12 @@ Feature: share
| testavatar.jpeg |
| simple.pdf |
When "Alice" shares the following resource using the sidebar panel
| resource | recipient | type | role |
| shareToBrian.txt | Brian | user | editor |
| shareToBrian.md | Brian | user | editor |
| testavatar.jpeg | Brian | user | viewer |
| simple.pdf | Brian | user | viewer |
| sharedFile.txt | Brian | user | editor |
| resource | recipient | type | role | resourceType |
| shareToBrian.txt | Brian | user | editor | file |
| shareToBrian.md | Brian | user | editor | file |
| testavatar.jpeg | Brian | user | viewer | file |
| simple.pdf | Brian | user | custom_permissions:read,update,share | file |
| sharedFile.txt | Brian | user | editor | file |
And "Brian" logs in
And "Brian" opens the "files" app
And "Brian" navigates to the shared with me page
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/cucumber/features/smoke/spaces/project.ocis.feature
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ Feature: spaces.personal

# borrowed from share.feature
When "Alice" shares the following resource using the sidebar panel
| resource | recipient | type | role |
| folder_to_shared | Brian | user | editor |
| resource | recipient | type | role | resourceType |
| folder_to_shared | Brian | user | editor | folder |

# team.2
And "Alice" navigates to the projects space page
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/cucumber/features/smoke/tags.ocis.feature
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ Feature: Users can use web to organize tags
| resource | tags |
| folder_to_shared/lorem.txt | tag 1, tag 2 |
When "Alice" shares the following resource using the sidebar panel
| resource | recipient | type | role |
| folder_to_shared | Brian | user | editor |
| resource | recipient | type | role | resourceType |
| folder_to_shared | Brian | user | editor | folder |
And "Alice" logs out

And "Brian" logs in
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/cucumber/steps/ui/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ When(
const resourceObject = new objects.applicationFiles.Resource({ page })

for (const info of stepTable.hashes()) {
await resourceObject.editResourse({ name: info.resource, content: info.content })
await resourceObject.editResource({ name: info.resource, content: info.content })
}
}
)
Expand Down
5 changes: 3 additions & 2 deletions tests/e2e/cucumber/steps/ui/shares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { objects } from '../../../support'

const parseShareTable = function (stepTable: DataTable, usersEnvironment) {
return stepTable.hashes().reduce((acc, stepRow) => {
const { resource, recipient, type, role } = stepRow
const { resource, recipient, type, role, resourceType } = stepRow

if (!acc[resource]) {
acc[resource] = []
Expand All @@ -17,7 +17,8 @@ const parseShareTable = function (stepTable: DataTable, usersEnvironment) {
? usersEnvironment.getGroup({ key: recipient })
: usersEnvironment.getUser({ key: recipient }),
role,
type
type,
resourceType
})

return acc
Expand Down
13 changes: 11 additions & 2 deletions tests/e2e/support/objects/app-files/resource/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,17 @@ export interface editResourcesArgs {

export const editResources = async (args: editResourcesArgs): Promise<void> => {
const { page, name, content } = args
await page.locator(util.format(resourceNameSelector, name)).click()
await editTextDocument({ page, content: content, name })
const { dir: resourceDir } = path.parse(name)

const folderPaths = name.split('/')
const resourceName = folderPaths.pop()

if (resourceDir) {
await clickResource({ page, path: resourceDir })
}

await page.locator(util.format(resourceNameSelector, resourceName)).click()
await editTextDocument({ page, content: content, name: resourceName })
}

export const addTagsToResource = async (args: resourceTagsArgs): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/support/objects/app-files/resource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class Resource {
await showHiddenResources(this.#page)
}

async editResourse(args: Omit<editResourcesArgs, 'page'>): Promise<void> {
async editResource(args: Omit<editResourcesArgs, 'page'>): Promise<void> {
await editResources({ ...args, page: this.#page })
}

Expand Down
45 changes: 36 additions & 9 deletions tests/e2e/support/objects/app-files/share/collaborator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface ICollaborator {
collaborator: User | Group
role: string
type?: CollaboratorType
resourceType?: string
}

export interface InviteCollaboratorsArgs {
Expand Down Expand Up @@ -52,14 +53,20 @@ export default class Collaborator {
private static readonly customPermissionApplyButton =
'//*[contains(@class, "files-recipient-custom-permissions-drop-cancel-confirm-btns")]//button[text()="Apply"]'

static CUSTOM_PERMISSIONS: readonly CustomPermissionType[] = [
static readonly FOLDER_CUSTOM_PERMISSIONS: readonly CustomPermissionType[] = [
'read',
'update',
'create',
'delete',
'share'
]

static readonly FILE_CUSTOM_PERMISSIONS: Omit<CustomPermissionType[], 'create' | 'delete'> = [
'read',
'update',
'share'
]

static async addCollaborator(args: CollaboratorArgs): Promise<void> {
const {
page,
Expand Down Expand Up @@ -93,31 +100,40 @@ export default class Collaborator {
// When adding multiple users/groups at once
// the role of the first collaborator is used as the collaborators role
const role = collaborators[0].role
const resourceType = collaborators[0].resourceType

for (const collaborator of collaborators) {
await Collaborator.addCollaborator({ page, collaborator })
}
await Collaborator.setCollaboratorRole(page, role)
await Collaborator.setCollaboratorRole(page, role, resourceType)
await Collaborator.sendInvitation(page)
}

static async setCustomPermissions(
page: Page,
permissions: CustomPermissionType[]
permissions: CustomPermissionType[],
resourceType: string
): Promise<void> {
const CUSTOM_PERMISSIONS: readonly CustomPermissionType[] =
resourceType === 'folder'
? Collaborator.FOLDER_CUSTOM_PERMISSIONS
: Collaborator.FILE_CUSTOM_PERMISSIONS
for (const permission of permissions) {
if (!Collaborator.CUSTOM_PERMISSIONS.includes(permission)) {
if (!CUSTOM_PERMISSIONS.includes(permission)) {
throw new Error(
'Invalid custom permission: ' +
permission +
'\nAvailable permissions: ' +
Collaborator.CUSTOM_PERMISSIONS
CUSTOM_PERMISSIONS
)
}

await page.check(util.format(Collaborator.customPermissionCheckbox, permission))
}

// uncheck others
const removePermissions = difference(Collaborator.CUSTOM_PERMISSIONS, permissions)
const removePermissions = difference(CUSTOM_PERMISSIONS, permissions)

for (const permission of removePermissions) {
await page.uncheck(util.format(Collaborator.customPermissionCheckbox, permission))
}
Expand All @@ -126,6 +142,7 @@ export default class Collaborator {
static async setCollaboratorRole(
page: Page,
role: string,
resourceType: string,
dropdownSelector?: string,
itemSelector?: string
): Promise<void> {
Expand All @@ -146,7 +163,11 @@ export default class Collaborator {
}

const permissions = custom_permissions.split(',')
await Collaborator.setCustomPermissions(page, permissions as CustomPermissionType[])
await Collaborator.setCustomPermissions(
page,
permissions as CustomPermissionType[],
resourceType
)

return await page.click(Collaborator.customPermissionApplyButton)
}
Expand All @@ -156,7 +177,7 @@ export default class Collaborator {
static async changeCollaboratorRole(args: CollaboratorArgs): Promise<void> {
const {
page,
collaborator: { collaborator, type, role }
collaborator: { collaborator, type, role, resourceType }
} = args

const collaboratorRow = Collaborator.getCollaboratorUserOrGroupSelector(collaborator, type)
Expand All @@ -165,7 +186,13 @@ export default class Collaborator {
collaboratorRow
)
const roleItemSelector = util.format(Collaborator.collaboratorRoleItemSelector, collaboratorRow)
await Collaborator.setCollaboratorRole(page, role, roleDropdownSelector, roleItemSelector)
await Collaborator.setCollaboratorRole(
page,
role,
resourceType,
roleDropdownSelector,
roleItemSelector
)
}

static async removeCollaborator(args: RemoveCollaboratorArgs): Promise<void> {
Expand Down

0 comments on commit ef42754

Please sign in to comment.