Skip to content

Commit 0dc9711

Browse files
authored
Merge pull request #52636 from nextcloud/test/files-download
2 parents e3e6a3b + 88829b3 commit 0dc9711

File tree

1 file changed

+206
-0
lines changed

1 file changed

+206
-0
lines changed

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

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import type { User } from '@nextcloud/cypress'
77
import { getRowForFile, navigateToFolder, triggerActionForFile } from './FilesUtils'
88
import { deleteDownloadsFolderBeforeEach } from 'cypress-delete-downloads-folder'
9+
import { zipFileContains } from '../../support/utils/assertions.ts'
10+
11+
import randomString from 'crypto-random-string'
912

1013
describe('files: Download files using file actions', { testIsolation: true }, () => {
1114
let user: User
@@ -34,6 +37,29 @@ describe('files: Download files using file actions', { testIsolation: true }, ()
3437
.and('equal', '<content>')
3538
})
3639

40+
it('can download folder', () => {
41+
cy.mkdir(user, '/subfolder')
42+
cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/subfolder/file.txt')
43+
44+
cy.login(user)
45+
cy.visit('/apps/files')
46+
getRowForFile('subfolder')
47+
.should('be.visible')
48+
49+
triggerActionForFile('subfolder', 'download')
50+
51+
// check a file is downloaded
52+
const downloadsFolder = Cypress.config('downloadsFolder')
53+
cy.readFile(`${downloadsFolder}/subfolder.zip`, null, { timeout: 15000 })
54+
.should('exist')
55+
.and('have.length.gt', 30)
56+
// Check all files are included
57+
.and(zipFileContains([
58+
'subfolder/',
59+
'subfolder/file.txt',
60+
]))
61+
})
62+
3763
/**
3864
* Regression test of https://github.com/nextcloud/server/issues/44855
3965
*/
@@ -143,3 +169,183 @@ describe('files: Download files using default action', { testIsolation: true },
143169
.and('equal', '<content>')
144170
})
145171
})
172+
173+
describe('files: Download files using selection', () => {
174+
175+
deleteDownloadsFolderBeforeEach()
176+
177+
it('can download selected files', () => {
178+
cy.createRandomUser().then((user) => {
179+
cy.mkdir(user, '/subfolder')
180+
cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/subfolder/file.txt')
181+
cy.login(user)
182+
cy.visit('/apps/files')
183+
})
184+
185+
getRowForFile('subfolder')
186+
.should('be.visible')
187+
188+
getRowForFile('subfolder')
189+
.findByRole('checkbox')
190+
.check({ force: true })
191+
192+
// see that two files are selected
193+
cy.get('[data-cy-files-list]').within(() => {
194+
cy.contains('1 selected').should('be.visible')
195+
})
196+
197+
// click download
198+
cy.get('[data-cy-files-list-selection-actions]')
199+
.findByRole('button', { name: 'Actions' })
200+
.click()
201+
cy.findByRole('menuitem', { name: 'Download (selected)' })
202+
.should('be.visible')
203+
.click()
204+
205+
// check a file is downloaded
206+
const downloadsFolder = Cypress.config('downloadsFolder')
207+
cy.readFile(`${downloadsFolder}/subfolder.zip`, null, { timeout: 15000 })
208+
.should('exist')
209+
.and('have.length.gt', 30)
210+
// Check all files are included
211+
.and(zipFileContains([
212+
'subfolder/',
213+
'subfolder/file.txt',
214+
]))
215+
})
216+
217+
it('can download multiple selected files', () => {
218+
cy.createRandomUser().then((user) => {
219+
cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/file.txt')
220+
cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/other file.txt')
221+
cy.login(user)
222+
cy.visit('/apps/files')
223+
})
224+
225+
getRowForFile('file.txt')
226+
.should('be.visible')
227+
.findByRole('checkbox')
228+
.check({ force: true })
229+
230+
getRowForFile('other file.txt')
231+
.should('be.visible')
232+
.findByRole('checkbox')
233+
.check({ force: true })
234+
235+
cy.get('[data-cy-files-list]').within(() => {
236+
// see that two files are selected
237+
cy.contains('2 selected').should('be.visible')
238+
})
239+
240+
// click download
241+
cy.get('[data-cy-files-list-selection-actions]')
242+
.findByRole('button', { name: 'Actions' })
243+
.click()
244+
cy.findByRole('menuitem', { name: 'Download (selected)' })
245+
.click()
246+
247+
// check a file is downloaded
248+
const downloadsFolder = Cypress.config('downloadsFolder')
249+
cy.readFile(`${downloadsFolder}/download.zip`, null, { timeout: 15000 })
250+
.should('exist')
251+
.and('have.length.gt', 30)
252+
// Check all files are included
253+
.and(zipFileContains([
254+
'file.txt',
255+
'other file.txt',
256+
]))
257+
})
258+
259+
/**
260+
* Regression test of https://help.nextcloud.com/t/unable-to-download-files-on-nextcloud-when-multiple-files-selected/221327/5
261+
*/
262+
it('can download selected files with special characters', () => {
263+
cy.createRandomUser().then((user) => {
264+
cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/1+1.txt')
265+
cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/some@other.txt')
266+
cy.login(user)
267+
cy.visit('/apps/files')
268+
})
269+
270+
getRowForFile('some@other.txt')
271+
.should('be.visible')
272+
.findByRole('checkbox')
273+
.check({ force: true })
274+
275+
getRowForFile('1+1.txt')
276+
.should('be.visible')
277+
.findByRole('checkbox')
278+
.check({ force: true })
279+
280+
cy.get('[data-cy-files-list]').within(() => {
281+
// see that two files are selected
282+
cy.contains('2 selected').should('be.visible')
283+
})
284+
285+
// click download
286+
cy.get('[data-cy-files-list-selection-actions]')
287+
.findByRole('button', { name: 'Actions' })
288+
.click()
289+
cy.findByRole('menuitem', { name: 'Download (selected)' })
290+
.click()
291+
292+
// check a file is downloaded
293+
const downloadsFolder = Cypress.config('downloadsFolder')
294+
cy.readFile(`${downloadsFolder}/download.zip`, null, { timeout: 15000 })
295+
.should('exist')
296+
.and('have.length.gt', 30)
297+
// Check all files are included
298+
.and(zipFileContains([
299+
'1+1.txt',
300+
'some@other.txt',
301+
]))
302+
})
303+
304+
/**
305+
* Regression test of https://help.nextcloud.com/t/unable-to-download-files-on-nextcloud-when-multiple-files-selected/221327/5
306+
*/
307+
it('can download selected files with email uid', () => {
308+
const name = `${randomString(5)}@${randomString(3)}`
309+
const user: User = { userId: name, password: name, language: 'en' }
310+
311+
cy.createUser(user).then(() => {
312+
cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/file.txt')
313+
cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/other file.txt')
314+
cy.login(user)
315+
cy.visit('/apps/files')
316+
})
317+
318+
getRowForFile('file.txt')
319+
.should('be.visible')
320+
.findByRole('checkbox')
321+
.check({ force: true })
322+
323+
getRowForFile('other file.txt')
324+
.should('be.visible')
325+
.findByRole('checkbox')
326+
.check({ force: true })
327+
328+
cy.get('[data-cy-files-list]').within(() => {
329+
// see that two files are selected
330+
cy.contains('2 selected').should('be.visible')
331+
})
332+
333+
// click download
334+
cy.get('[data-cy-files-list-selection-actions]')
335+
.findByRole('button', { name: 'Actions' })
336+
.click()
337+
cy.findByRole('menuitem', { name: 'Download (selected)' })
338+
.click()
339+
340+
// check a file is downloaded
341+
const downloadsFolder = Cypress.config('downloadsFolder')
342+
cy.readFile(`${downloadsFolder}/download.zip`, null, { timeout: 15000 })
343+
.should('exist')
344+
.and('have.length.gt', 30)
345+
// Check all files are included
346+
.and(zipFileContains([
347+
'file.txt',
348+
'other file.txt',
349+
]))
350+
})
351+
})

0 commit comments

Comments
 (0)