dashboard-tus.spec.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import type BaseTus from '@uppy/tus'
  2. type Tus = BaseTus & {
  3. requests: { isPaused: boolean }
  4. }
  5. // NOTE: we have to use different files to upload per test
  6. // because we are uploading to https://tusd.tusdemo.net,
  7. // constantly uploading the same images gives a different cached result (or something).
  8. describe('Dashboard with Tus', () => {
  9. beforeEach(() => {
  10. cy.visit('/dashboard-tus')
  11. cy.get('.uppy-Dashboard-input').as('file-input')
  12. cy.intercept('/files/*').as('tus')
  13. cy.intercept('http://localhost:3020/url/*').as('url')
  14. cy.intercept('http://localhost:3020/search/unsplash/*').as('unsplash')
  15. })
  16. it('should emit `error` and `upload-error` events on failed POST request', () => {
  17. cy.get('@file-input').attachFile(['images/traffic.jpg'])
  18. const error = cy.spy()
  19. const uploadError = cy.spy()
  20. cy.window().then(({ uppy }) => {
  21. uppy.on('upload-error', uploadError)
  22. uppy.on('error', error)
  23. })
  24. cy.get('.uppy-StatusBar-actionBtn--upload').click()
  25. cy.intercept(
  26. { method: 'POST', url: 'https://tusd.tusdemo.net/*', times: 1 },
  27. { statusCode: 401, body: { code: 401, message: 'Expired JWT Token' } },
  28. ).as('post')
  29. cy.wait('@post').then(() => {
  30. expect(error).to.be.called
  31. expect(uploadError).to.be.called
  32. })
  33. })
  34. it('should upload cat image successfully', () => {
  35. cy.get('@file-input').attachFile('images/cat.jpg')
  36. cy.get('.uppy-StatusBar-actionBtn--upload').click()
  37. cy.wait('@tus')
  38. cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
  39. })
  40. it('should start exponential backoff when receiving HTTP 429', () => {
  41. cy.get('@file-input').attachFile(['images/baboon.png'])
  42. cy.get('.uppy-StatusBar-actionBtn--upload').click()
  43. cy.intercept(
  44. { method: 'PATCH', pathname: '/files/*', times: 2 },
  45. { statusCode: 429, body: {} },
  46. ).as('patch')
  47. cy.wait('@patch')
  48. cy.window().then(({ uppy }) => {
  49. expect(uppy.getPlugin<Tus>('Tus').requests.isPaused).to.equal(true)
  50. cy.wait('@tus')
  51. cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
  52. })
  53. })
  54. it('should upload remote image with URL plugin', () => {
  55. cy.get('[data-cy="Url"]').click()
  56. cy.get('.uppy-Url-input').type('https://raw.githubusercontent.com/transloadit/uppy/main/e2e/cypress/fixtures/images/cat.jpg')
  57. cy.get('.uppy-Url-importButton').click()
  58. cy.get('.uppy-StatusBar-actionBtn--upload').click()
  59. cy.wait('@url')
  60. cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
  61. })
  62. it('should upload remote image with Unsplash plugin', () => {
  63. cy.get('[data-cy="Unsplash"]').click()
  64. cy.get('.uppy-SearchProvider-input').type('book')
  65. cy.get('.uppy-SearchProvider-searchButton').click()
  66. cy.wait('@unsplash')
  67. // Test that the author link is visible
  68. cy.get('.uppy-ProviderBrowserItem')
  69. .first()
  70. .within(() => {
  71. cy.root().click()
  72. // We have hover states that show the author
  73. // but we don't have hover in e2e, so we focus after the click
  74. // to get the same effect. Also tests keyboard users this way.
  75. cy.get('input[type="checkbox"]').focus()
  76. cy.get('a').should('have.css', 'display', 'block')
  77. })
  78. cy.get('.uppy-c-btn-primary').click()
  79. cy.get('.uppy-StatusBar-actionBtn--upload').click()
  80. cy.wait('@unsplash')
  81. cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
  82. })
  83. })