Merge pull request #52636 from nextcloud/test/files-download

pull/52378/head
John Molakvoæ 2025-05-07 11:16:17 +07:00 committed by GitHub
commit 0dc971189b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 206 additions and 0 deletions

@ -6,6 +6,9 @@
import type { User } from '@nextcloud/cypress'
import { getRowForFile, navigateToFolder, triggerActionForFile } from './FilesUtils'
import { deleteDownloadsFolderBeforeEach } from 'cypress-delete-downloads-folder'
import { zipFileContains } from '../../support/utils/assertions.ts'
import randomString from 'crypto-random-string'
describe('files: Download files using file actions', { testIsolation: true }, () => {
let user: User
@ -34,6 +37,29 @@ describe('files: Download files using file actions', { testIsolation: true }, ()
.and('equal', '<content>')
})
it('can download folder', () => {
cy.mkdir(user, '/subfolder')
cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/subfolder/file.txt')
cy.login(user)
cy.visit('/apps/files')
getRowForFile('subfolder')
.should('be.visible')
triggerActionForFile('subfolder', 'download')
// check a file is downloaded
const downloadsFolder = Cypress.config('downloadsFolder')
cy.readFile(`${downloadsFolder}/subfolder.zip`, null, { timeout: 15000 })
.should('exist')
.and('have.length.gt', 30)
// Check all files are included
.and(zipFileContains([
'subfolder/',
'subfolder/file.txt',
]))
})
/**
* Regression test of https://github.com/nextcloud/server/issues/44855
*/
@ -143,3 +169,183 @@ describe('files: Download files using default action', { testIsolation: true },
.and('equal', '<content>')
})
})
describe('files: Download files using selection', () => {
deleteDownloadsFolderBeforeEach()
it('can download selected files', () => {
cy.createRandomUser().then((user) => {
cy.mkdir(user, '/subfolder')
cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/subfolder/file.txt')
cy.login(user)
cy.visit('/apps/files')
})
getRowForFile('subfolder')
.should('be.visible')
getRowForFile('subfolder')
.findByRole('checkbox')
.check({ force: true })
// see that two files are selected
cy.get('[data-cy-files-list]').within(() => {
cy.contains('1 selected').should('be.visible')
})
// click download
cy.get('[data-cy-files-list-selection-actions]')
.findByRole('button', { name: 'Actions' })
.click()
cy.findByRole('menuitem', { name: 'Download (selected)' })
.should('be.visible')
.click()
// check a file is downloaded
const downloadsFolder = Cypress.config('downloadsFolder')
cy.readFile(`${downloadsFolder}/subfolder.zip`, null, { timeout: 15000 })
.should('exist')
.and('have.length.gt', 30)
// Check all files are included
.and(zipFileContains([
'subfolder/',
'subfolder/file.txt',
]))
})
it('can download multiple selected files', () => {
cy.createRandomUser().then((user) => {
cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/file.txt')
cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/other file.txt')
cy.login(user)
cy.visit('/apps/files')
})
getRowForFile('file.txt')
.should('be.visible')
.findByRole('checkbox')
.check({ force: true })
getRowForFile('other file.txt')
.should('be.visible')
.findByRole('checkbox')
.check({ force: true })
cy.get('[data-cy-files-list]').within(() => {
// see that two files are selected
cy.contains('2 selected').should('be.visible')
})
// click download
cy.get('[data-cy-files-list-selection-actions]')
.findByRole('button', { name: 'Actions' })
.click()
cy.findByRole('menuitem', { name: 'Download (selected)' })
.click()
// check a file is downloaded
const downloadsFolder = Cypress.config('downloadsFolder')
cy.readFile(`${downloadsFolder}/download.zip`, null, { timeout: 15000 })
.should('exist')
.and('have.length.gt', 30)
// Check all files are included
.and(zipFileContains([
'file.txt',
'other file.txt',
]))
})
/**
* Regression test of https://help.nextcloud.com/t/unable-to-download-files-on-nextcloud-when-multiple-files-selected/221327/5
*/
it('can download selected files with special characters', () => {
cy.createRandomUser().then((user) => {
cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/1+1.txt')
cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/some@other.txt')
cy.login(user)
cy.visit('/apps/files')
})
getRowForFile('some@other.txt')
.should('be.visible')
.findByRole('checkbox')
.check({ force: true })
getRowForFile('1+1.txt')
.should('be.visible')
.findByRole('checkbox')
.check({ force: true })
cy.get('[data-cy-files-list]').within(() => {
// see that two files are selected
cy.contains('2 selected').should('be.visible')
})
// click download
cy.get('[data-cy-files-list-selection-actions]')
.findByRole('button', { name: 'Actions' })
.click()
cy.findByRole('menuitem', { name: 'Download (selected)' })
.click()
// check a file is downloaded
const downloadsFolder = Cypress.config('downloadsFolder')
cy.readFile(`${downloadsFolder}/download.zip`, null, { timeout: 15000 })
.should('exist')
.and('have.length.gt', 30)
// Check all files are included
.and(zipFileContains([
'1+1.txt',
'some@other.txt',
]))
})
/**
* Regression test of https://help.nextcloud.com/t/unable-to-download-files-on-nextcloud-when-multiple-files-selected/221327/5
*/
it('can download selected files with email uid', () => {
const name = `${randomString(5)}@${randomString(3)}`
const user: User = { userId: name, password: name, language: 'en' }
cy.createUser(user).then(() => {
cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/file.txt')
cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/other file.txt')
cy.login(user)
cy.visit('/apps/files')
})
getRowForFile('file.txt')
.should('be.visible')
.findByRole('checkbox')
.check({ force: true })
getRowForFile('other file.txt')
.should('be.visible')
.findByRole('checkbox')
.check({ force: true })
cy.get('[data-cy-files-list]').within(() => {
// see that two files are selected
cy.contains('2 selected').should('be.visible')
})
// click download
cy.get('[data-cy-files-list-selection-actions]')
.findByRole('button', { name: 'Actions' })
.click()
cy.findByRole('menuitem', { name: 'Download (selected)' })
.click()
// check a file is downloaded
const downloadsFolder = Cypress.config('downloadsFolder')
cy.readFile(`${downloadsFolder}/download.zip`, null, { timeout: 15000 })
.should('exist')
.and('have.length.gt', 30)
// Check all files are included
.and(zipFileContains([
'file.txt',
'other file.txt',
]))
})
})