dashboard-tus.spec.ts 1.9 KB

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