ProgressBar.test.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const h = require('react').createElement
  2. const { mount, configure } = require('enzyme')
  3. const ReactAdapter = require('enzyme-adapter-react-16')
  4. const Uppy = require('@uppy/core')
  5. beforeAll(() => {
  6. configure({ adapter: new ReactAdapter() })
  7. })
  8. jest.mock('@uppy/progress-bar', () => require('./__mocks__/ProgressBarPlugin'))
  9. const ProgressBar = require('./ProgressBar')
  10. describe('react <ProgressBar />', () => {
  11. it('can be mounted and unmounted', () => {
  12. const oninstall = jest.fn()
  13. const onuninstall = jest.fn()
  14. const uppy = new Uppy()
  15. const dash = mount((
  16. <ProgressBar
  17. uppy={uppy}
  18. onInstall={oninstall}
  19. onUninstall={onuninstall}
  20. />
  21. ))
  22. expect(oninstall).toHaveBeenCalled()
  23. expect(onuninstall).not.toHaveBeenCalled()
  24. dash.unmount()
  25. expect(oninstall).toHaveBeenCalled()
  26. expect(onuninstall).toHaveBeenCalled()
  27. })
  28. it('react on HTMLDivElement props update', async () => {
  29. const uppy = new Uppy()
  30. const dash = mount((
  31. <ProgressBar
  32. uppy={uppy}
  33. onInstall={Function.prototype}
  34. onUninstall={Function.prototype}
  35. hidden
  36. />
  37. ))
  38. expect(dash.getDOMNode().hidden).toBeTruthy()
  39. dash.setProps({ hidden: false })
  40. expect(dash.getDOMNode().hidden).toBeFalsy()
  41. dash.unmount()
  42. })
  43. })