react.spec.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. describe('@uppy/react', () => {
  2. beforeEach(() => {
  3. cy.visit('/react')
  4. cy.get('#dashboard .uppy-Dashboard-input:first').as('dashboard-input')
  5. cy.get('#modal .uppy-Dashboard-input:first').as('modal-input')
  6. cy.get('#drag-drop .uppy-DragDrop-input').as('dragdrop-input')
  7. })
  8. it('should render Dashboard in React and show thumbnails', () => {
  9. cy.get('@dashboard-input').selectFile(
  10. [
  11. 'cypress/fixtures/images/cat.jpg',
  12. 'cypress/fixtures/images/traffic.jpg',
  13. ],
  14. { force: true },
  15. )
  16. cy.get('#dashboard .uppy-Dashboard-Item-previewImg')
  17. .should('have.length', 2)
  18. .each((element) => expect(element).attr('src').to.include('blob:'))
  19. })
  20. it('should render Dashboard with Remote Sources plugin pack', () => {
  21. const sources = [
  22. 'My Device',
  23. 'Google Drive',
  24. 'OneDrive',
  25. 'Unsplash',
  26. 'Zoom',
  27. 'Link',
  28. ]
  29. cy.get('#dashboard .uppy-DashboardTab-name').each((item, index, list) => {
  30. expect(list).to.have.length(6)
  31. // Returns the current element from the loop
  32. expect(Cypress.$(item).text()).to.eq(sources[index])
  33. })
  34. })
  35. it('should render Modal in React and show thumbnails', () => {
  36. cy.get('#open').click()
  37. cy.get('@modal-input').selectFile(
  38. [
  39. 'cypress/fixtures/images/cat.jpg',
  40. 'cypress/fixtures/images/traffic.jpg',
  41. ],
  42. { force: true },
  43. )
  44. cy.get('#modal .uppy-Dashboard-Item-previewImg')
  45. .should('have.length', 2)
  46. .each((element) => expect(element).attr('src').to.include('blob:'))
  47. })
  48. it('should render Drag & Drop in React and create a thumbail with @uppy/thumbnail-generator', () => {
  49. const spy = cy.spy()
  50. // eslint-disable-next-line
  51. // @ts-ignore fix me
  52. cy.window().then(({ uppy }) => uppy.on('thumbnail:generated', spy))
  53. cy.get('@dragdrop-input').selectFile(
  54. [
  55. 'cypress/fixtures/images/cat.jpg',
  56. 'cypress/fixtures/images/traffic.jpg',
  57. ],
  58. { force: true },
  59. )
  60. // not sure how I can accurately wait for the thumbnail
  61. // eslint-disable-next-line cypress/no-unnecessary-waiting
  62. cy.wait(1000).then(() => expect(spy).to.be.called)
  63. })
  64. })