Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only][full-ci] Refactor group store for e2e tests #8914

Merged
merged 2 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/e2e/cucumber/environment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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'

export { World }
Expand Down Expand Up @@ -110,6 +110,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.storeCreatedGroup({ group: { ...group, uuid: (await response.json()).id } })
return group
}

Expand Down
28 changes: 17 additions & 11 deletions tests/e2e/support/environment/userManagement.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -65,23 +64,30 @@ 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)
}

createGroup({ key, group }: { key: string; group: Group }): Group {
const uniqueKey = key.toLowerCase()
getCreatedGroup({ key }: { key: string }): Group {
const groupKey = key.toLowerCase()

if (dummyUserStore.has(uniqueKey)) {
throw new Error(`group with key '${uniqueKey}' already exists`)
if (!createdGroupStore.has(groupKey)) {
throw new Error(`group with key '${groupKey}' not found`)
}

dummyGroupStore.set(uniqueKey, group)
return createdGroupStore.get(groupKey)
}

storeCreatedGroup({ 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
}
Expand Down
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.storeCreatedGroup({
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions tests/e2e/support/store/index.ts
Original file line number Diff line number Diff line change
@@ -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'