nextcloud/tests/playwright/support/sections/FilesListPage.ts
Ferdinand Thiessen a21c2fddd6
test(files): migrate more tests from Cypress to Playwright
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
2026-06-10 09:49:04 +02:00

78 lines
2.6 KiB
TypeScript

/*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { Locator, Page } from '@playwright/test'
export class FilesListPage {
constructor(private readonly page: Page) {}
async open(): Promise<void> {
await this.page.goto('apps/files')
await this.page.locator('[data-cy-files-list]').waitFor({ state: 'visible' })
}
getRowForFile(filename: string): Locator {
return this.page.locator(`[data-cy-files-list-row-name="${filename}"]`)
}
getRowForFileId(fileid: number): Locator {
return this.page.locator(`[data-cy-files-list-row-fileid="${fileid}"]`)
}
private getActionsButtonForFile(filename: string): Locator {
return this.getRowForFile(filename)
.getByRole('button', { name: 'Actions' })
}
async triggerActionForFile(filename: string, actionId: string): Promise<void> {
const row = this.getRowForFile(filename)
await row.hover()
const actionsButton = this.getActionsButtonForFile(filename)
await actionsButton.scrollIntoViewIfNeeded()
// force: true to avoid issues with the sticky file list header
await actionsButton.click({ force: true })
const menuId = await actionsButton.getAttribute('aria-controls')
// The action button has role="menuitem", so use tag selector not getByRole
const actionEntry = this.page
.locator(`#${menuId} [data-cy-files-list-row-action="${actionId}"] button`)
await actionEntry.waitFor({ state: 'visible' })
await actionEntry.click()
}
async selectAll(): Promise<void> {
await this.page.locator('[data-cy-files-list-selection-checkbox]')
.getByRole('checkbox')
.click({ force: true })
}
async triggerSelectionAction(actionId: string): Promise<void> {
const actionsButton = this.page.locator('[data-cy-files-list-selection-actions]')
.getByRole('button', { name: 'Actions' })
await actionsButton.click({ force: true })
// NcActionButton renders as <li data-cy-...><button role="menuitem">
const actionButton = this.page.locator(`[data-cy-files-list-selection-action="${actionId}"] button`)
await actionButton.waitFor({ state: 'visible' })
await actionButton.click()
}
getRenameInputForFile(filename: string): Locator {
return this.getRowForFile(filename).getByRole('textbox', { name: 'Filename' })
}
getRenameInputForFolder(foldername: string): Locator {
return this.getRowForFile(foldername).getByRole('textbox', { name: 'Folder name' })
}
async navigateToFolder(dirPath: string): Promise<void> {
for (const directory of dirPath.split('/').filter(Boolean)) {
await this.getRowForFile(directory)
.getByRole('button')
.filter({ hasText: directory })
.click()
}
}
}