dashboard-tus.spec.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import type BaseTus from '@uppy/tus'
  2. type Tus = BaseTus & {
  3. requests: { isPaused: boolean }
  4. }
  5. describe('Dashboard with Tus', () => {
  6. beforeEach(() => {
  7. cy.visit('/dashboard-tus')
  8. cy.get('.uppy-Dashboard-input').as('file-input')
  9. cy.intercept('/files/*').as('tus')
  10. cy.intercept('http://localhost:3020/url/*').as('url')
  11. cy.intercept('http://localhost:3020/search/unsplash/*').as('unsplash')
  12. })
  13. it('should upload cat image successfully', () => {
  14. cy.get('@file-input').attachFile('images/cat.jpg')
  15. cy.get('.uppy-StatusBar-actionBtn--upload').click()
  16. cy.wait('@tus')
  17. cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
  18. })
  19. it('should start exponential backoff when receiving HTTP 429', () => {
  20. cy.get('@file-input').attachFile(['images/cat.jpg', 'images/traffic.jpg'])
  21. cy.get('.uppy-StatusBar-actionBtn--upload').click()
  22. cy.intercept(
  23. { method: 'PATCH', pathname: '/files/*', times: 1 },
  24. { statusCode: 429, body: {} },
  25. ).as('patch')
  26. cy.wait('@patch')
  27. cy.window().then(({ uppy }) => {
  28. expect(uppy.getPlugin<Tus>('Tus').requests.isPaused).to.equal(true)
  29. cy.wait('@tus')
  30. cy.get('.uppy-StatusBar-statusPrimary', { timeout: 60_000 }).should('contain', 'Complete')
  31. })
  32. })
  33. it('should upload remote image with URL plugin', () => {
  34. cy.get('[data-cy="Url"]').click()
  35. cy.get('.uppy-Url-input').type('https://via.placeholder.com/600x400')
  36. cy.get('.uppy-Url-importButton').click()
  37. cy.get('.uppy-StatusBar-actionBtn--upload').click()
  38. cy.wait('@url')
  39. cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
  40. })
  41. it('should upload remote image with Unsplash plugin', () => {
  42. cy.get('[data-cy="Unsplash"]').click()
  43. cy.get('.uppy-SearchProvider-input').type('book')
  44. cy.get('.uppy-SearchProvider-searchButton').click()
  45. cy.wait('@unsplash')
  46. // Test that the author link is visible
  47. cy.get('.uppy-ProviderBrowserItem')
  48. .first()
  49. .within(() => {
  50. cy.root().click()
  51. // We have hover states that show the author
  52. // but we don't have hover in e2e, so we focus after the click
  53. // to get the same effect. Also tests keyboard users this way.
  54. cy.get('input[type="checkbox"]').focus()
  55. cy.get('a').should('have.css', 'display', 'block')
  56. })
  57. cy.get('.uppy-c-btn-primary').click()
  58. cy.get('.uppy-StatusBar-actionBtn--upload').click()
  59. cy.wait('@unsplash')
  60. // eslint-disable-next-line cypress/no-unnecessary-waiting
  61. cy.wait(2000) // bad practice, but the request is successful before the status bar updates here
  62. cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
  63. })
  64. })