Skip to content

Commit

Permalink
Fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Oct 12, 2022
1 parent 7cdfc30 commit a8dc37c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
23 changes: 14 additions & 9 deletions tests/e2e/cucumber/steps/app-files/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,14 @@ Then(
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const resourceObject = new objects.applicationFiles.Resource({ page })
for (const info of stepTable.hashes()) {
const message = await resourceObject.deleteTrashBin({ resource: info.resource })
const paths = info.resource.split('/')
if (actionType === 'should not') {
expect(message).toBe(`failed to delete "${paths[paths.length - 1]}"`)
const isVisible = await resourceObject.isDeleteTrashBinButtonVisible({
resource: info.resource
})
expect(isVisible).toBe(false)
} else {
const message = await resourceObject.deleteTrashBin({ resource: info.resource })
const paths = info.resource.split('/')
expect(message).toBe(`"${paths[paths.length - 1]}" was deleted successfully`)
}
}
Expand All @@ -190,14 +193,16 @@ Then(
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const resourceObject = new objects.applicationFiles.Resource({ page })
for (const info of stepTable.hashes()) {
const message = await resourceObject.restoreTrashBin({
resource: info.resource,
actionType
})
const paths = info.resource.split('/')
if (actionType === 'should not') {
expect(message).toBe(`failed to restore "${paths[paths.length - 1]}"`)
const isVisible = await resourceObject.isRestoreTrashBinButtonVisible({
resource: info.resource
})
expect(isVisible).toBe(false)
} else {
const message = await resourceObject.restoreTrashBin({
resource: info.resource
})
const paths = info.resource.split('/')
expect(message).toBe(`${paths[paths.length - 1]} was restored successfully`)
}
}
Expand Down
29 changes: 28 additions & 1 deletion tests/e2e/support/objects/app-files/resource/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,22 @@ export const deleteResourceTrashbin = async (args: deleteResourceArgs): Promise<
return message.trim().toLowerCase()
}

export const getDeleteResourceButtonVisibility = async (
args: deleteResourceArgs
): Promise<boolean> => {
const { page, resource } = args
const resourceCheckbox = page.locator(
util.format(checkBoxForTrashbin, `/${resource.replace(/^\/+/, '')}`)
)
await new Promise((resolve) => setTimeout(resolve, 5000))
if (!(await resourceCheckbox.isChecked())) {
await resourceCheckbox.check()
}
return await page.locator(permanentDeleteButton).isVisible()
}

export interface restoreResourceTrashbinArgs {
resource: string
actionType: string
page: Page
}

Expand All @@ -499,6 +512,20 @@ export const restoreResourceTrashbin = async (
return message.trim().toLowerCase()
}

export const getRestoreResourceButtonVisibility = async (
args: restoreResourceTrashbinArgs
): Promise<boolean> => {
const { page, resource } = args
const resourceCheckbox = page.locator(
util.format(checkBoxForTrashbin, `/${resource.replace(/^\/+/, '')}`)
)
await new Promise((resolve) => setTimeout(resolve, 5000))
if (!(await resourceCheckbox.isChecked())) {
await resourceCheckbox.check()
}
return await page.locator(restoreResourceButton).isVisible()
}

export interface searchResourceGlobalSearchArgs {
keyword: string
page: Page
Expand Down
14 changes: 13 additions & 1 deletion tests/e2e/support/objects/app-files/resource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import {
editResources,
editResourcesArgs,
openFileInViewer,
openFileInViewerArgs
openFileInViewerArgs,
getDeleteResourceButtonVisibility,
getRestoreResourceButtonVisibility
} from './actions'

export class Resource {
Expand Down Expand Up @@ -115,13 +117,23 @@ export class Resource {
return message
}

async isDeleteTrashBinButtonVisible(args: Omit<deleteResourceArgs, 'page'>): Promise<boolean> {
return await getDeleteResourceButtonVisibility({ ...args, page: this.#page })
}

async restoreTrashBin(args: Omit<restoreResourceTrashbinArgs, 'page'>): Promise<string> {
const startUrl = this.#page.url()
const message = await restoreResourceTrashbin({ ...args, page: this.#page })
await this.#page.goto(startUrl)
return message
}

async isRestoreTrashBinButtonVisible(
args: Omit<restoreResourceTrashbinArgs, 'page'>
): Promise<boolean> {
return await getRestoreResourceButtonVisibility({ ...args, page: this.#page })
}

async searchResource(args: Omit<searchResourceGlobalSearchArgs, 'page'>): Promise<void> {
await searchResourceGlobalSearch({ ...args, page: this.#page })
}
Expand Down

0 comments on commit a8dc37c

Please sign in to comment.