dashboard-tus.spec.ts 2.9 KB

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