view_view-only-no-download.cy.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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([]), 'text/plain', `/${shareName}/foo.txt`)
  15. cy.uploadContent($user, new Blob([]), '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. cy.findByRole('checkbox', { name: 'Hide download' })
  45. .check({ force: true })
  46. // save the update
  47. cy.intercept('PUT', '**/ocs/v2.php/apps/files_sharing/api/v1/shares/*').as('updateShare')
  48. cy.findByRole('button', { name: 'Update share' })
  49. .click()
  50. cy.wait('@updateShare')
  51. })
  52. })
  53. beforeEach(() => {
  54. cy.logout()
  55. cy.visit(shareUrl)
  56. })
  57. it('Can see the files list', () => {
  58. // foo exists
  59. getRowForFile('foo.txt')
  60. .should('be.visible')
  61. })
  62. it('But no actions available', () => {
  63. // foo exists
  64. getRowForFile('foo.txt')
  65. .should('be.visible')
  66. // but no actions
  67. getActionButtonForFile('foo.txt')
  68. .should('not.exist')
  69. // TODO: We really need Viewer in the server repo.
  70. // So we could at least test viewing images
  71. })
  72. it('Can navigate to subfolder', () => {
  73. getRowForFile('subfolder')
  74. .should('be.visible')
  75. navigateToFolder('subfolder')
  76. getRowForFile('bar.txt')
  77. .should('be.visible')
  78. // but also no actions
  79. getActionButtonForFile('bar.txt')
  80. .should('not.exist')
  81. })
  82. it('Cannot upload files', () => {
  83. // wait for file list to be ready
  84. getRowForFile('foo.txt')
  85. .should('be.visible')
  86. cy.contains('button', 'New')
  87. .should('be.visible')
  88. .and('be.disabled')
  89. })
  90. })