dashboard-tus.spec.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {
  2. interceptCompanionUrlRequest,
  3. interceptCompanionUnsplashRequest,
  4. runRemoteUrlImageUploadTest,
  5. runRemoteUnsplashUploadTest,
  6. } from './reusable-tests'
  7. // NOTE: we have to use different files to upload per test
  8. // because we are uploading to https://tusd.tusdemo.net,
  9. // constantly uploading the same images gives a different cached result (or something).
  10. describe('Dashboard with Tus', () => {
  11. beforeEach(() => {
  12. cy.visit('/dashboard-tus')
  13. cy.get('.uppy-Dashboard-input:first').as('file-input')
  14. cy.intercept('/files/*').as('tus')
  15. cy.intercept({ method: 'POST', pathname: '/files' }).as('post')
  16. cy.intercept({ method: 'PATCH', pathname: '/files/*' }).as('patch')
  17. interceptCompanionUrlRequest()
  18. interceptCompanionUnsplashRequest()
  19. })
  20. it('should upload cat image successfully', () => {
  21. cy.get('@file-input').selectFile('cypress/fixtures/images/cat.jpg', { force:true })
  22. cy.get('.uppy-StatusBar-actionBtn--upload').click()
  23. cy.wait(['@post', '@patch']).then(() => {
  24. cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
  25. })
  26. })
  27. it('should start exponential backoff when receiving HTTP 429', () => {
  28. cy.get('@file-input').selectFile('cypress/fixtures/images/baboon.png', { force: true })
  29. cy.intercept(
  30. { method: 'PATCH', pathname: '/files/*', times: 2 },
  31. { statusCode: 429, body: {} },
  32. ).as('patch')
  33. cy.get('.uppy-StatusBar-actionBtn--upload').click()
  34. cy.wait('@tus').then(() => {
  35. cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
  36. })
  37. })
  38. it('should upload remote image with URL plugin', () => {
  39. runRemoteUrlImageUploadTest()
  40. })
  41. it('should upload remote image with Unsplash plugin', () => {
  42. runRemoteUnsplashUploadTest()
  43. })
  44. })