Skip to content

Commit 0c54d51

Browse files
test(cypress): improve resilience of files-copy-move sharing tests
- Remove `.within()` scoping to avoid stale DOM references on re-render - Remove unused `cy.intercept()` calls (aliases were never awaited) - Add explicit visibility gates before file picker interactions - Re-query `.file-picker` per command chain for DOM freshness - Add `CSS.escape()` to `moveFileForbidden` directory selector (bug fix) - Increase assertion timeouts for slow CI environments - Replace `cy.contains().should('not.exist')` anti-pattern with `cy.get().should('not.contain')` for correct negative assertion Signed-off-by: Josh <josh.t.richards@gmail.com>
1 parent 753e6ee commit 0c54d51

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

cypress/e2e/files_sharing/files-copy-move.cy.ts

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,44 +19,52 @@ export function copyFileForbidden(fileName: string, dirPath: string) {
1919
getRowForFile(fileName).should('be.visible')
2020
triggerActionForFile(fileName, ACTION_COPY_MOVE)
2121

22-
cy.get('.file-picker').within(() => {
23-
// intercept the copy so we can wait for it
24-
cy.intercept('COPY', /\/(remote|public)\.php\/dav\/files\//).as('copyFile')
25-
26-
const directories = dirPath.split('/')
27-
directories.forEach((directory) => {
28-
// select the folder
29-
cy.get(`[data-filename="${CSS.escape(directory)}"]`).should('be.visible').click()
30-
})
22+
cy.get('.file-picker').should('be.visible')
3123

32-
// check copy button
33-
cy.contains('button', `Copy to ${directories.at(-1)}`).should('be.disabled')
24+
const directories = dirPath.split('/')
25+
directories.forEach((directory) => {
26+
cy.get('.file-picker')
27+
.find(`[data-filename="${CSS.escape(directory)}"]`)
28+
.should('be.visible')
29+
.click()
3430
})
31+
32+
// Re-query after possible re-render and assert eventual disabled state
33+
cy.get('.file-picker')
34+
.contains('button', `Copy to ${directories.at(-1)}`, { timeout: 10000 })
35+
.should('be.visible')
36+
.and('be.disabled')
3537
}
3638

3739
export function moveFileForbidden(fileName: string, dirPath: string) {
3840
getRowForFile(fileName).should('be.visible')
3941
triggerActionForFile(fileName, ACTION_COPY_MOVE)
4042

41-
cy.get('.file-picker').within(() => {
42-
// intercept the copy so we can wait for it
43-
cy.intercept('MOVE', /\/(remote|public)\.php\/dav\/files\//).as('moveFile')
43+
cy.get('.file-picker').should('be.visible')
4444

45-
// select home folder
46-
cy.get('.breadcrumb')
47-
.findByRole('button', { name: 'All files' })
48-
.should('be.visible')
49-
.click()
45+
// Avoid stale chained subject when breadcrumb re-renders
46+
cy.get('.file-picker .breadcrumb')
47+
.findByRole('button', { name: 'All files' })
48+
.should('be.visible')
49+
.click()
5050

51-
const directories = dirPath.split('/')
52-
directories.forEach((directory) => {
53-
// select the folder
54-
cy.get(`[data-filename="${directory}"]`).should('be.visible').click()
55-
})
51+
// Re-acquire file picker after navigation click
52+
cy.get('.file-picker').should('be.visible')
5653

57-
// click move
58-
cy.contains('button', `Move to ${directories.at(-1)}`).should('not.exist')
54+
const directories = dirPath.split('/')
55+
directories.forEach((directory) => {
56+
cy.get('.file-picker')
57+
.find(`[data-filename="${CSS.escape(directory)}"]`)
58+
.should('be.visible')
59+
.click()
5960
})
61+
62+
// If move is forbidden, the move button should not be present.
63+
// Use should('not.contain') on the parent to avoid the cy.contains() + should('not.exist')
64+
// anti-pattern, where cy.contains() must first find the element before the negation can pass,
65+
// causing unnecessary waits or false failures.
66+
cy.get('.file-picker', { timeout: 10000 })
67+
.should('not.contain', `Move to ${directories.at(-1)}`)
6068
}
6169

6270
describe('files_sharing: Move or copy files', { testIsolation: true }, () => {

0 commit comments

Comments
 (0)