file-request.cy.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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, enterGuestName } from './FilesSharingUtils'
  8. describe('Files', { testIsolation: true }, () => {
  9. let user: User
  10. let url = ''
  11. let folderName = 'test-folder'
  12. it('Login with a user and create a file request', () => {
  13. cy.createRandomUser().then((_user) => {
  14. user = _user
  15. cy.login(user)
  16. })
  17. cy.visit('/apps/files')
  18. createFolder(folderName)
  19. createFileRequest(`/${folderName}`)
  20. cy.get('@fileRequestUrl').should('contain', '/s/').then((_url: string) => {
  21. cy.logout()
  22. url = _url
  23. })
  24. })
  25. it('Open the file request as a guest', () => {
  26. cy.visit(url)
  27. enterGuestName('Guest')
  28. // Check various elements on the page
  29. cy.get('#public-upload .emptycontent').should('be.visible')
  30. cy.get('#public-upload h2').contains(`Upload files to ${folderName}`)
  31. cy.get('#public-upload input[type="file"]').as('fileInput').should('exist')
  32. cy.intercept('PUT', '/public.php/dav/files/*/*').as('uploadFile')
  33. // Upload a file
  34. cy.get('@fileInput').selectFile({
  35. contents: Cypress.Buffer.from('abcdef'),
  36. fileName: 'file.txt',
  37. mimeType: 'text/plain',
  38. lastModified: Date.now(),
  39. }, { force: true })
  40. cy.wait('@uploadFile').its('response.statusCode').should('eq', 201)
  41. })
  42. it('Check the uploaded file', () => {
  43. cy.login(user)
  44. cy.visit(`/apps/files/files?dir=/${folderName}`)
  45. getRowForFile('Guest')
  46. .should('be.visible')
  47. navigateToFolder('Guest')
  48. getRowForFile('file.txt').should('be.visible')
  49. })
  50. })