From bbf0dff1cc9df01eb45d67ee3a914e1ff1a53b28 Mon Sep 17 00:00:00 2001 From: amrita Date: Wed, 26 Apr 2023 11:07:33 +0545 Subject: [PATCH 1/2] Refactor group store --- tests/e2e/cucumber/environment/index.ts | 2 ++ tests/e2e/cucumber/steps/ui/adminSettings.ts | 3 +-- tests/e2e/support/api/graph/userManagement.ts | 4 ++-- .../e2e/support/environment/userManagement.ts | 19 ++++++++++++++++++ .../app-admin-settings/groups/actions.ts | 6 +++--- .../app-admin-settings/groups/index.ts | 20 ++++++++++++++++--- 6 files changed, 44 insertions(+), 10 deletions(-) diff --git a/tests/e2e/cucumber/environment/index.ts b/tests/e2e/cucumber/environment/index.ts index ea075e86006..211f52e38d3 100644 --- a/tests/e2e/cucumber/environment/index.ts +++ b/tests/e2e/cucumber/environment/index.ts @@ -17,6 +17,7 @@ import { World } from './world' import { state } from './shared' import { createdSpaceStore, createdLinkStore } from '../../support/store' import { User } from '../../support/types' +import { createdGroupStore } from '../../support/store/group' export { World } @@ -110,6 +111,7 @@ After(async function (this: World, { result }: ITestCaseHookParameter) { await cleanUpSpaces(this.usersEnvironment.getUser({ key: 'admin' })) + createdGroupStore.clear() createdLinkStore.clear() }) diff --git a/tests/e2e/cucumber/steps/ui/adminSettings.ts b/tests/e2e/cucumber/steps/ui/adminSettings.ts index d5c9cb852ca..7abd6b3f542 100644 --- a/tests/e2e/cucumber/steps/ui/adminSettings.ts +++ b/tests/e2e/cucumber/steps/ui/adminSettings.ts @@ -413,8 +413,7 @@ When( } await page.reload() for (const info of stepTable.hashes()) { - const group = this.usersEnvironment.getGroup({ key: info.id }) - group.uuid = await groupsObject.createGroup({ key: group.displayName }) + await groupsObject.createGroup({ key: info.id }) } } ) diff --git a/tests/e2e/support/api/graph/userManagement.ts b/tests/e2e/support/api/graph/userManagement.ts index 863321dfc7f..b9af1cd5fd6 100644 --- a/tests/e2e/support/api/graph/userManagement.ts +++ b/tests/e2e/support/api/graph/userManagement.ts @@ -84,8 +84,8 @@ export const createGroup = async ({ checkResponseStatus(response, 'Failed while creating group') - const responseData = await response.json() - group.uuid = responseData.id + const usersEnvironment = new UsersEnvironment() + usersEnvironment.storeGroup({ group: { ...group, uuid: (await response.json()).id } }) return group } diff --git a/tests/e2e/support/environment/userManagement.ts b/tests/e2e/support/environment/userManagement.ts index 48c93e1c78f..113a7916b5b 100644 --- a/tests/e2e/support/environment/userManagement.ts +++ b/tests/e2e/support/environment/userManagement.ts @@ -74,6 +74,16 @@ export class UsersEnvironment { return dummyGroupStore.get(uniqueKey) } + getCreatedGroup({ key }: { key: string }): Group { + const uniqueKey = key.toLowerCase() + + if (!createdGroupStore.has(uniqueKey)) { + throw new Error(`group with key '${uniqueKey}' not found`) + } + console.log(createdGroupStore.get(uniqueKey)) + return createdGroupStore.get(uniqueKey) + } + createGroup({ key, group }: { key: string; group: Group }): Group { const uniqueKey = key.toLowerCase() @@ -85,4 +95,13 @@ export class UsersEnvironment { return group } + + storeGroup({ group }: { group: Group }): Group { + if (createdGroupStore.has(group.id)) { + throw new Error(`user with key '${group.id}' already exists`) + } + createdGroupStore.set(group.id, group) + + return group + } } diff --git a/tests/e2e/support/objects/app-admin-settings/groups/actions.ts b/tests/e2e/support/objects/app-admin-settings/groups/actions.ts index eb7804c5421..072d4a9b81c 100644 --- a/tests/e2e/support/objects/app-admin-settings/groups/actions.ts +++ b/tests/e2e/support/objects/app-admin-settings/groups/actions.ts @@ -18,7 +18,7 @@ const closeEditPanel = '.sidebar-panel__header .header__close' const userInput = '#%s-input' const compareDialogConfirm = '.compare-save-dialog-confirm-btn' -export const createGroup = async (args: { page: Page; key: string }): Promise => { +export const createGroup = async (args: { page: Page; key: string }): Promise => { const { page, key } = args await page.locator(newGroupBtn).click() await page.locator(createGroupInput).fill(key) @@ -30,8 +30,8 @@ export const createGroup = async (args: { page: Page; key: string }): Promise => { diff --git a/tests/e2e/support/objects/app-admin-settings/groups/index.ts b/tests/e2e/support/objects/app-admin-settings/groups/index.ts index 152962c39f2..8b25bc1f80d 100644 --- a/tests/e2e/support/objects/app-admin-settings/groups/index.ts +++ b/tests/e2e/support/objects/app-admin-settings/groups/index.ts @@ -17,21 +17,35 @@ export class Groups { this.#usersEnvironment = new UsersEnvironment() this.#page = page } + getUUID({ key }: { key: string }): string { - return this.#usersEnvironment.getGroup({ key }).uuid + return this.#usersEnvironment.getCreatedGroup({ key }).uuid } - async createGroup({ key }: { key: string }): Promise { - return await createGroup({ page: this.#page, key: key }) + + async createGroup({ key }: { key: string }): Promise { + const group = this.#usersEnvironment.getGroup({ key }) + const response = await createGroup({ page: this.#page, key: group.displayName }) + this.#usersEnvironment.storeGroup({ + group: { + id: key, + uuid: response['id'], + displayName: response['displayName'] + } + }) } + getDisplayedGroups(): Promise { return getDisplayedGroups({ page: this.#page }) } + async selectGroup({ key }: { key: string }): Promise { await selectGroup({ page: this.#page, uuid: this.getUUID({ key }) }) } + async deleteGroupUsingBatchAction({ groupIds }: { groupIds: string[] }): Promise { await deleteGrouprUsingBatchAction({ page: this.#page, groupIds }) } + async deleteGroupUsingContextMenu({ key }: { key: string }): Promise { await deleteGroupUsingContextMenu({ page: this.#page, uuid: this.getUUID({ key }) }) } From da1fb181d6c3982f9487da1be7afa75be0d65f06 Mon Sep 17 00:00:00 2001 From: amrita Date: Fri, 5 May 2023 14:00:45 +0545 Subject: [PATCH 2/2] Minor changes --- tests/e2e/cucumber/environment/index.ts | 3 +- tests/e2e/support/api/graph/userManagement.ts | 2 +- .../e2e/support/environment/userManagement.ts | 33 ++++++------------- .../app-admin-settings/groups/index.ts | 2 +- .../app-admin-settings/users/actions.ts | 2 +- tests/e2e/support/store/index.ts | 4 +-- 6 files changed, 16 insertions(+), 30 deletions(-) diff --git a/tests/e2e/cucumber/environment/index.ts b/tests/e2e/cucumber/environment/index.ts index 211f52e38d3..ecdbe99b88e 100644 --- a/tests/e2e/cucumber/environment/index.ts +++ b/tests/e2e/cucumber/environment/index.ts @@ -15,9 +15,8 @@ import { config } from '../../config' import { api, environment } from '../../support' import { World } from './world' import { state } from './shared' -import { createdSpaceStore, createdLinkStore } from '../../support/store' +import { createdSpaceStore, createdLinkStore, createdGroupStore } from '../../support/store' import { User } from '../../support/types' -import { createdGroupStore } from '../../support/store/group' export { World } diff --git a/tests/e2e/support/api/graph/userManagement.ts b/tests/e2e/support/api/graph/userManagement.ts index b9af1cd5fd6..eda28946976 100644 --- a/tests/e2e/support/api/graph/userManagement.ts +++ b/tests/e2e/support/api/graph/userManagement.ts @@ -85,7 +85,7 @@ export const createGroup = async ({ checkResponseStatus(response, 'Failed while creating group') const usersEnvironment = new UsersEnvironment() - usersEnvironment.storeGroup({ group: { ...group, uuid: (await response.json()).id } }) + usersEnvironment.storeCreatedGroup({ group: { ...group, uuid: (await response.json()).id } }) return group } diff --git a/tests/e2e/support/environment/userManagement.ts b/tests/e2e/support/environment/userManagement.ts index 113a7916b5b..484b45fea0c 100644 --- a/tests/e2e/support/environment/userManagement.ts +++ b/tests/e2e/support/environment/userManagement.ts @@ -1,6 +1,5 @@ import { Group, User } from '../types' -import { dummyUserStore, dummyGroupStore } from '../store' -import { createdUserStore } from '../store/user' +import { dummyUserStore, dummyGroupStore, createdUserStore, createdGroupStore } from '../store' export class UsersEnvironment { getUser({ key }: { key: string }): User { @@ -65,38 +64,26 @@ export class UsersEnvironment { } getGroup({ key }: { key: string }): Group { - const uniqueKey = key.toLowerCase() + const groupKey = key.toLowerCase() - if (!dummyGroupStore.has(uniqueKey)) { - throw new Error(`group with key '${uniqueKey}' not found`) + if (!dummyGroupStore.has(groupKey)) { + throw new Error(`group with key '${groupKey}' not found`) } - return dummyGroupStore.get(uniqueKey) + return dummyGroupStore.get(groupKey) } getCreatedGroup({ key }: { key: string }): Group { - const uniqueKey = key.toLowerCase() + const groupKey = key.toLowerCase() - if (!createdGroupStore.has(uniqueKey)) { - throw new Error(`group with key '${uniqueKey}' not found`) + if (!createdGroupStore.has(groupKey)) { + throw new Error(`group with key '${groupKey}' not found`) } - console.log(createdGroupStore.get(uniqueKey)) - return createdGroupStore.get(uniqueKey) - } - - createGroup({ key, group }: { key: string; group: Group }): Group { - const uniqueKey = key.toLowerCase() - - if (dummyUserStore.has(uniqueKey)) { - throw new Error(`group with key '${uniqueKey}' already exists`) - } - - dummyGroupStore.set(uniqueKey, group) - return group + return createdGroupStore.get(groupKey) } - storeGroup({ group }: { group: Group }): Group { + storeCreatedGroup({ group }: { group: Group }): Group { if (createdGroupStore.has(group.id)) { throw new Error(`user with key '${group.id}' already exists`) } diff --git a/tests/e2e/support/objects/app-admin-settings/groups/index.ts b/tests/e2e/support/objects/app-admin-settings/groups/index.ts index 8b25bc1f80d..06aef42ffd7 100644 --- a/tests/e2e/support/objects/app-admin-settings/groups/index.ts +++ b/tests/e2e/support/objects/app-admin-settings/groups/index.ts @@ -25,7 +25,7 @@ export class Groups { async createGroup({ key }: { key: string }): Promise { const group = this.#usersEnvironment.getGroup({ key }) const response = await createGroup({ page: this.#page, key: group.displayName }) - this.#usersEnvironment.storeGroup({ + this.#usersEnvironment.storeCreatedGroup({ group: { id: key, uuid: response['id'], diff --git a/tests/e2e/support/objects/app-admin-settings/users/actions.ts b/tests/e2e/support/objects/app-admin-settings/users/actions.ts index 245d2ac9d16..8571846b0d7 100644 --- a/tests/e2e/support/objects/app-admin-settings/users/actions.ts +++ b/tests/e2e/support/objects/app-admin-settings/users/actions.ts @@ -429,5 +429,5 @@ export const waitForEditPanelToBeVisible = async (args: { page: Page }): Promise const getGroupId = (group: string): string => { const usersEnvironment = new UsersEnvironment() - return usersEnvironment.getGroup({ key: group }).uuid + return usersEnvironment.getCreatedGroup({ key: group }).uuid } diff --git a/tests/e2e/support/store/index.ts b/tests/e2e/support/store/index.ts index bcb029f0883..bef99b9b139 100644 --- a/tests/e2e/support/store/index.ts +++ b/tests/e2e/support/store/index.ts @@ -1,6 +1,6 @@ export { actorStore } from './actor' export { createdLinkStore } from './link' export { createdSpaceStore } from './space' -export { dummyUserStore } from './user' -export { dummyGroupStore } from './group' +export { dummyUserStore, createdUserStore } from './user' +export { dummyGroupStore, createdGroupStore } from './group' export { userRoleStore } from './role'