1
0

download-files.cy.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*!
  2. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. // @ts-expect-error The package is currently broken - but works...
  6. import { deleteDownloadsFolderBeforeEach } from 'cypress-delete-downloads-folder'
  7. import { zipFileContains } from '../../../support/utils/assertions.ts'
  8. import { getRowForFile, triggerActionForFile } from '../../files/FilesUtils.ts'
  9. import { getShareUrl, setupPublicShare } from './setup-public-share.ts'
  10. describe('files_sharing: Public share - downloading files', { testIsolation: true }, () => {
  11. before(() => setupPublicShare())
  12. deleteDownloadsFolderBeforeEach()
  13. beforeEach(() => {
  14. cy.logout()
  15. cy.visit(getShareUrl())
  16. })
  17. it('Can download all files', () => {
  18. getRowForFile('foo.txt').should('be.visible')
  19. cy.get('[data-cy-files-list]').within(() => {
  20. cy.findByRole('checkbox', { name: /Toggle selection for all files/i })
  21. .should('exist')
  22. .check({ force: true })
  23. // see that two files are selected
  24. cy.contains('2 selected').should('be.visible')
  25. // click download
  26. cy.findByRole('button', { name: 'Download (selected)' })
  27. .should('be.visible')
  28. .click()
  29. // check a file is downloaded
  30. const downloadsFolder = Cypress.config('downloadsFolder')
  31. cy.readFile(`${downloadsFolder}/download.zip`, null, { timeout: 15000 })
  32. .should('exist')
  33. .and('have.length.gt', 30)
  34. // Check all files are included
  35. .and(zipFileContains([
  36. 'foo.txt',
  37. 'subfolder/',
  38. 'subfolder/bar.txt',
  39. ]))
  40. })
  41. })
  42. it('Can download selected files', () => {
  43. getRowForFile('subfolder')
  44. .should('be.visible')
  45. cy.get('[data-cy-files-list]').within(() => {
  46. getRowForFile('subfolder')
  47. .findByRole('checkbox')
  48. .check({ force: true })
  49. // see that two files are selected
  50. cy.contains('1 selected').should('be.visible')
  51. // click download
  52. cy.findByRole('button', { name: 'Download (selected)' })
  53. .should('be.visible')
  54. .click()
  55. // check a file is downloaded
  56. const downloadsFolder = Cypress.config('downloadsFolder')
  57. cy.readFile(`${downloadsFolder}/subfolder.zip`, null, { timeout: 15000 })
  58. .should('exist')
  59. .and('have.length.gt', 30)
  60. // Check all files are included
  61. .and(zipFileContains([
  62. 'subfolder/',
  63. 'subfolder/bar.txt',
  64. ]))
  65. })
  66. })
  67. it('Can download folder by action', () => {
  68. getRowForFile('subfolder')
  69. .should('be.visible')
  70. cy.get('[data-cy-files-list]').within(() => {
  71. triggerActionForFile('subfolder', 'download')
  72. // check a file is downloaded
  73. const downloadsFolder = Cypress.config('downloadsFolder')
  74. cy.readFile(`${downloadsFolder}/subfolder.zip`, null, { timeout: 15000 })
  75. .should('exist')
  76. .and('have.length.gt', 30)
  77. // Check all files are included
  78. .and(zipFileContains([
  79. 'subfolder/',
  80. 'subfolder/bar.txt',
  81. ]))
  82. })
  83. })
  84. it('Can download file by action', () => {
  85. getRowForFile('foo.txt')
  86. .should('be.visible')
  87. cy.get('[data-cy-files-list]').within(() => {
  88. triggerActionForFile('foo.txt', 'download')
  89. // check a file is downloaded
  90. const downloadsFolder = Cypress.config('downloadsFolder')
  91. cy.readFile(`${downloadsFolder}/foo.txt`, 'utf-8', { timeout: 15000 })
  92. .should('exist')
  93. .and('have.length.gt', 5)
  94. .and('contain', '<content>foo</content>')
  95. })
  96. })
  97. it('Can download file by selection', () => {
  98. getRowForFile('foo.txt')
  99. .should('be.visible')
  100. cy.get('[data-cy-files-list]').within(() => {
  101. getRowForFile('foo.txt')
  102. .findByRole('checkbox')
  103. .check({ force: true })
  104. cy.findByRole('button', { name: 'Download (selected)' })
  105. .click()
  106. // check a file is downloaded
  107. const downloadsFolder = Cypress.config('downloadsFolder')
  108. cy.readFile(`${downloadsFolder}/foo.txt`, 'utf-8', { timeout: 15000 })
  109. .should('exist')
  110. .and('have.length.gt', 5)
  111. .and('contain', '<content>foo</content>')
  112. })
  113. })
  114. })