Skip to content

Commit

Permalink
add test for copy and move multiple files at once (#9914)
Browse files Browse the repository at this point in the history
  • Loading branch information
PrajwolAmatya authored Nov 8, 2023
1 parent 6ed2c7c commit 65cbcdd
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 0 deletions.
93 changes: 93 additions & 0 deletions tests/e2e/cucumber/features/smoke/copyMove.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,24 @@ Feature: Copy
| PARENTMove |
| PARENTCopy3 |
| PARENTCopy4/Sub1/Sub2 |
| PARENT |
| PARENT/Sub1/Sub |
| PARENT/Sub2 |
| PARENT/Sub3 |
| PARENT/Sub4 |
| PARENT/Sub5 |
And "Alice" creates the following files into personal space using API
| pathToFile | content |
| PARENTCopy3/example1.txt | example text |
| PARENTCopy3/example2.txt | example text |
| KeyboardExample.txt | copy with the help of keyboard |
| dragDrop.txt | copy with the help of drag-drop |
| sidebar.txt | copy with the help of sidebar panel |
| PARENT/fileToCopy1.txt | some content |
| PARENT/fileToCopy2.txt | some content |
| PARENT/fileToCopy3.txt | some content |
| PARENT/fileToCopy4.txt | some content |
| PARENT/fileToCopy5.txt | some content |
And "Alice" opens the "files" app

When "Alice" copies the following resource using sidebar-panel
Expand Down Expand Up @@ -56,4 +67,86 @@ Feature: Copy
And "Alice" moves the following resource using drag-drop-breadcrumb
| resource | to |
| Sub2 | PARENTCopy4 |

And "Alice" opens the "files" app
And "Alice" opens folder "PARENT"
And "Alice" copies the following resources to "PARENT/Sub1" at once using dropdown-menu
| resource |
| fileToCopy1.txt |
| fileToCopy2.txt |
| fileToCopy3.txt |
| fileToCopy4.txt |
| fileToCopy5.txt |
| Sub4 |
| Sub5 |
And "Alice" copies the following resources to "PARENT/Sub2" at once using batch-action
| resource |
| fileToCopy1.txt |
| fileToCopy2.txt |
| fileToCopy3.txt |
| fileToCopy4.txt |
| fileToCopy5.txt |
| Sub4 |
| Sub5 |
And "Alice" copies the following resources to "PARENT/Sub3" at once using keyboard
| resource |
| fileToCopy1.txt |
| fileToCopy2.txt |
| fileToCopy3.txt |
| fileToCopy4.txt |
| fileToCopy5.txt |
| Sub4 |
| Sub5 |
And "Alice" opens folder "Sub1"
And "Alice" moves the following resources to "PARENT/Sub1/Sub" at once using dropdown-menu
| resource |
| fileToCopy1.txt |
| fileToCopy2.txt |
| fileToCopy3.txt |
| fileToCopy4.txt |
| fileToCopy5.txt |
| Sub4 |
| Sub5 |
And "Alice" opens folder "Sub"
And "Alice" moves the following resources to "PARENT/Sub1" at once using batch-action
| resource |
| fileToCopy1.txt |
| fileToCopy2.txt |
| fileToCopy3.txt |
| fileToCopy4.txt |
| fileToCopy5.txt |
| Sub4 |
| Sub5 |
And "Alice" opens the "files" app
And "Alice" opens folder "PARENT"
And "Alice" moves the following resources to "Sub4" at once using drag-drop
| resource |
| fileToCopy1.txt |
| fileToCopy2.txt |
| fileToCopy3.txt |
| fileToCopy4.txt |
| fileToCopy5.txt |
| Sub1 |
| Sub2 |
And "Alice" opens folder "Sub4"
And "Alice" moves the following resources to "PARENT" at once using drag-drop-breadcrumb
| resource |
| fileToCopy1.txt |
| fileToCopy2.txt |
| fileToCopy3.txt |
| fileToCopy4.txt |
| fileToCopy5.txt |
| Sub1 |
| Sub2 |
And "Alice" opens the "files" app
And "Alice" opens folder "PARENT"
And "Alice" moves the following resources to "PARENT/Sub4" at once using keyboard
| resource |
| fileToCopy1.txt |
| fileToCopy2.txt |
| fileToCopy3.txt |
| fileToCopy4.txt |
| fileToCopy5.txt |
| Sub1 |
| Sub2 |
And "Alice" logs out
24 changes: 24 additions & 0 deletions tests/e2e/cucumber/steps/ui/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,30 @@ When(
}
)

When(
/^"([^"]*)" (copies|moves) the following resources to "([^"]*)" at once using (keyboard|drag-drop|drag-drop-breadcrumb|dropdown-menu|batch-action)$/,
async function (
this: World,
stepUser: string,
actionType: string,
newLocation: string,
method: string,
stepTable: DataTable
): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const resourceObject = new objects.applicationFiles.Resource({ page })

const resources = [].concat(...stepTable.rows())
await resourceObject[
actionType === 'copies' ? 'copyMultipleResources' : 'moveMultipleResources'
]({
newLocation,
method,
resources
})
}
)

When(
'{string} restores following resource(s)',
async function (this: World, stepUser: string, stepTable: DataTable): Promise<void> {
Expand Down
96 changes: 96 additions & 0 deletions tests/e2e/support/objects/app-files/resource/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const onlyOfficeCanvasCursorSelector = '#id_target_cursor'
const collaboraCanvasEditorSelector = '.leaflet-layer'
const textEditorTextArea = '#text-editor-input'
const filesContextMenuAction = 'div[id^="context-menu-drop"] button.oc-files-actions-%s-trigger'
const highlightedFileRowSelector = '#files-space-table tr.oc-table-highlighted'

export const clickResource = async ({
page,
Expand Down Expand Up @@ -646,6 +647,10 @@ export interface moveOrCopyResourceArgs {
method: string
}

export interface moveOrCopyMultipleResourceArgs extends Omit<moveOrCopyResourceArgs, 'resource'> {
resources: string[]
}

export const pasteResource = async (
args: Omit<moveOrCopyResourceArgs, 'action'>
): Promise<void> => {
Expand Down Expand Up @@ -673,6 +678,97 @@ export const pasteResource = async (
})
}

export const moveOrCopyMultipleResources = async (
args: moveOrCopyMultipleResourceArgs
): Promise<void> => {
const { page, newLocation, action, method, resources } = args

for (const resource of resources) {
await page.locator(util.format(checkBox, resource)).click()
}

const waitForMoveResponses = []
if (['drag-drop-breadcrumb', 'drag-drop'].includes(method)) {
for (const resource of resources) {
waitForMoveResponses.push(
page.waitForResponse(
(resp) =>
resp.url().endsWith(resource) &&
resp.status() === 201 &&
resp.request().method() === 'MOVE'
)
)
}
}

switch (method) {
case 'dropdown-menu': {
// after selecting multiple resources, resources can be copied or moved by clicking on any of the selected resources
await page.locator(highlightedFileRowSelector).first().click({ button: 'right' })
await page.locator(util.format(filesContextMenuAction, action)).click()

await page.locator(breadcrumbRoot).click()
const newLocationPath = newLocation.split('/')
for (const path of newLocationPath) {
if (path !== 'Personal') {
await clickResource({ page, path: path })
}
}
await page.locator(filesView).click({ button: 'right' })
await page.locator(util.format(filesContextMenuAction, 'copy')).click()
break
}
case 'batch-action': {
await page.locator(util.format(filesBatchAction, action)).click()

await page.locator(breadcrumbRoot).click()
const newLocationPath = newLocation.split('/')
for (const path of newLocationPath) {
if (path !== 'Personal') {
await clickResource({ page, path: path })
}
}
await page.locator(pasteButton).click()
break
}
case 'keyboard': {
const keyValue = action === 'copy' ? 'c' : 'x'
await page.keyboard.press(`Control+${keyValue}`)
await page.locator(breadcrumbRoot).click()
const newLocationPath = newLocation.split('/')
for (const path of newLocationPath) {
if (path !== 'Personal') {
await clickResource({ page, path: path })
}
}
await page.keyboard.press('Control+v')
break
}
case 'drag-drop': {
const source = page.locator(highlightedFileRowSelector).first()
const target = page.locator(util.format(resourceNameSelector, newLocation))

await Promise.all([...waitForMoveResponses, source.dragTo(target)])

await target.click()
break
}
case 'drag-drop-breadcrumb': {
const source = page.locator(highlightedFileRowSelector).first()
const target = page.locator(util.format(breadcrumbResourceNameSelector, newLocation))

await Promise.all([...waitForMoveResponses, source.dragTo(target)])

await target.click()
break
}
}
await waitForResources({
page,
names: resources
})
}

export const moveOrCopyResource = async (args: moveOrCopyResourceArgs): Promise<void> => {
const { page, resource, newLocation, action, method } = args
const { dir: resourceDir, base: resourceBase } = path.parse(resource)
Expand Down
12 changes: 12 additions & 0 deletions tests/e2e/support/objects/app-files/resource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ export class Resource {
await this.#page.goto(startUrl)
}

async copyMultipleResources(args: Omit<po.moveOrCopyMultipleResourceArgs, 'page' | 'action'>) {
const startUrl = this.#page.url()
await po.moveOrCopyMultipleResources({ ...args, page: this.#page, action: 'copy' })
await this.#page.goto(startUrl)
}

async moveMultipleResources(args: Omit<po.moveOrCopyMultipleResourceArgs, 'page' | 'action'>) {
const startUrl = this.#page.url()
await po.moveOrCopyMultipleResources({ ...args, page: this.#page, action: 'move' })
await this.#page.goto(startUrl)
}

async delete(args: Omit<po.deleteResourceArgs, 'page'>): Promise<void> {
const startUrl = this.#page.url()
await po.deleteResource({ ...args, page: this.#page })
Expand Down

0 comments on commit 65cbcdd

Please sign in to comment.