Skip to content

Commit

Permalink
Refactor group store
Browse files Browse the repository at this point in the history
  • Loading branch information
amrita-shrestha committed May 5, 2023
1 parent 7aea053 commit bbf0dff
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 10 deletions.
2 changes: 2 additions & 0 deletions tests/e2e/cucumber/environment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -110,6 +111,7 @@ After(async function (this: World, { result }: ITestCaseHookParameter) {

await cleanUpSpaces(this.usersEnvironment.getUser({ key: 'admin' }))

createdGroupStore.clear()
createdLinkStore.clear()
})

Expand Down
3 changes: 1 addition & 2 deletions tests/e2e/cucumber/steps/ui/adminSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
}
)
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/support/api/graph/userManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
19 changes: 19 additions & 0 deletions tests/e2e/support/environment/userManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> => {
export const createGroup = async (args: { page: Page; key: string }): Promise<Response> => {
const { page, key } = args
await page.locator(newGroupBtn).click()
await page.locator(createGroupInput).fill(key)
Expand All @@ -30,8 +30,8 @@ export const createGroup = async (args: { page: Page; key: string }): Promise<st
),
page.locator(actionConfirmButton).click()
])
const group = await response.json()
return group.id

return await response.json()
}

export const getDisplayedGroups = async (args: { page: Page }): Promise<string[]> => {
Expand Down
20 changes: 17 additions & 3 deletions tests/e2e/support/objects/app-admin-settings/groups/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
return await createGroup({ page: this.#page, key: key })

async createGroup({ key }: { key: string }): Promise<void> {
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<string[]> {
return getDisplayedGroups({ page: this.#page })
}

async selectGroup({ key }: { key: string }): Promise<void> {
await selectGroup({ page: this.#page, uuid: this.getUUID({ key }) })
}

async deleteGroupUsingBatchAction({ groupIds }: { groupIds: string[] }): Promise<void> {
await deleteGrouprUsingBatchAction({ page: this.#page, groupIds })
}

async deleteGroupUsingContextMenu({ key }: { key: string }): Promise<void> {
await deleteGroupUsingContextMenu({ page: this.#page, uuid: this.getUUID({ key }) })
}
Expand Down

0 comments on commit bbf0dff

Please sign in to comment.