DashboardModal.test.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. jest.mock('@uppy/dashboard', () => require('./__mocks__/DashboardPlugin'))
  6. const DashboardModal = require('./DashboardModal')
  7. beforeAll(() => {
  8. configure({ adapter: new ReactAdapter() })
  9. })
  10. beforeEach(() => {
  11. Object.assign(require('@uppy/dashboard').prototype, {
  12. openModal: jest.fn(),
  13. closeModal: jest.fn()
  14. })
  15. })
  16. describe('react <DashboardModal />', () => {
  17. it('can be mounted and unmounted', () => {
  18. const oninstall = jest.fn()
  19. const onuninstall = jest.fn()
  20. const uppy = Uppy()
  21. const dash = mount((
  22. <DashboardModal
  23. uppy={uppy}
  24. onInstall={oninstall}
  25. onUninstall={onuninstall}
  26. />
  27. ))
  28. expect(oninstall).toHaveBeenCalled()
  29. expect(onuninstall).not.toHaveBeenCalled()
  30. dash.unmount()
  31. expect(oninstall).toHaveBeenCalled()
  32. expect(onuninstall).toHaveBeenCalled()
  33. })
  34. it('opens the modal using the `open={true}` prop', () => {
  35. const uppy = Uppy()
  36. const dash = mount((
  37. <DashboardModal
  38. uppy={uppy}
  39. open={false}
  40. />
  41. ))
  42. const { plugin } = dash.instance()
  43. expect(plugin.openModal).not.toHaveBeenCalled()
  44. dash.setProps({ open: true })
  45. expect(plugin.openModal).toHaveBeenCalled()
  46. dash.unmount()
  47. })
  48. it('closes the modal using the `open={false}` prop', () => {
  49. const uppy = Uppy()
  50. const dash = mount((
  51. <DashboardModal
  52. uppy={uppy}
  53. open
  54. />
  55. ))
  56. const { plugin } = dash.instance()
  57. expect(plugin.openModal).toHaveBeenCalled()
  58. expect(plugin.closeModal).not.toHaveBeenCalled()
  59. dash.setProps({ open: false })
  60. expect(plugin.closeModal).toHaveBeenCalled()
  61. dash.unmount()
  62. })
  63. })