Skip to content

Commit

Permalink
Restructure stores for e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amrita-shrestha committed Apr 18, 2023
1 parent 2dca419 commit 1339d86
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 41 deletions.
8 changes: 4 additions & 4 deletions 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 { spaceStore, linkStore } from '../../support/store'
import { createdSpaceStore, createdLinkStore } from '../../support/store'
import { User } from '../../support/types'

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

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

linkStore.clear()
createdLinkStore.clear()
})

AfterAll(() => state.browser && state.browser.close())
Expand All @@ -119,7 +119,7 @@ setWorldConstructor(World)

const cleanUpSpaces = async (adminUser: User) => {
const requests = []
spaceStore.forEach((space) => {
createdSpaceStore.forEach((space) => {
requests.push(
api.graph
.disableSpace({
Expand All @@ -137,5 +137,5 @@ const cleanUpSpaces = async (adminUser: User) => {
)
})
await Promise.all(requests)
spaceStore.clear()
createdSpaceStore.clear()
}
4 changes: 2 additions & 2 deletions tests/e2e/cucumber/steps/ui/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DateTime } from 'luxon'
import { World } from '../../environment'
import { objects } from '../../../support'
import { processDelete, processDownload } from './resources'
import { linkStore } from '../../../support/store'
import { createdLinkStore } from '../../../support/store'

When(
'{string} opens the public link {string}',
Expand Down Expand Up @@ -145,7 +145,7 @@ When(
Then(
'{string} should not be able to open the old link {string}',
function (this: World, stepUser: string, name: string): void {
expect(linkStore.has(name)).toBe(false)
expect(createdLinkStore.has(name)).toBe(false)
}
)

Expand Down
20 changes: 10 additions & 10 deletions tests/e2e/support/environment/link.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { Link } from '../types'
import { linkStore } from '../store'
import { createdLinkStore } from '../store'

export class LinksEnvironment {
getLink({ name }: { name: string }): Link {
if (!linkStore.has(name)) {
if (!createdLinkStore.has(name)) {
throw new Error(`link with name '${name}' not found`)
}
return linkStore.get(name)
return createdLinkStore.get(name)
}

updateLinkName({ key, link }: { key: string; link: Link }): any {
if (!linkStore.has(key)) {
if (!createdLinkStore.has(key)) {
throw new Error(`link with name '${key}' not found`)
}
linkStore.set(link.name, link)
linkStore.delete(key)
createdLinkStore.set(link.name, link)
createdLinkStore.delete(key)
}

createLink({ key, link }: { key: string; link: Link }): Link {
if (linkStore.has(key)) {
if (createdLinkStore.has(key)) {
throw new Error(`link with key '${key}' already exists`)
}
linkStore.set(key, link)
createdLinkStore.set(key, link)
return link
}

deleteLink({ key }: { key: string }): boolean {
if (linkStore.has(key)) {
return linkStore.delete(key)
if (createdLinkStore.has(key)) {
return createdLinkStore.delete(key)
}
throw new Error(`link with key '${key}' doesn't exist`)
}
Expand Down
10 changes: 5 additions & 5 deletions tests/e2e/support/environment/space.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { Space } from '../types'
import { spaceStore } from '../store'
import { createdSpaceStore } from '../store'

export class SpacesEnvironment {
getSpace({ key }: { key: string }): Space {
if (!spaceStore.has(key)) {
if (!createdSpaceStore.has(key)) {
throw new Error(`space with key '${key}' not found`)
}

return spaceStore.get(key)
return createdSpaceStore.get(key)
}

createSpace({ key, space }: { key: string; space: Space }): Space {
if (spaceStore.has(key)) {
if (createdSpaceStore.has(key)) {
throw new Error(`link with key '${key}' already exists`)
}

spaceStore.set(key, space)
createdSpaceStore.set(key, space)

return space
}
Expand Down
18 changes: 9 additions & 9 deletions tests/e2e/support/environment/userManagement.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import { Group, User } from '../types'
import { userStore, groupStore } from '../store'
import { dummyUserStore, dummyGroupStore } from '../store'

export class UsersEnvironment {
getUser({ key }: { key: string }): User {
const uniqueKey = key.toLowerCase()

if (!userStore.has(uniqueKey)) {
if (!dummyUserStore.has(uniqueKey)) {
throw new Error(`user with key '${uniqueKey}' not found`)
}

return userStore.get(uniqueKey)
return dummyUserStore.get(uniqueKey)
}

createUser({ key, user }: { key: string; user: User }): User {
const uniqueKey = key.toLowerCase()

if (userStore.has(uniqueKey)) {
if (dummyUserStore.has(uniqueKey)) {
throw new Error(`user with key '${uniqueKey}' already exists`)
}

userStore.set(uniqueKey, user)
dummyUserStore.set(uniqueKey, user)

return user
}

getGroup({ key }: { key: string }): Group {
const uniqueKey = key.toLowerCase()

if (!groupStore.has(uniqueKey)) {
if (!dummyGroupStore.has(uniqueKey)) {
throw new Error(`group with key '${uniqueKey}' not found`)
}

return groupStore.get(uniqueKey)
return dummyGroupStore.get(uniqueKey)
}

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

if (userStore.has(uniqueKey)) {
if (dummyUserStore.has(uniqueKey)) {
throw new Error(`group with key '${uniqueKey}' already exists`)
}

groupStore.set(uniqueKey, group)
dummyGroupStore.set(uniqueKey, group)

return group
}
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/support/objects/app-files/share/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { sidebar } from '../utils'
import { clickResource } from '../resource/actions'
import { copyLinkArgs, waitForPopupNotPresent } from '../link/actions'
import { config } from '../../../../config.js'
import { linkStore } from '../../../store'
import { createdLinkStore } from '../../../store'

const filesSharedWithMeAccepted =
'#files-shared-with-me-accepted-section [data-test-resource-name="%s"]'
Expand Down Expand Up @@ -215,8 +215,8 @@ export const copyQuickLink = async (args: copyLinkArgs): Promise<string> => {

await waitForPopupNotPresent(page)

if (url && !linkStore.has(linkName)) {
linkStore.set(linkName, { name: linkName, url })
if (url && !createdLinkStore.has(linkName)) {
createdLinkStore.set(linkName, { name: linkName, url })
}
return url
}
4 changes: 3 additions & 1 deletion tests/e2e/support/store/group.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Group } from '../types'

export const groupStore = new Map<string, Group>([
export const dummyGroupStore = new Map<string, Group>([
[
'security',
{
Expand All @@ -23,3 +23,5 @@ export const groupStore = new Map<string, Group>([
}
]
])

export const createdGroupStore = new Map<string, Group>()
8 changes: 4 additions & 4 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 { linkStore } from './link'
export { spaceStore } from './space'
export { userStore } from './user'
export { groupStore } from './group'
export { createdLinkStore } from './link'
export { createdSpaceStore } from './space'
export { dummyUserStore } from './user'
export { dummyGroupStore } from './group'
export { userRoleStore } from './role'
2 changes: 1 addition & 1 deletion tests/e2e/support/store/link.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Link } from '../types'

export const linkStore = new Map<string, Link>()
export const createdLinkStore = new Map<string, Link>()
2 changes: 1 addition & 1 deletion tests/e2e/support/store/space.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Space } from '../types'

export const spaceStore = new Map<string, Space>()
export const createdSpaceStore = new Map<string, Space>()
4 changes: 3 additions & 1 deletion tests/e2e/support/store/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { User } from '../types'

export const userStore = new Map<string, User>([
export const dummyUserStore = new Map<string, User>([
[
'admin',
{
Expand Down Expand Up @@ -65,3 +65,5 @@ export const userStore = new Map<string, User>([
}
]
])

export const createdUserStore = new Map<string, User>()

0 comments on commit 1339d86

Please sign in to comment.