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