Skip to content

Commit ad93216

Browse files
committed
test(files): migrate files actions e2e from Cypress to Playwright
Signed-off-by: Peter Ringelmann <peter.ringelmann@nextcloud.com>
1 parent 87f8d78 commit ad93216

3 files changed

Lines changed: 78 additions & 74 deletions

File tree

cypress/e2e/files/files-actions.cy.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { test, expect } from '../../support/fixtures/files-page.ts'
7+
import { rm, uploadContent } from '../../support/utils/dav.ts'
8+
9+
// A representative subset of the default actions, not the full feature set.
10+
const expectedRowActions = ['move-copy', 'delete', 'details']
11+
const expectedSelectionActions = ['move-copy', 'delete']
12+
13+
test.describe('Files: Actions', () => {
14+
test.beforeEach(async ({ page, user, filesListPage }) => {
15+
// New users get welcome.txt — remove it so the list contains only our test file
16+
await rm(page.request, user, '/welcome.txt')
17+
await uploadContent(page.request, user, Buffer.alloc(0), 'image/jpeg', '/image.jpg')
18+
await filesListPage.open()
19+
})
20+
21+
test('shows the standard row actions', async ({ filesListPage }) => {
22+
await expect(filesListPage.getRowForFile('image.jpg')).toBeVisible()
23+
24+
const menu = await filesListPage.openActionsMenuForFile('image.jpg')
25+
for (const actionId of expectedRowActions) {
26+
await expect(filesListPage.getActionButtonInMenu(menu, actionId)).toBeVisible()
27+
}
28+
})
29+
30+
test('shows the standard actions for a selection', async ({ filesListPage }) => {
31+
await expect(filesListPage.getRowForFile('image.jpg')).toBeVisible()
32+
33+
await filesListPage.selectRowForFile('image.jpg')
34+
await expect(filesListPage.getSelectionActionsToolbar()).toBeVisible()
35+
36+
await filesListPage.openSelectionActionsMenu()
37+
for (const actionId of expectedSelectionActions) {
38+
await expect(filesListPage.getSelectionActionEntry(actionId)).toBeVisible()
39+
}
40+
})
41+
})

tests/playwright/support/sections/FilesListPage.ts

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,45 @@ export class FilesListPage {
6868
.click({ force: true })
6969
}
7070

71+
async selectRowForFile(filename: string): Promise<void> {
72+
// The checkbox is visually hidden inside NcCheckboxRadioSwitch, so force the check
73+
await this.getRowForFile(filename)
74+
.getByRole('checkbox', { name: /Toggle selection/ })
75+
.check({ force: true })
76+
}
77+
78+
/**
79+
* The toolbar that replaces the list header once one or more rows are selected.
80+
*/
81+
getSelectionActionsToolbar(): Locator {
82+
return this.page.locator('[data-cy-files-list-selection-actions]')
83+
}
84+
85+
private getSelectionActionsButton(): Locator {
86+
return this.getSelectionActionsToolbar().getByRole('button', { name: 'Actions' })
87+
}
88+
89+
/**
90+
* Open the bulk-selection actions menu. Pair with {@link getSelectionActionEntry}
91+
* to inspect an entry (e.g. assert it is visible) before acting; for a plain
92+
* "open and click" use {@link triggerSelectionAction}.
93+
*/
94+
async openSelectionActionsMenu(): Promise<void> {
95+
await this.getSelectionActionsButton().click({ force: true })
96+
}
97+
98+
/**
99+
* A selection action entry. Matched at page level on the product-owned
100+
* attribute because selection actions can render inline or inside the menu popover.
101+
*/
102+
getSelectionActionEntry(actionId: string): Locator {
103+
return this.page.locator(`[data-cy-files-list-selection-action="${actionId}"]`)
104+
}
105+
71106
async triggerSelectionAction(actionId: string): Promise<void> {
72-
const actionsButton = this.page.locator('[data-cy-files-list-selection-actions]')
73-
.getByRole('button', { name: 'Actions' })
74-
await actionsButton.click({ force: true })
107+
await this.openSelectionActionsMenu()
75108
// NcActionButton renders as <li data-cy-...><button role="menuitem">
76-
const actionButton = this.page.locator(`[data-cy-files-list-selection-action="${actionId}"] button`)
109+
const actionButton = this.getSelectionActionEntry(actionId).locator('button')
77110
await actionButton.waitFor({ state: 'visible' })
78111
await actionButton.click()
79112
}

0 commit comments

Comments
 (0)