dashboard-tus.spec.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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().then(() => {
  23. cy.wait(['@post', '@patch']).then(() => {
  24. cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
  25. })
  26. })
  27. })
  28. it('should start exponential backoff when receiving HTTP 429', () => {
  29. cy.get('@file-input').selectFile('cypress/fixtures/images/baboon.png', { force: true })
  30. cy.intercept(
  31. { method: 'PATCH', pathname: '/files/*', times: 2 },
  32. { statusCode: 429, body: {} },
  33. ).as('patch')
  34. cy.get('.uppy-StatusBar-actionBtn--upload').click().then(() => {
  35. cy.wait('@tus').then(() => {
  36. cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
  37. })
  38. })
  39. })
  40. it('should upload remote image with URL plugin', () => {
  41. runRemoteUrlImageUploadTest()
  42. })
  43. it('should upload remote image with Unsplash plugin', () => {
  44. runRemoteUnsplashUploadTest()
  45. })
  46. })