view_view-only.cy.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*!
  2. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. import { getActionButtonForFile, getRowForFile, navigateToFolder } from '../../files/FilesUtils.ts'
  6. import { openSharingPanel } from '../FilesSharingUtils.ts'
  7. describe('files_sharing: Public share - View only', { testIsolation: true }, () => {
  8. let shareUrl: string
  9. const shareName = 'shared'
  10. before(() => {
  11. cy.createRandomUser().then(($user) => {
  12. cy.mkdir($user, `/${shareName}`)
  13. cy.mkdir($user, `/${shareName}/subfolder`)
  14. cy.uploadContent($user, new Blob(['content']), 'text/plain', `/${shareName}/foo.txt`)
  15. cy.uploadContent($user, new Blob(['content']), 'text/plain', `/${shareName}/subfolder/bar.txt`)
  16. cy.login($user)
  17. // open the files app
  18. cy.visit('/apps/files')
  19. // open the sidebar
  20. openSharingPanel(shareName)
  21. // create the share
  22. cy.intercept('POST', '**/ocs/v2.php/apps/files_sharing/api/v1/shares').as('createShare')
  23. cy.findByRole('button', { name: 'Create a new share link' })
  24. .click()
  25. // extract the link
  26. cy.wait('@createShare').should(({ response }) => {
  27. const { ocs } = response?.body ?? {}
  28. shareUrl = ocs?.data.url
  29. expect(shareUrl).to.match(/^http:\/\//)
  30. })
  31. // Update the share to be a view-only-no-download share
  32. cy.findByRole('list', { name: 'Link shares' })
  33. .findAllByRole('listitem')
  34. .first()
  35. .findByRole('button', { name: /Actions/i })
  36. .click()
  37. cy.findByRole('menuitem', { name: /Customize link/i })
  38. .should('be.visible')
  39. .click()
  40. cy.get('[data-cy-files-sharing-share-permissions-bundle]')
  41. .should('be.visible')
  42. cy.get('[data-cy-files-sharing-share-permissions-bundle="read-only"]')
  43. .click()
  44. // save the update
  45. cy.intercept('PUT', '**/ocs/v2.php/apps/files_sharing/api/v1/shares/*').as('updateShare')
  46. cy.findByRole('button', { name: 'Update share' })
  47. .click()
  48. cy.wait('@updateShare')
  49. })
  50. })
  51. beforeEach(() => {
  52. cy.logout()
  53. cy.visit(shareUrl)
  54. })
  55. it('Can see the files list', () => {
  56. // foo exists
  57. getRowForFile('foo.txt')
  58. .should('be.visible')
  59. })
  60. it('Can navigate to subfolder', () => {
  61. getRowForFile('subfolder')
  62. .should('be.visible')
  63. navigateToFolder('subfolder')
  64. getRowForFile('bar.txt')
  65. .should('be.visible')
  66. })
  67. it('Cannot upload files', () => {
  68. // wait for file list to be ready
  69. getRowForFile('foo.txt')
  70. .should('be.visible')
  71. cy.contains('button', 'New')
  72. .should('be.visible')
  73. .and('be.disabled')
  74. })
  75. it('Only download action is actions available', () => {
  76. getActionButtonForFile('foo.txt')
  77. .should('be.visible')
  78. .click()
  79. // Only the download action
  80. cy.findByRole('menuitem', { name: 'Download' })
  81. .should('be.visible')
  82. cy.findAllByRole('menuitem')
  83. .should('have.length', 1)
  84. // Can download
  85. cy.findByRole('menuitem', { name: 'Download' }).click()
  86. // check a file is downloaded
  87. const downloadsFolder = Cypress.config('downloadsFolder')
  88. cy.readFile(`${downloadsFolder}/foo.txt`, 'utf-8', { timeout: 15000 })
  89. .should('exist')
  90. .and('have.length.gt', 5)
  91. .and('contain', 'content')
  92. })
  93. })