dashboard-xhr.spec.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {
  2. interceptCompanionUrlMetaRequest,
  3. interceptCompanionUrlRequest,
  4. runRemoteUrlImageUploadTest,
  5. runRemoteUnsplashUploadTest,
  6. } from './reusable-tests.ts'
  7. describe('Dashboard with XHR', () => {
  8. beforeEach(() => {
  9. cy.visit('/dashboard-xhr')
  10. })
  11. it('should upload remote image with URL plugin', () => {
  12. runRemoteUrlImageUploadTest()
  13. })
  14. it('should return correct file name with URL plugin from remote image with Content-Disposition', () => {
  15. const fileName = `DALL·E IMG_9078 - 学中文 🤑`
  16. cy.get('[data-cy="Url"]').click()
  17. cy.get('.uppy-Url-input').type(
  18. 'http://localhost:4678/file-with-content-disposition',
  19. )
  20. interceptCompanionUrlMetaRequest()
  21. cy.get('.uppy-Url-importButton').click()
  22. cy.wait('@url-meta').then(() => {
  23. cy.get('.uppy-Dashboard-Item-name').should('contain', fileName)
  24. cy.get('.uppy-Dashboard-Item-status').should('contain', '84 KB')
  25. })
  26. })
  27. it('should return correct file name with URL plugin from remote image without Content-Disposition', () => {
  28. cy.get('[data-cy="Url"]').click()
  29. cy.get('.uppy-Url-input').type('http://localhost:4678/file-no-headers')
  30. interceptCompanionUrlMetaRequest()
  31. cy.get('.uppy-Url-importButton').click()
  32. cy.wait('@url-meta').then(() => {
  33. cy.get('.uppy-Dashboard-Item-name').should('contain', 'file-no')
  34. cy.get('.uppy-Dashboard-Item-status').should('contain', '0')
  35. })
  36. })
  37. it('should return correct file name even when Companion doesnt supply it', () => {
  38. cy.intercept('POST', 'http://localhost:3020/url/meta', {
  39. statusCode: 200,
  40. headers: {},
  41. body: JSON.stringify({ size: 123, type: 'image/jpeg' }),
  42. }).as('url')
  43. cy.get('[data-cy="Url"]').click()
  44. cy.get('.uppy-Url-input').type(
  45. 'http://localhost:4678/file-with-content-disposition',
  46. )
  47. interceptCompanionUrlMetaRequest()
  48. cy.get('.uppy-Url-importButton').click()
  49. cy.wait('@url-meta').then(() => {
  50. cy.get('.uppy-Dashboard-Item-name').should('contain', 'file-with')
  51. cy.get('.uppy-Dashboard-Item-status').should('contain', '123 B')
  52. })
  53. })
  54. it('should upload unknown size files', () => {
  55. cy.get('[data-cy="Url"]').click()
  56. cy.get('.uppy-Url-input').type('http://localhost:4678/unknown-size')
  57. cy.get('.uppy-Url-importButton').click()
  58. interceptCompanionUrlRequest()
  59. cy.get('.uppy-StatusBar-actionBtn--upload').click()
  60. cy.wait('@url').then(() => {
  61. cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
  62. })
  63. })
  64. it('should upload remote image with Unsplash plugin', () => {
  65. runRemoteUnsplashUploadTest()
  66. })
  67. })