1
0

files-download.cy.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*!
  2. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. import type { User } from '@nextcloud/cypress'
  6. import { getRowForFile, navigateToFolder, triggerActionForFile } from './FilesUtils'
  7. import { deleteDownloadsFolderBeforeEach } from 'cypress-delete-downloads-folder'
  8. describe('files: Download files using file actions', { testIsolation: true }, () => {
  9. let user: User
  10. deleteDownloadsFolderBeforeEach()
  11. beforeEach(() => {
  12. cy.createRandomUser().then(($user) => {
  13. user = $user
  14. })
  15. })
  16. it('can download file', () => {
  17. cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/file.txt')
  18. cy.login(user)
  19. cy.visit('/apps/files')
  20. getRowForFile('file.txt').should('be.visible')
  21. triggerActionForFile('file.txt', 'download')
  22. const downloadsFolder = Cypress.config('downloadsFolder')
  23. cy.readFile(`${downloadsFolder}/file.txt`, { timeout: 15000 })
  24. .should('exist')
  25. .and('have.length.gt', 8)
  26. .and('equal', '<content>')
  27. })
  28. /**
  29. * Regression test of https://github.com/nextcloud/server/issues/44855
  30. */
  31. it('can download file with hash name', () => {
  32. cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/#file.txt')
  33. cy.login(user)
  34. cy.visit('/apps/files')
  35. triggerActionForFile('#file.txt', 'download')
  36. const downloadsFolder = Cypress.config('downloadsFolder')
  37. cy.readFile(`${downloadsFolder}/#file.txt`, { timeout: 15000 })
  38. .should('exist')
  39. .and('have.length.gt', 8)
  40. .and('equal', '<content>')
  41. })
  42. /**
  43. * Regression test of https://github.com/nextcloud/server/issues/44855
  44. */
  45. it('can download file from folder with hash name', () => {
  46. cy.mkdir(user, '/#folder')
  47. .uploadContent(user, new Blob(['<content>']), 'text/plain', '/#folder/file.txt')
  48. cy.login(user)
  49. cy.visit('/apps/files')
  50. navigateToFolder('#folder')
  51. // All are visible by default
  52. getRowForFile('file.txt').should('be.visible')
  53. triggerActionForFile('file.txt', 'download')
  54. const downloadsFolder = Cypress.config('downloadsFolder')
  55. cy.readFile(`${downloadsFolder}/file.txt`, { timeout: 15000 })
  56. .should('exist')
  57. .and('have.length.gt', 8)
  58. .and('equal', '<content>')
  59. })
  60. })
  61. describe('files: Download files using default action', { testIsolation: true }, () => {
  62. let user: User
  63. deleteDownloadsFolderBeforeEach()
  64. beforeEach(() => {
  65. cy.createRandomUser().then(($user) => {
  66. user = $user
  67. })
  68. })
  69. it('can download file', () => {
  70. cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/file.txt')
  71. cy.login(user)
  72. cy.visit('/apps/files')
  73. getRowForFile('file.txt')
  74. .should('be.visible')
  75. .findByRole('button', { name: 'Download' })
  76. .click()
  77. const downloadsFolder = Cypress.config('downloadsFolder')
  78. cy.readFile(`${downloadsFolder}/file.txt`, { timeout: 15000 })
  79. .should('exist')
  80. .and('have.length.gt', 8)
  81. .and('equal', '<content>')
  82. })
  83. /**
  84. * Regression test of https://github.com/nextcloud/server/issues/44855
  85. */
  86. it('can download file with hash name', () => {
  87. cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/#file.txt')
  88. cy.login(user)
  89. cy.visit('/apps/files')
  90. getRowForFile('#file.txt')
  91. .should('be.visible')
  92. .findByRole('button', { name: 'Download' })
  93. .click()
  94. const downloadsFolder = Cypress.config('downloadsFolder')
  95. cy.readFile(`${downloadsFolder}/#file.txt`, { timeout: 15000 })
  96. .should('exist')
  97. .and('have.length.gt', 8)
  98. .and('equal', '<content>')
  99. })
  100. /**
  101. * Regression test of https://github.com/nextcloud/server/issues/44855
  102. */
  103. it('can download file from folder with hash name', () => {
  104. cy.mkdir(user, '/#folder')
  105. .uploadContent(user, new Blob(['<content>']), 'text/plain', '/#folder/file.txt')
  106. cy.login(user)
  107. cy.visit('/apps/files')
  108. navigateToFolder('#folder')
  109. // All are visible by default
  110. getRowForFile('file.txt')
  111. .should('be.visible')
  112. .findByRole('button', { name: 'Download' })
  113. .click()
  114. const downloadsFolder = Cypress.config('downloadsFolder')
  115. cy.readFile(`${downloadsFolder}/file.txt`, { timeout: 15000 })
  116. .should('exist')
  117. .and('have.length.gt', 8)
  118. .and('equal', '<content>')
  119. })
  120. })