file-request.cy.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 { createFolder, getRowForFile, navigateToFolder } from '../files/FilesUtils'
  7. import { createFileRequest } from './FilesSharingUtils'
  8. const enterGuestName = (name: string) => {
  9. cy.findByRole('dialog', { name: /Upload files to/ })
  10. .should('be.visible')
  11. .within(() => {
  12. cy.findByRole('textbox', { name: 'Nickname' })
  13. .should('be.visible')
  14. cy.findByRole('textbox', { name: 'Nickname' })
  15. .type(`{selectall}${name}`)
  16. cy.findByRole('button', { name: 'Submit name' })
  17. .should('be.visible')
  18. .click()
  19. })
  20. cy.findByRole('dialog', { name: /Upload files to/ })
  21. .should('not.exist')
  22. }
  23. describe('Files', { testIsolation: true }, () => {
  24. const folderName = 'test-folder'
  25. let user: User
  26. let url = ''
  27. it('Login with a user and create a file request', () => {
  28. cy.createRandomUser().then((_user) => {
  29. user = _user
  30. cy.login(user)
  31. })
  32. cy.visit('/apps/files')
  33. createFolder(folderName)
  34. createFileRequest(`/${folderName}`)
  35. cy.get('@fileRequestUrl').should('contain', '/s/').then((_url: string) => {
  36. cy.logout()
  37. url = _url
  38. })
  39. })
  40. it('Open the file request as a guest', () => {
  41. cy.visit(url)
  42. enterGuestName('Guest')
  43. // Check various elements on the page
  44. cy.contains(`Upload files to ${folderName}`)
  45. .should('be.visible')
  46. cy.findByRole('button', { name: 'Upload' })
  47. .should('be.visible')
  48. cy.intercept('PUT', '/public.php/dav/files/*/*').as('uploadFile')
  49. // Upload a file
  50. cy.get('[data-cy-files-sharing-file-drop] input[type="file"]')
  51. .should('exist')
  52. .selectFile({
  53. contents: Cypress.Buffer.from('abcdef'),
  54. fileName: 'file.txt',
  55. mimeType: 'text/plain',
  56. lastModified: Date.now(),
  57. }, { force: true })
  58. cy.wait('@uploadFile').its('response.statusCode').should('eq', 201)
  59. })
  60. it('Check the uploaded file', () => {
  61. cy.login(user)
  62. cy.visit(`/apps/files/files?dir=/${folderName}`)
  63. getRowForFile('Guest')
  64. .should('be.visible')
  65. navigateToFolder('Guest')
  66. getRowForFile('file.txt').should('be.visible')
  67. })
  68. })