Skip to content

Commit

Permalink
Refactor and fix CI failure
Browse files Browse the repository at this point in the history
  • Loading branch information
SagarGi committed Feb 2, 2023
1 parent 56a500e commit fd25afe
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ Feature: spaces participant management
And "Anonymous" uploads the following resources in public link page
| resource |
| textfile.txt |
And "Anonymous" deletes the following resources from public link
| resource |
| lorem.txt |
And "Anonymous" deletes the following resources from public link using sidebar panel
| resource | from |
| lorem.txt | |
When "Brian" deletes the following resources using the sidebar panel
| resource | from |
| textfile.txt | parent |
Expand Down
15 changes: 9 additions & 6 deletions tests/e2e/cucumber/steps/ui/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { kebabCase } from 'lodash'
import { DateTime } from 'luxon'
import { World } from '../../environment'
import { objects } from '../../../support'
import { processDownload } from './resources'
import { processDelete, processDownload } from './resources'
import { linkStore } from '../../../support/store'

When(
Expand Down Expand Up @@ -128,12 +128,15 @@ Then(
)

When(
'{string} deletes the following resources from public link',
async function (this: World, stepUser: string, stepTable: DataTable): Promise<void> {
/^"([^"]*)" deletes the following resources from public link using (sidebar panel| batch action)$/,
async function (
this: World,
stepUser: string,
actionType: string,
stepTable: DataTable
): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const pageObject = new objects.applicationFiles.page.Public({ page })
for (const info of stepTable.hashes()) {
await pageObject.delete({ resource: info.resource })
}
await processDelete(stepTable, pageObject, actionType)
}
)
48 changes: 26 additions & 22 deletions tests/e2e/cucumber/steps/ui/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,9 @@ When(
actionType: string,
stepTable: DataTable
) {
let files, parentFolder
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const resourceObject = new objects.applicationFiles.Resource({ page })
const deleteInfo = stepTable.hashes().reduce((acc, stepRow) => {
const { resource, from } = stepRow
const resourceInfo = {
name: resource
}
if (!acc[from]) {
acc[from] = []
}
acc[from].push(resourceInfo)
return acc
}, {})

for (const folder of Object.keys(deleteInfo)) {
files = deleteInfo[folder]
parentFolder = folder !== 'undefined' ? folder : null
await resourceObject.deleteWithOption({
folder: parentFolder,
resources: files,
via: actionType === 'batch action' ? 'BATCH_ACTION' : 'SIDEBAR_PANEL'
})
}
await processDelete(stepTable, resourceObject, actionType)
}
)

Expand Down Expand Up @@ -282,6 +261,31 @@ When(
}
)

export const processDelete = async (stepTable: DataTable, pageObject: any, actionType: string) => {
let files, parentFolder
const deleteInfo = stepTable.hashes().reduce((acc, stepRow) => {
const { resource, from } = stepRow
const resourceInfo = {
name: resource
}
if (!acc[from]) {
acc[from] = []
}
acc[from].push(resourceInfo)
return acc
}, {})

for (const folder of Object.keys(deleteInfo)) {
files = deleteInfo[folder]
parentFolder = folder !== 'undefined' ? folder : null
await pageObject.delete({
folder: parentFolder,
resources: files,
via: actionType === 'batch action' ? 'BATCH_ACTION' : 'SIDEBAR_PANEL'
})
}
}

export const processDownload = async (
stepTable: DataTable,
pageObject: any,
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/support/objects/app-files/page/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { File } from '../../../types'
import util from 'util'
import path from 'path'
import {
deleteResource,
deleteResourceArgs,
deleteResourceViaOption,
deleteResourceViaOptionArgs,
downloadResources,
downloadResourcesArgs,
renameResource,
Expand Down Expand Up @@ -72,9 +72,9 @@ export class Public {
await this.#page.locator('body').click()
}

async delete(args: Omit<deleteResourceArgs, 'page'>): Promise<void> {
async delete(args: Omit<deleteResourceViaOptionArgs, 'page'>): Promise<void> {
const startUrl = this.#page.url()
await deleteResource({ ...args, page: this.#page })
await deleteResourceViaOption({ ...args, page: this.#page })
await this.#page.goto(startUrl)
}
}
2 changes: 1 addition & 1 deletion tests/e2e/support/objects/app-files/resource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class Resource {
}
}

async deleteWithOption(args: Omit<deleteResourceViaOptionArgs, 'page'>): Promise<void> {
async delete(args: Omit<deleteResourceViaOptionArgs, 'page'>): Promise<void> {
const startUrl = this.#page.url()
await deleteResourceViaOption({ ...args, page: this.#page })
await this.#page.goto(startUrl)
Expand Down

0 comments on commit fd25afe

Please sign in to comment.