-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
test(cypress): split helpers for files actions to make tests less flaky #54237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,65 +15,63 @@ 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' }) | ||
|
|
||
| const searchForActionInRow = (row: JQuery<HTMLElement>, actionId: string): Cypress.Chainable<JQuery<HTMLElement>> => { | ||
| 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') | ||
| if (menuButtonId === undefined) { | ||
| return cy.wrap(Cypress.$()) | ||
| } | ||
| export const getActionEntryForFileId = (fileid: number, actionId: string) => { | ||
| return getActionButtonForFileId(fileid) | ||
| .should('have.attr', 'aria-controls') | ||
| .then((menuId) => cy.get(`#${menuId}`).find(`[data-cy-files-list-row-action="${CSS.escape(actionId)}"]`)) | ||
| } | ||
|
|
||
| // eslint-disable-next-line no-unused-expressions | ||
| expect(menuButtonId).not.to.be.undefined | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ This would just fail and not be retried, so if the menu is not yet loaded (opened) and DOM was updated then this will fail forever in this test run. |
||
| return cy.get(`#${menuButtonId} [data-cy-files-list-row-action="${CSS.escape(actionId)}"]`) | ||
| export const getActionEntryForFile = (file: string, actionId: string) => { | ||
| return getActionButtonForFile(file) | ||
| .should('have.attr', 'aria-controls') | ||
| .then((menuId) => cy.get(`#${menuId}`).find(`[data-cy-files-list-row-action="${CSS.escape(actionId)}"]`)) | ||
| } | ||
|
|
||
| export const getActionEntryForFileId = (fileid: number, actionId: string): Cypress.Chainable<JQuery<HTMLElement>> => { | ||
| // 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 getInlineActionEntryForFileId = (fileid: number, actionId: string) => { | ||
| return getActionsForFileId(fileid) | ||
| .find(`[data-cy-files-list-row-action="${CSS.escape(actionId)}"]`) | ||
| } | ||
| export const getActionEntryForFile = (filename: string, actionId: string): Cypress.Chainable<JQuery<HTMLElement>> => { | ||
| // 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 getInlineActionEntryForFile = (file: string, actionId: string) => { | ||
| return getActionsForFile(file) | ||
| .find(`[data-cy-files-list-row-action="${CSS.escape(actionId)}"]`) | ||
| } | ||
|
|
||
| export const triggerActionForFileId = (fileid: number, actionId: string) => { | ||
| // Even if it's inline, we open the action menu to get all actions visible | ||
| getActionButtonForFileId(fileid).click({ force: true }) | ||
| // wait for the actions menu to be visible | ||
| cy.findByRole('menu').findAllByRole('menuitem').first().should('be.visible') | ||
| getActionEntryForFileId(fileid, actionId) | ||
| .find('button').last().as('actionButton') | ||
| getActionButtonForFileId(fileid) | ||
| .as('actionButton') | ||
| .scrollIntoView() | ||
| cy.get('@actionButton') | ||
| .click({ force: true }) // force to avoid issues with overlaying file list header | ||
| getActionEntryForFileId(fileid, actionId) | ||
| .find('button') | ||
| .should('be.visible') | ||
| .click({ force: true }) | ||
| .click() | ||
| } | ||
|
|
||
| export const triggerActionForFile = (filename: string, actionId: string) => { | ||
| // Even if it's inline, we open the action menu to get all actions visible | ||
| getActionButtonForFile(filename).click({ force: true }) | ||
| // wait for the actions menu to be visible | ||
| cy.findByRole('menu').findAllByRole('menuitem').first().should('be.visible') | ||
| getActionEntryForFile(filename, actionId) | ||
| .find('button').last().as('actionButton') | ||
| getActionButtonForFile(filename) | ||
| .as('actionButton') | ||
| .scrollIntoView() | ||
| cy.get('@actionButton') | ||
| .click({ force: true }) // force to avoid issues with overlaying file list header | ||
| getActionEntryForFile(filename, actionId) | ||
| .find('button') | ||
| .should('be.visible') | ||
| .click({ force: true }) | ||
| .click() | ||
| } | ||
|
|
||
| export const triggerInlineActionForFileId = (fileid: number, actionId: string) => { | ||
| getActionsForFileId(fileid).find(`button[data-cy-files-list-row-action="${CSS.escape(actionId)}"]`).should('exist').click() | ||
| getActionsForFileId(fileid) | ||
| .find(`button[data-cy-files-list-row-action="${CSS.escape(actionId)}"]`) | ||
| .should('exist') | ||
| .click() | ||
| } | ||
| export const triggerInlineActionForFile = (filename: string, actionId: string) => { | ||
| getActionsForFile(filename).find(`button[data-cy-files-list-row-action="${CSS.escape(actionId)}"]`).should('exist').click() | ||
| getActionsForFile(filename) | ||
| .find(`button[data-cy-files-list-row-action="${CSS.escape(actionId)}"]`) | ||
| .should('exist') | ||
| .click() | ||
| } | ||
|
|
||
| export const selectAllFiles = () => { | ||
|
|
@@ -176,12 +174,17 @@ export const copyFile = (fileName: string, dirPath: string) => { | |
|
|
||
| export const renameFile = (fileName: string, newFileName: string) => { | ||
| getRowForFile(fileName) | ||
| .should('exist') | ||
| .scrollIntoView() | ||
|
|
||
| triggerActionForFile(fileName, 'rename') | ||
|
|
||
| // intercept the move so we can wait for it | ||
| cy.intercept('MOVE', /\/(remote|public)\.php\/dav\/files\//).as('moveFile') | ||
|
|
||
| getRowForFile(fileName).find('[data-cy-files-list-row-name] input').type(`{selectAll}${newFileName}{enter}`) | ||
| getRowForFile(fileName) | ||
| .find('[data-cy-files-list-row-name] input') | ||
| .type(`{selectAll}${newFileName}{enter}`) | ||
|
|
||
| cy.wait('@moveFile') | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ whereas here we assure a aria-controls is already available (because we do not need to check inline actions) and thus can assume in the
thenthat the previous was retried until available.