Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 34 additions & 26 deletions cypress/e2e/files_sharing/files-copy-move.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,52 @@ export function copyFileForbidden(fileName: string, dirPath: string) {
getRowForFile(fileName).should('be.visible')
triggerActionForFile(fileName, ACTION_COPY_MOVE)

cy.get('.file-picker').within(() => {
// intercept the copy so we can wait for it
cy.intercept('COPY', /\/(remote|public)\.php\/dav\/files\//).as('copyFile')

const directories = dirPath.split('/')
directories.forEach((directory) => {
// select the folder
cy.get(`[data-filename="${CSS.escape(directory)}"]`).should('be.visible').click()
})
cy.get('.file-picker').should('be.visible')

// check copy button
cy.contains('button', `Copy to ${directories.at(-1)}`).should('be.disabled')
const directories = dirPath.split('/')
directories.forEach((directory) => {
cy.get('.file-picker')
.find(`[data-filename="${CSS.escape(directory)}"]`)
.should('be.visible')
.click()
})

// Re-query after possible re-render and assert eventual disabled state
cy.get('.file-picker')
.contains('button', `Copy to ${directories.at(-1)}`, { timeout: 10000 })
.should('be.visible')
.and('be.disabled')
}

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

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

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

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

// click move
cy.contains('button', `Move to ${directories.at(-1)}`).should('not.exist')
const directories = dirPath.split('/')
directories.forEach((directory) => {
cy.get('.file-picker')
.find(`[data-filename="${CSS.escape(directory)}"]`)
.should('be.visible')
.click()
})

// If move is forbidden, the move button should not be present.
// Use should('not.contain') on the parent to avoid the cy.contains() + should('not.exist')
// anti-pattern, where cy.contains() must first find the element before the negation can pass,
// causing unnecessary waits or false failures.
cy.get('.file-picker', { timeout: 10000 })
.should('not.contain', `Move to ${directories.at(-1)}`)
}

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