Skip to content

Commit

Permalink
[tests-only][full-ci]Expand kinder garden feature to delete serveral …
Browse files Browse the repository at this point in the history
…`objects/resources` (#8348)
  • Loading branch information
SagarGi authored Feb 7, 2023
1 parent 3c58c48 commit cf47646
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 69 deletions.
13 changes: 13 additions & 0 deletions tests/e2e/cucumber/features/journeys/kindergarten.oc10.feature
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ Feature: Kindergarten can use web to organize a day
| Pre-Schools Pirates | groups | folder |
| Teddy Bear Daycare | groups | folder |
| groups | | folder |
And "Alice" deletes the following resources using the batch action
| resource | from |
| lorem.txt | groups/Kindergarten Koalas/meal plan |
| lorem-big.txt | groups/Kindergarten Koalas/meal plan |
| data.zip | groups/Pre-Schools Pirates/meal plan |
| lorem.txt | groups/Pre-Schools Pirates/meal plan |
| lorem-big.txt | groups/Pre-Schools Pirates/meal plan |
| data.zip | groups/Teddy Bear Daycare/meal plan |
| lorem.txt | groups/Teddy Bear Daycare/meal plan |
| lorem-big.txt | groups/Teddy Bear Daycare/meal plan |
| Kindergarten Koalas | groups |
| Pre-Schools Pirates | groups |
| Teddy Bear Daycare | groups |
# Then what do we check for to be confident that the above things done by Alice have worked?
# Then the downloaded files should have content "abc..."
And "Alice" logs out
13 changes: 13 additions & 0 deletions tests/e2e/cucumber/features/journeys/kindergarten.ocis.feature
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ Feature: Kindergarten can use web to organize a day
| Pre-Schools Pirates | groups | folder |
| Teddy Bear Daycare | groups | folder |
| groups | | folder |
And "Alice" deletes the following resources using the batch action
| resource | from |
| lorem.txt | groups/Kindergarten Koalas/meal plan |
| lorem-big.txt | groups/Kindergarten Koalas/meal plan |
| data.zip | groups/Pre-Schools Pirates/meal plan |
| lorem.txt | groups/Pre-Schools Pirates/meal plan |
| lorem-big.txt | groups/Pre-Schools Pirates/meal plan |
| data.zip | groups/Teddy Bear Daycare/meal plan |
| lorem.txt | groups/Teddy Bear Daycare/meal plan |
| lorem-big.txt | groups/Teddy Bear Daycare/meal plan |
| Kindergarten Koalas | groups |
| Pre-Schools Pirates | groups |
| Teddy Bear Daycare | groups |
# Then what do we check for to be confident that the above things done by Alice have worked?
# Then the downloaded files should have content "abc..."
And "Alice" logs out
14 changes: 7 additions & 7 deletions tests/e2e/cucumber/features/smoke/share.oc10.feature
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ Feature: share
And "Brian" copies the following resource using dropdown-menu
| resource | to |
| Shares/folder_to_shared | Personal |
When "Brian" deletes the following resources
| resource |
| Shares/folder_to_customShared/lorem-big.txt |
When "Brian" deletes the following resources using the sidebar panel
| resource | from |
| lorem-big.txt | Shares/folder_to_customShared |
When "Alice" opens the "files" app
#Then "Alice" should see the following resources
# | folder_to_shared/lorem_new.txt |
Expand All @@ -62,10 +62,10 @@ Feature: share
| resource | to | version |
| simple.pdf | Shares/folder_to_shared | 1 |
#Then "Brian" should see that the version of resource "simple.pdf" has been restored
When "Alice" deletes the following resources
| resource |
| folder_to_shared/lorem_new.txt |
| folder_to_shared |
When "Alice" deletes the following resources using the sidebar panel
| resource | from |
| lorem_new.txt | folder_to_shared |
| folder_to_shared | |
And "Alice" logs out
#And "Brian" opens the "files" app
#Then "Brian" should not see the following resource
Expand Down
14 changes: 7 additions & 7 deletions tests/e2e/cucumber/features/smoke/share.ocis.feature
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ Feature: share
| resource | to |
| simple.pdf | folder_to_shared |
| testavatar.jpeg | folder_to_customShared |
And "Brian" deletes the following resources
| resource |
| folder_to_customShared/lorem-big.txt |
When "Brian" deletes the following resources using the sidebar panel
| resource | from |
| lorem-big.txt | folder_to_customShared |
And "Alice" opens the "files" app
And "Alice" uploads the following resource
| resource | to | option |
Expand All @@ -64,10 +64,10 @@ Feature: share
And "Alice" removes following sharee
| resource | recipient |
| folder_to_customShared | Brian |
And "Alice" deletes the following resources
| resource |
| folder_to_shared/lorem_new.txt |
| folder_to_shared |
When "Alice" deletes the following resources using the sidebar panel
| resource | from |
| lorem_new.txt | folder_to_shared |
| folder_to_shared | |
And "Alice" logs out
Then "Brian" should not be able to see the following shares
| resource | owner |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ 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 "Brian" deletes the following resources
| resource |
| parent/textfile.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 |
And "Anonymous" logs out
When "Carol" navigates to the trashbin of the project space "team.1"
Then "Carol" should not be able to delete following resources from the trashbin
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/cucumber/features/smoke/spaces/project.ocis.feature
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ Feature: spaces.personal
When "Brian" restores following resources
| resource | to | version |
| simple.pdf | folder_to_shared | 1 |
When "Alice" deletes the following resources
| resource |
| folder_to_shared/lorem_new.txt |
| folder_to_shared |
When "Alice" deletes the following resources using the sidebar panel
| resource | from |
| lorem_new.txt | folder_to_shared |
| folder_to_shared | |
And "Brian" logs out

# alice is done
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)
}
)
52 changes: 40 additions & 12 deletions tests/e2e/cucumber/steps/ui/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ When(
}
)

When(
/^"([^"]*)" deletes the following resource(s)? using the (sidebar panel|batch action)$/,
async function (
this: World,
stepUser: string,
_: string,
actionType: string,
stepTable: DataTable
) {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const resourceObject = new objects.applicationFiles.Resource({ page })
await processDelete(stepTable, resourceObject, actionType)
}
)

When(
'{string} renames the following resource(s)',
async function (this: World, stepUser: string, stepTable: DataTable) {
Expand Down Expand Up @@ -107,18 +122,6 @@ When(
}
)

When(
'{string} deletes the following resource(s)',
async function (this: World, stepUser: string, stepTable: DataTable) {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const resourceObject = new objects.applicationFiles.Resource({ page })

for (const info of stepTable.hashes()) {
await resourceObject.delete({ resource: info.resource })
}
}
)

When(
'{string} downloads old version of the following resource(s)',
async function (this: World, stepUser: string, stepTable: DataTable): Promise<void> {
Expand Down Expand Up @@ -258,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,
resourcesWithInfo: files,
via: actionType === 'batch action' ? 'BATCH_ACTION' : 'SIDEBAR_PANEL'
})
}
}

export const processDownload = async (
stepTable: DataTable,
pageObject: any,
Expand Down
88 changes: 64 additions & 24 deletions tests/e2e/support/objects/app-files/resource/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { resourceExists, waitForResources } from './utils'
import path from 'path'
import { File } from '../../../types'
import { sidebar } from '../utils'
import { config } from '../../../../config'

const downloadFileButtonSideBar =
'#oc-files-actions-sidebar .oc-files-actions-download-file-trigger'
const downloadFolderButtonSidedBar =
'#oc-files-actions-sidebar .oc-files-actions-download-archive-trigger'
const downloadButtonBatchAction = '.oc-files-actions-download-archive-trigger'
const deleteButtonBatchAction = '.oc-files-actions-delete-trigger'
const checkBox = `//*[@data-test-resource-name="%s"]//ancestor::tr//input`
const checkBoxForTrashbin = `//*[@data-test-resource-path="%s"]//ancestor::tr//input`
export const fileRow = '//ancestor::tr'
Expand Down Expand Up @@ -479,35 +481,68 @@ export const restoreResourceVersion = async (args: restoreResourceVersionArgs) =
}

/**/

export interface deleteResourceArgs {
page: Page
resource: string
resourcesWithInfo: resourceArgs[]
folder?: string
via: 'SIDEBAR_PANEL' | 'BATCH_ACTION'
}

export const deleteResource = async (args: deleteResourceArgs): Promise<void> => {
const { page, resource } = args
const folderPaths = resource.split('/')
const resourceName = folderPaths.pop()

if (folderPaths.length) {
await clickResource({ page, path: folderPaths.join('/') })
}
const { page, resourcesWithInfo, folder, via } = args
switch (via) {
case 'SIDEBAR_PANEL': {
if (folder) {
await clickResource({ page, path: folder })
}
for (const resource of resourcesWithInfo) {
await sidebar.open({ page, resource: resource.name })
await sidebar.openPanel({ page, name: 'actions' })
await page.locator(deleteButtonSidebar).first().click()
await Promise.all([
page.waitForResponse(
(resp) =>
resp.url().includes(encodeURIComponent(resource.name)) &&
resp.status() === 204 &&
resp.request().method() === 'DELETE'
),
page.locator(util.format(actionConfirmationButton, 'Delete')).click()
])
await sidebar.close({ page })
}
break
}

await sidebar.open({ page, resource: resourceName })
await sidebar.openPanel({ page, name: 'actions' })
case 'BATCH_ACTION': {
await selectOrDeselectResources({ page, resources: resourcesWithInfo, folder, select: true })
const deletetedResources = []
if (resourcesWithInfo.length <= 1) {
throw new Error('Single resource or objects cannot be deleted with batch action')
}

await page.locator(deleteButtonSidebar).first().click()
await Promise.all([
page.waitForResponse(
(resp) =>
resp.url().includes(encodeURIComponent(resourceName)) &&
resp.status() === 204 &&
resp.request().method() === 'DELETE'
),
page.locator(util.format(actionConfirmationButton, 'Delete')).click()
])
await sidebar.close({ page })
await page.locator(deleteButtonBatchAction).click()
await Promise.all([
page.waitForResponse((resp) => {
if (resp.status() === 204 && resp.request().method() === 'DELETE') {
deletetedResources.push(decodeURIComponent(resp.url().split('/').pop()))
}
// waiting for GET response after all the resource are deleted with batch action
return (
resp.url().includes(config.ocis ? 'graph/v1.0/drives' : 'ocs/v1.php/cloud/users') &&
resp.status() === 200 &&
resp.request().method() === 'GET'
)
}),
page.locator(util.format(actionConfirmationButton, 'Delete')).click()
])
// assertion that the resources actually got deleted
expect(resourcesWithInfo.length).toBe(deletetedResources.length)
for (const resource of resourcesWithInfo) {
expect(deletetedResources).toContain(resource.name)
}
break
}
}
}

export interface downloadResourceVersionArgs {
Expand Down Expand Up @@ -551,7 +586,12 @@ export const emptyTrashBinResources = async (page): Promise<string> => {
return message.trim().toLowerCase()
}

export const deleteResourceTrashbin = async (args: deleteResourceArgs): Promise<string> => {
export interface deleteResourceTrashbinArgs {
page: Page
resource: string
}

export const deleteResourceTrashbin = async (args: deleteResourceTrashbinArgs): Promise<string> => {
const { page, resource } = args
const resourceCheckbox = page.locator(
util.format(checkBoxForTrashbin, `/${resource.replace(/^\/+/, '')}`)
Expand All @@ -573,7 +613,7 @@ export const deleteResourceTrashbin = async (args: deleteResourceArgs): Promise<
}

export const getDeleteResourceButtonVisibility = async (
args: deleteResourceArgs
args: deleteResourceTrashbinArgs
): Promise<boolean> => {
const { page, resource } = args
const resourceCheckbox = page.locator(
Expand Down
9 changes: 6 additions & 3 deletions tests/e2e/support/objects/app-files/resource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import {
openFileInViewer,
openFileInViewerArgs,
getDeleteResourceButtonVisibility,
getRestoreResourceButtonVisibility
getRestoreResourceButtonVisibility,
deleteResourceTrashbinArgs
} from './actions'

export class Resource {
Expand Down Expand Up @@ -121,14 +122,16 @@ export class Resource {
return await emptyTrashBinResources(this.#page)
}

async deleteTrashBin(args: Omit<deleteResourceArgs, 'page'>): Promise<string> {
async deleteTrashBin(args: Omit<deleteResourceTrashbinArgs, 'page'>): Promise<string> {
const startUrl = this.#page.url()
const message = await deleteResourceTrashbin({ ...args, page: this.#page })
await this.#page.goto(startUrl)
return message
}

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

Expand Down

0 comments on commit cf47646

Please sign in to comment.