dashboard-tus.spec.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 upload cat image successfully', () => {
  17. cy.get('@file-input').attachFile('images/cat.jpg')
  18. cy.get('.uppy-StatusBar-actionBtn--upload').click()
  19. cy.wait('@tus')
  20. cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
  21. })
  22. it('should start exponential backoff when receiving HTTP 429', () => {
  23. cy.get('@file-input').attachFile(['images/baboon.png'])
  24. cy.get('.uppy-StatusBar-actionBtn--upload').click()
  25. cy.intercept(
  26. { method: 'PATCH', pathname: '/files/*', times: 2 },
  27. { statusCode: 429, body: {} },
  28. ).as('patch')
  29. cy.wait('@patch')
  30. cy.wait('@patch')
  31. cy.window().then(({ uppy }) => {
  32. expect(uppy.getPlugin<Tus>('Tus').requests.isPaused).to.equal(true)
  33. cy.wait('@tus')
  34. cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
  35. })
  36. })
  37. it('should upload remote image with URL plugin', () => {
  38. cy.get('[data-cy="Url"]').click()
  39. cy.get('.uppy-Url-input').type('https://raw.githubusercontent.com/transloadit/uppy/main/e2e/cypress/fixtures/images/cat.jpg')
  40. cy.get('.uppy-Url-importButton').click()
  41. cy.get('.uppy-StatusBar-actionBtn--upload').click()
  42. cy.wait('@url')
  43. cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
  44. })
  45. it('should upload remote image with Unsplash plugin', () => {
  46. cy.get('[data-cy="Unsplash"]').click()
  47. cy.get('.uppy-SearchProvider-input').type('book')
  48. cy.get('.uppy-SearchProvider-searchButton').click()
  49. cy.wait('@unsplash')
  50. // Test that the author link is visible
  51. cy.get('.uppy-ProviderBrowserItem')
  52. .first()
  53. .within(() => {
  54. cy.root().click()
  55. // We have hover states that show the author
  56. // but we don't have hover in e2e, so we focus after the click
  57. // to get the same effect. Also tests keyboard users this way.
  58. cy.get('input[type="checkbox"]').focus()
  59. cy.get('a').should('have.css', 'display', 'block')
  60. })
  61. cy.get('.uppy-c-btn-primary').click()
  62. cy.get('.uppy-StatusBar-actionBtn--upload').click()
  63. cy.wait('@unsplash')
  64. cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
  65. })
  66. })