From 8567f2d95b00af558ce1b2e0b7835e96cbf31568 Mon Sep 17 00:00:00 2001 From: skjnldsv Date: Thu, 20 Feb 2025 20:39:18 +0100 Subject: [PATCH] fix(cypress): action selector menu lookup Signed-off-by: skjnldsv [skip ci] --- cypress/e2e/files/FilesUtils.ts | 24 ++++++++++++++++++++---- cypress/e2e/files/files-actions.cy.ts | 4 +++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/cypress/e2e/files/FilesUtils.ts b/cypress/e2e/files/FilesUtils.ts index d1e609713b66b..fce23fc146346 100644 --- a/cypress/e2e/files/FilesUtils.ts +++ b/cypress/e2e/files/FilesUtils.ts @@ -15,11 +15,27 @@ export const getActionsForFile = (filename: string) => getRowForFile(filename).f export const getActionButtonForFileId = (fileid: number) => getActionsForFileId(fileid).findByRole('button', { name: 'Actions' }) export const getActionButtonForFile = (filename: string) => getActionsForFile(filename).findByRole('button', { name: 'Actions' }) -export const getActionEntryForFileId = (fileid: number, actionId: string) => { - return getRowForFileId(fileid).find(`[data-cy-files-list-row-action="${CSS.escape(actionId)}"]`) +const searchForActionInRow = (row: JQuery, actionId: string): Cypress.Chainable> => { + const action = row.find(`[data-cy-files-list-row-action="${CSS.escape(actionId)}"]`) + if (action.length > 0) { + cy.log('Found action in row') + return cy.wrap(action) + } + + // Else look in the action menu + const menuButtonId = row.find('button[aria-controls]').attr('aria-controls') + return cy.get(`#${menuButtonId} [data-cy-files-list-row-action="${CSS.escape(actionId)}"]`) +} + +export const getActionEntryForFileId = (fileid: number, actionId: string): Cypress.Chainable> => { + // If we cannot find the action in the row, it might be in the action menu + return getRowForFileId(fileid).should('be.visible') + .then(row => searchForActionInRow(row, actionId)) } -export const getActionEntryForFile = (filename: string, actionId: string) => { - return getRowForFile(filename).find(`[data-cy-files-list-row-action="${CSS.escape(actionId)}"]`) +export const getActionEntryForFile = (filename: string, actionId: string): Cypress.Chainable> => { + // If we cannot find the action in the row, it might be in the action menu + return getRowForFile(filename).should('be.visible') + .then(row => searchForActionInRow(row, actionId)) } export const triggerActionForFileId = (fileid: number, actionId: string) => { diff --git a/cypress/e2e/files/files-actions.cy.ts b/cypress/e2e/files/files-actions.cy.ts index 8b0057e30425c..597b1b9046442 100644 --- a/cypress/e2e/files/files-actions.cy.ts +++ b/cypress/e2e/files/files-actions.cy.ts @@ -6,7 +6,7 @@ import type { User } from '@nextcloud/cypress' import { FileAction } from '@nextcloud/files' -import { getActionButtonForFileId, getActionEntryForFileId, getRowForFile, getSelectionActionButton, getSelectionActionEntry, selectRowForFile, triggerActionForFile, triggerActionForFileId } from './FilesUtils' +import { getActionButtonForFileId, getActionEntryForFileId, getRowForFile, getSelectionActionButton, getSelectionActionEntry, selectRowForFile } from './FilesUtils' import { ACTION_COPY_MOVE } from '../../../apps/files/src/actions/moveOrCopyAction' import { ACTION_DELETE } from '../../../apps/files/src/actions/deleteAction' import { ACTION_DETAILS } from '../../../apps/files/src/actions/sidebarAction' @@ -53,6 +53,8 @@ describe('Files: Actions', { testIsolation: true }, () => { getActionButtonForFileId(fileId).click({ force: true }) // Check the action is visible getActionEntryForFileId(fileId, actionId).should('be.visible') + // Close the menu + cy.get('body').click({ force: true}) }) })