DashboardModal.test.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 = new 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 = new 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 = new 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. it('react on HTMLDivElement props update', async () => {
  64. const uppy = new Uppy()
  65. const dash = mount((
  66. <DashboardModal
  67. uppy={uppy}
  68. hidden
  69. />
  70. ))
  71. expect(dash.getDOMNode().hidden).toBeTruthy()
  72. dash.setProps({ hidden: false })
  73. expect(dash.getDOMNode().hidden).toBeFalsy()
  74. dash.unmount()
  75. })
  76. it('react on @uppy/dashboard props update', async () => {
  77. const uppy = new Uppy()
  78. const dash = mount((
  79. <DashboardModal
  80. uppy={uppy}
  81. theme="dark"
  82. />
  83. ))
  84. const { plugin } = dash.instance()
  85. expect(plugin.opts.theme).toBe('dark')
  86. dash.setProps({ theme: 'light' })
  87. expect(plugin.opts.theme).toBe('light')
  88. dash.unmount()
  89. })
  90. })