From addcc6c21dadbb1c992d22a94f88a15955541ce1 Mon Sep 17 00:00:00 2001 From: amrita Date: Thu, 5 Jan 2023 14:53:16 +0545 Subject: [PATCH] Add custom permission test for personal space Added custom Persion for both file and folder Refactor share related steps --- .../cucumber/features/smoke/reshare.feature | 12 ++--- .../cucumber/features/smoke/search.feature | 6 +-- .../features/smoke/share.oc10.feature | 46 ++++++++++++------- .../features/smoke/share.ocis.feature | 28 ++++++----- .../smoke/spaces/project.ocis.feature | 4 +- .../cucumber/features/smoke/tags.ocis.feature | 4 +- tests/e2e/cucumber/steps/ui/resources.ts | 2 +- tests/e2e/cucumber/steps/ui/shares.ts | 5 +- .../objects/app-files/resource/actions.ts | 13 +++++- .../objects/app-files/resource/index.ts | 2 +- .../objects/app-files/share/collaborator.ts | 45 ++++++++++++++---- 11 files changed, 111 insertions(+), 56 deletions(-) diff --git a/tests/e2e/cucumber/features/smoke/reshare.feature b/tests/e2e/cucumber/features/smoke/reshare.feature index 4dd69ce603d..dfd0fbd0a43 100644 --- a/tests/e2e/cucumber/features/smoke/reshare.feature +++ b/tests/e2e/cucumber/features/smoke/reshare.feature @@ -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 @@ -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 @@ -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 diff --git a/tests/e2e/cucumber/features/smoke/search.feature b/tests/e2e/cucumber/features/smoke/search.feature index 1296310fd2a..28aee379264 100644 --- a/tests/e2e/cucumber/features/smoke/search.feature +++ b/tests/e2e/cucumber/features/smoke/search.feature @@ -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 diff --git a/tests/e2e/cucumber/features/smoke/share.oc10.feature b/tests/e2e/cucumber/features/smoke/share.oc10.feature index f6f414b9265..542f2c564c2 100644 --- a/tests/e2e/cucumber/features/smoke/share.oc10.feature +++ b/tests/e2e/cucumber/features/smoke/share.oc10.feature @@ -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 | @@ -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 @@ -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 | @@ -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 | diff --git a/tests/e2e/cucumber/features/smoke/share.ocis.feature b/tests/e2e/cucumber/features/smoke/share.ocis.feature index 63fab037dc9..347ea4b1de1 100644 --- a/tests/e2e/cucumber/features/smoke/share.ocis.feature +++ b/tests/e2e/cucumber/features/smoke/share.ocis.feature @@ -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 @@ -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 | @@ -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 diff --git a/tests/e2e/cucumber/features/smoke/spaces/project.ocis.feature b/tests/e2e/cucumber/features/smoke/spaces/project.ocis.feature index 355b635bcf3..acdda058808 100644 --- a/tests/e2e/cucumber/features/smoke/spaces/project.ocis.feature +++ b/tests/e2e/cucumber/features/smoke/spaces/project.ocis.feature @@ -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 diff --git a/tests/e2e/cucumber/features/smoke/tags.ocis.feature b/tests/e2e/cucumber/features/smoke/tags.ocis.feature index bee49be49e8..2cd716b2bcb 100644 --- a/tests/e2e/cucumber/features/smoke/tags.ocis.feature +++ b/tests/e2e/cucumber/features/smoke/tags.ocis.feature @@ -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 diff --git a/tests/e2e/cucumber/steps/ui/resources.ts b/tests/e2e/cucumber/steps/ui/resources.ts index 46e24309aa4..eb415f73e62 100644 --- a/tests/e2e/cucumber/steps/ui/resources.ts +++ b/tests/e2e/cucumber/steps/ui/resources.ts @@ -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 }) } } ) diff --git a/tests/e2e/cucumber/steps/ui/shares.ts b/tests/e2e/cucumber/steps/ui/shares.ts index 06d80b730b5..8a7127aef44 100644 --- a/tests/e2e/cucumber/steps/ui/shares.ts +++ b/tests/e2e/cucumber/steps/ui/shares.ts @@ -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] = [] @@ -17,7 +17,8 @@ const parseShareTable = function (stepTable: DataTable, usersEnvironment) { ? usersEnvironment.getGroup({ key: recipient }) : usersEnvironment.getUser({ key: recipient }), role, - type + type, + resourceType }) return acc diff --git a/tests/e2e/support/objects/app-files/resource/actions.ts b/tests/e2e/support/objects/app-files/resource/actions.ts index e860a724703..64422d2f67d 100644 --- a/tests/e2e/support/objects/app-files/resource/actions.ts +++ b/tests/e2e/support/objects/app-files/resource/actions.ts @@ -772,8 +772,17 @@ export interface editResourcesArgs { export const editResources = async (args: editResourcesArgs): Promise => { 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 => { diff --git a/tests/e2e/support/objects/app-files/resource/index.ts b/tests/e2e/support/objects/app-files/resource/index.ts index 1f2cec58827..ac3e66fa954 100644 --- a/tests/e2e/support/objects/app-files/resource/index.ts +++ b/tests/e2e/support/objects/app-files/resource/index.ts @@ -188,7 +188,7 @@ export class Resource { await showHiddenResources(this.#page) } - async editResourse(args: Omit): Promise { + async editResource(args: Omit): Promise { await editResources({ ...args, page: this.#page }) } diff --git a/tests/e2e/support/objects/app-files/share/collaborator.ts b/tests/e2e/support/objects/app-files/share/collaborator.ts index 707c60e00da..709288e3204 100644 --- a/tests/e2e/support/objects/app-files/share/collaborator.ts +++ b/tests/e2e/support/objects/app-files/share/collaborator.ts @@ -7,6 +7,7 @@ export interface ICollaborator { collaborator: User | Group role: string type?: CollaboratorType + resourceType?: string } export interface InviteCollaboratorsArgs { @@ -52,7 +53,7 @@ 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', @@ -60,6 +61,12 @@ export default class Collaborator { 'share' ] + static readonly FILE_CUSTOM_PERMISSIONS: Omit = [ + 'read', + 'update', + 'share' + ] + static async addCollaborator(args: CollaboratorArgs): Promise { const { page, @@ -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 { + 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)) } @@ -126,6 +142,7 @@ export default class Collaborator { static async setCollaboratorRole( page: Page, role: string, + resourceType: string, dropdownSelector?: string, itemSelector?: string ): Promise { @@ -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) } @@ -156,7 +177,7 @@ export default class Collaborator { static async changeCollaboratorRole(args: CollaboratorArgs): Promise { const { page, - collaborator: { collaborator, type, role } + collaborator: { collaborator, type, role, resourceType } } = args const collaboratorRow = Collaborator.getCollaboratorUserOrGroupSelector(collaborator, type) @@ -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 {