Skip to content

Commit 3dc38fa

Browse files
committed
test(cypress): wait for button to be visible
Instead of just expecting the button in the DOM. This causes flaky tests with files-renaming. Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent f85154f commit 3dc38fa

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

cypress/e2e/files/FilesUtils.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,37 @@ const searchForActionInRow = (row: JQuery<HTMLElement>, actionId: string): Cypre
3636
export const getActionEntryForFileId = (fileid: number, actionId: string): Cypress.Chainable<JQuery<HTMLElement>> => {
3737
// If we cannot find the action in the row, it might be in the action menu
3838
return getRowForFileId(fileid).should('be.visible')
39-
.then(row => searchForActionInRow(row, actionId))
39+
.then((row) => searchForActionInRow(row, actionId))
4040
}
4141
export const getActionEntryForFile = (filename: string, actionId: string): Cypress.Chainable<JQuery<HTMLElement>> => {
4242
// If we cannot find the action in the row, it might be in the action menu
4343
return getRowForFile(filename).should('be.visible')
44-
.then(row => searchForActionInRow(row, actionId))
44+
.then((row) => searchForActionInRow(row, actionId))
4545
}
4646

4747
export const triggerActionForFileId = (fileid: number, actionId: string) => {
4848
// Even if it's inline, we open the action menu to get all actions visible
4949
getActionButtonForFileId(fileid).click({ force: true })
50+
// wait for the actions menu to be visible
51+
cy.findByRole('menu').findAllByRole('menuitem').first().should('be.visible')
5052
getActionEntryForFileId(fileid, actionId)
51-
.find('button').last()
52-
.should('exist').click({ force: true })
53+
.find('button').last().as('actionButton')
54+
.scrollIntoView()
55+
cy.get('@actionButton')
56+
.should('be.visible')
57+
.click({ force: true })
5358
}
5459
export const triggerActionForFile = (filename: string, actionId: string) => {
5560
// Even if it's inline, we open the action menu to get all actions visible
5661
getActionButtonForFile(filename).click({ force: true })
62+
// wait for the actions menu to be visible
63+
cy.findByRole('menu').findAllByRole('menuitem').first().should('be.visible')
5764
getActionEntryForFile(filename, actionId)
58-
.find('button').last()
59-
.should('exist').click({ force: true })
65+
.find('button').last().as('actionButton')
66+
.scrollIntoView()
67+
cy.get('@actionButton')
68+
.should('be.visible')
69+
.click({ force: true })
6070
}
6171

6272
export const triggerInlineActionForFileId = (fileid: number, actionId: string) => {

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ import { calculateViewportHeight, createFolder, getRowForFile, haveValidity, ren
99
describe('files: Rename nodes', { testIsolation: true }, () => {
1010
let user: User
1111

12-
beforeEach(() => cy.createRandomUser().then(($user) => {
13-
user = $user
14-
15-
// remove welcome file
16-
cy.rm(user, '/welcome.txt')
17-
// create a file called "file.txt"
18-
cy.uploadContent(user, new Blob([]), 'text/plain', '/file.txt')
19-
20-
// login and visit files app
21-
cy.login(user)
12+
beforeEach(() => {
13+
cy.createRandomUser().then(($user) => {
14+
user = $user
15+
16+
// remove welcome file
17+
cy.rm(user, '/welcome.txt')
18+
// create a file called "file.txt"
19+
cy.uploadContent(user, new Blob([]), 'text/plain', '/file.txt')
20+
21+
// login and visit files app
22+
cy.login(user)
23+
})
2224
cy.visit('/apps/files')
23-
}))
25+
})
2426

2527
it('can rename a file', () => {
2628
// All are visible by default

0 commit comments

Comments
 (0)