react-dropzone 3.13.0 → 3.13.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +3 -54
- package/.travis.yml +2 -7
- package/README.md +12 -78
- package/commitlint.config.js +1 -0
- package/dist/index.js +94 -71
- package/dist/index.js.map +1 -1
- package/examples/.eslintrc +3 -0
- package/examples/Accept/Readme.md +63 -11
- package/examples/Basic/Readme.md +9 -12
- package/examples/File Dialog/Readme.md +16 -0
- package/examples/Fullscreen/Readme.md +19 -20
- package/examples/Styling/Readme.md +23 -0
- package/package.json +28 -30
- package/src/__snapshots__/index.spec.js.snap +5 -3
- package/src/getDataTransferItems.js +7 -12
- package/src/getDataTransferItems.spec.js +48 -61
- package/src/index.js +164 -142
- package/src/index.spec.js +604 -592
- package/styleguide.config.js +28 -5
- package/testSetup.js +3 -2
- package/wallaby.config.js +3 -9
- package/webpack.config.js +3 -6
- package/yarn.lock +1549 -1029
- package/examples/Accept/index.js +0 -38
- package/examples/Basic/index.js +0 -26
- package/examples/Fullscreen/index.js +0 -78
- package/examples/Readme.md +0 -1
package/src/index.spec.js
CHANGED
|
@@ -1,31 +1,36 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { mount, render } from 'enzyme'
|
|
3
|
-
import { spy, stub } from 'sinon'
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { mount, render } from 'enzyme'
|
|
3
|
+
import { spy, stub } from 'sinon'
|
|
4
4
|
|
|
5
|
-
const Dropzone = require(process.env.NODE_ENV === 'production' ? '../dist/index' : './index')
|
|
5
|
+
const Dropzone = require(process.env.NODE_ENV === 'production' ? '../dist/index' : './index') // eslint-disable-line import/no-dynamic-require
|
|
6
|
+
const DummyChildComponent = () => null
|
|
6
7
|
|
|
7
|
-
let files
|
|
8
|
-
let images
|
|
8
|
+
let files
|
|
9
|
+
let images
|
|
9
10
|
|
|
10
11
|
describe('Dropzone', () => {
|
|
11
|
-
|
|
12
12
|
beforeEach(() => {
|
|
13
|
-
files = [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
13
|
+
files = [
|
|
14
|
+
{
|
|
15
|
+
name: 'file1.pdf',
|
|
16
|
+
size: 1111,
|
|
17
|
+
type: 'application/pdf'
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
images = [
|
|
22
|
+
{
|
|
23
|
+
name: 'cats.gif',
|
|
24
|
+
size: 1234,
|
|
25
|
+
type: 'image/gif'
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'dogs.jpg',
|
|
29
|
+
size: 2345,
|
|
30
|
+
type: 'image/jpeg'
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
})
|
|
29
34
|
|
|
30
35
|
describe('basics', () => {
|
|
31
36
|
it('should render children', () => {
|
|
@@ -33,242 +38,242 @@ describe('Dropzone', () => {
|
|
|
33
38
|
<Dropzone>
|
|
34
39
|
<p>some content</p>
|
|
35
40
|
</Dropzone>
|
|
36
|
-
)
|
|
37
|
-
expect(dropzone.html()).toMatchSnapshot()
|
|
38
|
-
})
|
|
41
|
+
)
|
|
42
|
+
expect(dropzone.html()).toMatchSnapshot()
|
|
43
|
+
})
|
|
39
44
|
|
|
40
45
|
it('should render an input HTML element', () => {
|
|
41
46
|
const dropzone = mount(
|
|
42
47
|
<Dropzone>
|
|
43
48
|
<p>some content</p>
|
|
44
49
|
</Dropzone>
|
|
45
|
-
)
|
|
46
|
-
expect(dropzone.find('input').length).toEqual(1)
|
|
47
|
-
})
|
|
50
|
+
)
|
|
51
|
+
expect(dropzone.find('input').length).toEqual(1)
|
|
52
|
+
})
|
|
48
53
|
|
|
49
54
|
it('sets ref properly', () => {
|
|
50
|
-
const dropzone = mount(
|
|
51
|
-
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
expect(dropzone.instance().fileInputEl.tagName).toEqual('INPUT');
|
|
55
|
-
});
|
|
55
|
+
const dropzone = mount(<Dropzone />)
|
|
56
|
+
expect(dropzone.instance().fileInputEl).not.toBeUndefined()
|
|
57
|
+
expect(dropzone.instance().fileInputEl.tagName).toEqual('INPUT')
|
|
58
|
+
})
|
|
56
59
|
|
|
57
60
|
it('renders dynamic props on the root element', () => {
|
|
58
|
-
const component = mount(
|
|
59
|
-
|
|
60
|
-
)
|
|
61
|
-
expect(component.html()).toContain('
|
|
62
|
-
|
|
63
|
-
expect(component.html()).toContain('title="Dropzone"');
|
|
64
|
-
});
|
|
61
|
+
const component = mount(<Dropzone hidden aria-hidden title="Dropzone" />)
|
|
62
|
+
expect(component.html()).toContain('aria-hidden="true"')
|
|
63
|
+
expect(component.html()).toContain('hidden=""')
|
|
64
|
+
expect(component.html()).toContain('title="Dropzone"')
|
|
65
|
+
})
|
|
65
66
|
|
|
66
67
|
it('renders dynamic props on the input element', () => {
|
|
67
|
-
const component = mount(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
expect(component.find('input').html()).toContain('id="hiddenFileInput"');
|
|
71
|
-
});
|
|
68
|
+
const component = mount(<Dropzone inputProps={{ id: 'hiddenFileInput' }} />)
|
|
69
|
+
expect(component.find('input').html()).toContain('id="hiddenFileInput"')
|
|
70
|
+
})
|
|
72
71
|
|
|
73
72
|
it('applies the accept prop to the child input', () => {
|
|
74
|
-
const component = render(
|
|
75
|
-
|
|
76
|
-
)
|
|
77
|
-
expect(component.find('
|
|
78
|
-
|
|
79
|
-
expect(component.find('input').attr('accept')).toEqual('image/jpeg');
|
|
80
|
-
});
|
|
73
|
+
const component = render(<Dropzone className="my-dropzone" accept="image/jpeg" />)
|
|
74
|
+
expect(component.find('.my-dropzone').attr()).not.toContain('accept')
|
|
75
|
+
expect(Object.keys(component.find('input').attr())).toContain('accept')
|
|
76
|
+
expect(component.find('input').attr('accept')).toEqual('image/jpeg')
|
|
77
|
+
})
|
|
81
78
|
|
|
82
79
|
it('applies the name prop to the child input', () => {
|
|
83
|
-
const component = render(
|
|
84
|
-
|
|
85
|
-
)
|
|
86
|
-
expect(component.find('
|
|
87
|
-
|
|
88
|
-
expect(component.find('input').attr('name')).toEqual('test-file-input');
|
|
89
|
-
});
|
|
80
|
+
const component = render(<Dropzone className="my-dropzone" name="test-file-input" />)
|
|
81
|
+
expect(component.find('.my-dropzone').attr()).not.toContain('name')
|
|
82
|
+
expect(Object.keys(component.find('input').attr())).toContain('name')
|
|
83
|
+
expect(component.find('input').attr('name')).toEqual('test-file-input')
|
|
84
|
+
})
|
|
90
85
|
|
|
91
86
|
it('should render children function', () => {
|
|
92
|
-
const content = <p>some content</p
|
|
87
|
+
const content = <p>some content</p>
|
|
93
88
|
const dropzone = mount(
|
|
94
89
|
<Dropzone>
|
|
95
90
|
{content}
|
|
96
91
|
</Dropzone>
|
|
97
|
-
)
|
|
92
|
+
)
|
|
98
93
|
const dropzoneWithFunction = mount(
|
|
99
94
|
<Dropzone>
|
|
100
95
|
{() => content}
|
|
101
96
|
</Dropzone>
|
|
102
|
-
)
|
|
103
|
-
expect(dropzoneWithFunction.html()).toEqual(dropzone.html())
|
|
104
|
-
})
|
|
105
|
-
})
|
|
97
|
+
)
|
|
98
|
+
expect(dropzoneWithFunction.html()).toEqual(dropzone.html())
|
|
99
|
+
})
|
|
100
|
+
})
|
|
106
101
|
|
|
107
102
|
describe('document drop protection', () => {
|
|
108
|
-
let dropzone
|
|
109
|
-
let addEventCalls
|
|
110
|
-
let savedAddEventListener
|
|
111
|
-
let savedRemoveEventListener
|
|
103
|
+
let dropzone
|
|
104
|
+
let addEventCalls
|
|
105
|
+
let savedAddEventListener
|
|
106
|
+
let savedRemoveEventListener
|
|
112
107
|
|
|
113
108
|
beforeEach(() => {
|
|
114
|
-
savedAddEventListener = document.addEventListener
|
|
115
|
-
savedRemoveEventListener = document.removeEventListener
|
|
116
|
-
document.addEventListener = spy()
|
|
117
|
-
document.removeEventListener = spy()
|
|
118
|
-
})
|
|
109
|
+
savedAddEventListener = document.addEventListener
|
|
110
|
+
savedRemoveEventListener = document.removeEventListener
|
|
111
|
+
document.addEventListener = spy()
|
|
112
|
+
document.removeEventListener = spy()
|
|
113
|
+
})
|
|
119
114
|
|
|
120
115
|
afterEach(() => {
|
|
121
|
-
document.addEventListener = savedAddEventListener
|
|
122
|
-
document.removeEventListener = savedRemoveEventListener
|
|
123
|
-
})
|
|
116
|
+
document.addEventListener = savedAddEventListener
|
|
117
|
+
document.removeEventListener = savedRemoveEventListener
|
|
118
|
+
})
|
|
124
119
|
|
|
125
120
|
// Collect the list of addEventListener/removeEventListener spy calls into an object keyed by event name.
|
|
126
121
|
function collectEventListenerCalls(calls) {
|
|
127
122
|
return calls.reduce((acc, [eventName, ...rest]) => {
|
|
128
|
-
acc[eventName] = rest
|
|
129
|
-
return acc
|
|
130
|
-
}, {})
|
|
123
|
+
acc[eventName] = rest // eslint-disable-line no-param-reassign
|
|
124
|
+
return acc
|
|
125
|
+
}, {})
|
|
131
126
|
}
|
|
132
127
|
|
|
133
128
|
it('installs hooks to prevent stray drops from taking over the browser window', () => {
|
|
134
|
-
dropzone = mount(<Dropzone><p>Content</p></Dropzone>)
|
|
135
|
-
expect(dropzone.html()).toMatchSnapshot()
|
|
136
|
-
expect(document.addEventListener.callCount).toEqual(2)
|
|
137
|
-
addEventCalls = collectEventListenerCalls(document.addEventListener.args)
|
|
138
|
-
Object.keys(addEventCalls).forEach(
|
|
139
|
-
expect(addEventCalls[eventName][0]).toBeDefined()
|
|
140
|
-
expect(addEventCalls[eventName][1]).toBe(false)
|
|
141
|
-
})
|
|
142
|
-
})
|
|
129
|
+
dropzone = mount(<Dropzone><p>Content</p></Dropzone>)
|
|
130
|
+
expect(dropzone.html()).toMatchSnapshot()
|
|
131
|
+
expect(document.addEventListener.callCount).toEqual(2)
|
|
132
|
+
addEventCalls = collectEventListenerCalls(document.addEventListener.args)
|
|
133
|
+
Object.keys(addEventCalls).forEach(eventName => {
|
|
134
|
+
expect(addEventCalls[eventName][0]).toBeDefined()
|
|
135
|
+
expect(addEventCalls[eventName][1]).toBe(false)
|
|
136
|
+
})
|
|
137
|
+
})
|
|
143
138
|
|
|
144
139
|
it('terminates drags and drops on elements outside our dropzone', () => {
|
|
145
|
-
const event = { preventDefault: spy() }
|
|
146
|
-
Dropzone.onDocumentDragOver(event)
|
|
147
|
-
expect(event.preventDefault.callCount).toEqual(1)
|
|
148
|
-
event.preventDefault.reset()
|
|
140
|
+
const event = { preventDefault: spy() }
|
|
141
|
+
Dropzone.onDocumentDragOver(event)
|
|
142
|
+
expect(event.preventDefault.callCount).toEqual(1)
|
|
143
|
+
event.preventDefault.reset()
|
|
149
144
|
|
|
150
|
-
dropzone.getNode().onDocumentDrop(event)
|
|
151
|
-
expect(event.preventDefault.callCount).toEqual(1)
|
|
152
|
-
})
|
|
145
|
+
dropzone.getNode().onDocumentDrop(event)
|
|
146
|
+
expect(event.preventDefault.callCount).toEqual(1)
|
|
147
|
+
})
|
|
153
148
|
|
|
154
149
|
it('permits drags and drops on elements inside our dropzone', () => {
|
|
155
150
|
const instanceEvent = {
|
|
156
151
|
preventDefault: spy(),
|
|
157
152
|
target: dropzone.getDOMNode()
|
|
158
|
-
}
|
|
159
|
-
dropzone.getNode().onDocumentDrop(instanceEvent)
|
|
160
|
-
expect(instanceEvent.preventDefault.callCount).toEqual(0)
|
|
161
|
-
})
|
|
153
|
+
}
|
|
154
|
+
dropzone.getNode().onDocumentDrop(instanceEvent)
|
|
155
|
+
expect(instanceEvent.preventDefault.callCount).toEqual(0)
|
|
156
|
+
})
|
|
162
157
|
|
|
163
158
|
it('removes document hooks when unmounted', () => {
|
|
164
|
-
dropzone.unmount()
|
|
165
|
-
expect(document.removeEventListener.callCount).toEqual(2)
|
|
166
|
-
const removeEventCalls = collectEventListenerCalls(document.removeEventListener.args)
|
|
167
|
-
Object.keys(addEventCalls).forEach(
|
|
168
|
-
expect(removeEventCalls[eventName][0]).toEqual(addEventCalls[eventName][0])
|
|
169
|
-
})
|
|
170
|
-
})
|
|
159
|
+
dropzone.unmount()
|
|
160
|
+
expect(document.removeEventListener.callCount).toEqual(2)
|
|
161
|
+
const removeEventCalls = collectEventListenerCalls(document.removeEventListener.args)
|
|
162
|
+
Object.keys(addEventCalls).forEach(eventName => {
|
|
163
|
+
expect(removeEventCalls[eventName][0]).toEqual(addEventCalls[eventName][0])
|
|
164
|
+
})
|
|
165
|
+
})
|
|
171
166
|
|
|
172
167
|
it('does not prevent stray drops when preventDropOnDocument is false', () => {
|
|
173
|
-
dropzone = mount(<Dropzone preventDropOnDocument={false} />)
|
|
174
|
-
expect(dropzone.html()).toMatchSnapshot()
|
|
175
|
-
expect(document.addEventListener.callCount).toEqual(0)
|
|
168
|
+
dropzone = mount(<Dropzone preventDropOnDocument={false} />)
|
|
169
|
+
expect(dropzone.html()).toMatchSnapshot()
|
|
170
|
+
expect(document.addEventListener.callCount).toEqual(0)
|
|
176
171
|
|
|
177
|
-
dropzone.unmount()
|
|
178
|
-
expect(document.removeEventListener.callCount).toEqual(0)
|
|
179
|
-
})
|
|
180
|
-
})
|
|
172
|
+
dropzone.unmount()
|
|
173
|
+
expect(document.removeEventListener.callCount).toEqual(0)
|
|
174
|
+
})
|
|
175
|
+
})
|
|
181
176
|
|
|
182
177
|
describe('onClick', () => {
|
|
183
|
-
it('should call `open` method',
|
|
184
|
-
const dropzone = mount(
|
|
185
|
-
|
|
186
|
-
)
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
178
|
+
it('should call `open` method', done => {
|
|
179
|
+
const dropzone = mount(<Dropzone />)
|
|
180
|
+
spy(dropzone.instance(), 'open')
|
|
181
|
+
dropzone.simulate('click')
|
|
182
|
+
setTimeout(() => {
|
|
183
|
+
expect(dropzone.instance().open.callCount).toEqual(1)
|
|
184
|
+
done()
|
|
185
|
+
}, 0)
|
|
186
|
+
})
|
|
191
187
|
|
|
192
188
|
it('should not call `open` if disableClick prop is true', () => {
|
|
193
|
-
const dropzone = mount(
|
|
194
|
-
|
|
195
|
-
)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
});
|
|
189
|
+
const dropzone = mount(<Dropzone disableClick />)
|
|
190
|
+
spy(dropzone.instance(), 'open')
|
|
191
|
+
dropzone.simulate('click')
|
|
192
|
+
expect(dropzone.instance().open.callCount).toEqual(0)
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
it('should call `onClick` callback if provided', done => {
|
|
196
|
+
const clickSpy = spy()
|
|
197
|
+
const dropzone = mount(<Dropzone onClick={clickSpy} />)
|
|
198
|
+
spy(dropzone.instance(), 'open')
|
|
199
|
+
dropzone.simulate('click')
|
|
200
|
+
setTimeout(() => {
|
|
201
|
+
expect(dropzone.instance().open.callCount).toEqual(1)
|
|
202
|
+
expect(clickSpy.callCount).toEqual(1)
|
|
203
|
+
done()
|
|
204
|
+
}, 0)
|
|
205
|
+
})
|
|
211
206
|
|
|
212
207
|
it('should reset the value of input', () => {
|
|
213
|
-
const dropzone = mount(
|
|
214
|
-
|
|
215
|
-
)
|
|
216
|
-
|
|
217
|
-
expect(dropzone.render().find('input').attr('value'
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
)
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
});
|
|
208
|
+
const dropzone = mount(<Dropzone />)
|
|
209
|
+
expect(dropzone.render().find('input').attr('value')).toBeUndefined()
|
|
210
|
+
expect(dropzone.render().find('input').attr('value', 10)).not.toBeUndefined()
|
|
211
|
+
dropzone.simulate('click')
|
|
212
|
+
expect(dropzone.render().find('input').attr('value')).toBeUndefined()
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it('should trigger click even on the input', done => {
|
|
216
|
+
const dropzone = mount(<Dropzone />)
|
|
217
|
+
const clickSpy = spy(dropzone.instance().fileInputEl, 'click')
|
|
218
|
+
dropzone.simulate('click')
|
|
219
|
+
dropzone.simulate('click')
|
|
220
|
+
setTimeout(() => {
|
|
221
|
+
expect(clickSpy.callCount).toEqual(2)
|
|
222
|
+
done()
|
|
223
|
+
}, 0)
|
|
224
|
+
})
|
|
231
225
|
|
|
232
226
|
it('should not invoke onClick on the wrapper', () => {
|
|
233
|
-
const onClickOuterSpy = spy()
|
|
234
|
-
const onClickInnerSpy = spy()
|
|
227
|
+
const onClickOuterSpy = spy()
|
|
228
|
+
const onClickInnerSpy = spy()
|
|
235
229
|
const component = mount(
|
|
236
230
|
<div onClick={onClickOuterSpy}>
|
|
237
231
|
<Dropzone onClick={onClickInnerSpy} />
|
|
238
232
|
</div>
|
|
239
|
-
)
|
|
233
|
+
)
|
|
240
234
|
|
|
241
|
-
component.simulate('click')
|
|
242
|
-
expect(onClickOuterSpy.callCount).toEqual(1)
|
|
243
|
-
expect(onClickInnerSpy.callCount).toEqual(0)
|
|
235
|
+
component.simulate('click')
|
|
236
|
+
expect(onClickOuterSpy.callCount).toEqual(1)
|
|
237
|
+
expect(onClickInnerSpy.callCount).toEqual(0)
|
|
244
238
|
|
|
245
|
-
onClickOuterSpy.reset()
|
|
246
|
-
onClickInnerSpy.reset()
|
|
239
|
+
onClickOuterSpy.reset()
|
|
240
|
+
onClickInnerSpy.reset()
|
|
247
241
|
|
|
248
|
-
component.find('Dropzone').simulate('click')
|
|
249
|
-
expect(onClickOuterSpy.callCount).toEqual(0)
|
|
250
|
-
expect(onClickInnerSpy.callCount).toEqual(1)
|
|
251
|
-
})
|
|
242
|
+
component.find('Dropzone').simulate('click')
|
|
243
|
+
expect(onClickOuterSpy.callCount).toEqual(0)
|
|
244
|
+
expect(onClickInnerSpy.callCount).toEqual(1)
|
|
245
|
+
})
|
|
252
246
|
|
|
253
247
|
it('should invoke onClick on the wrapper if disableClick is set', () => {
|
|
254
|
-
const onClickOuterSpy = spy()
|
|
248
|
+
const onClickOuterSpy = spy()
|
|
255
249
|
const component = mount(
|
|
256
250
|
<div onClick={onClickOuterSpy}>
|
|
257
251
|
<Dropzone disableClick />
|
|
258
252
|
</div>
|
|
259
|
-
)
|
|
253
|
+
)
|
|
260
254
|
|
|
261
|
-
component.find('Dropzone').simulate('click')
|
|
262
|
-
expect(onClickOuterSpy.callCount).toEqual(1)
|
|
263
|
-
})
|
|
264
|
-
|
|
255
|
+
component.find('Dropzone').simulate('click')
|
|
256
|
+
expect(onClickOuterSpy.callCount).toEqual(1)
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
it('should invoke inputProps onClick if provided', done => {
|
|
260
|
+
const inputPropsClickSpy = spy()
|
|
261
|
+
const component = mount(<Dropzone inputProps={{ onClick: inputPropsClickSpy }} />)
|
|
262
|
+
|
|
263
|
+
component.find('Dropzone').simulate('click')
|
|
264
|
+
setTimeout(() => {
|
|
265
|
+
expect(inputPropsClickSpy.callCount).toEqual(1)
|
|
266
|
+
done()
|
|
267
|
+
}, 0)
|
|
268
|
+
})
|
|
269
|
+
})
|
|
265
270
|
|
|
266
271
|
describe('drag-n-drop', () => {
|
|
267
272
|
it('should override onDrag* methods', () => {
|
|
268
|
-
const dragStartSpy = spy()
|
|
269
|
-
const dragEnterSpy = spy()
|
|
270
|
-
const dragOverSpy = spy()
|
|
271
|
-
const dragLeaveSpy = spy()
|
|
273
|
+
const dragStartSpy = spy()
|
|
274
|
+
const dragEnterSpy = spy()
|
|
275
|
+
const dragOverSpy = spy()
|
|
276
|
+
const dragLeaveSpy = spy()
|
|
272
277
|
const component = mount(
|
|
273
278
|
<Dropzone
|
|
274
279
|
onDragStart={dragStartSpy}
|
|
@@ -276,168 +281,197 @@ describe('Dropzone', () => {
|
|
|
276
281
|
onDragOver={dragOverSpy}
|
|
277
282
|
onDragLeave={dragLeaveSpy}
|
|
278
283
|
/>
|
|
279
|
-
)
|
|
280
|
-
component.simulate('dragStart')
|
|
281
|
-
component.simulate('dragEnter', { dataTransfer: { items: files } })
|
|
282
|
-
component.simulate('dragOver', { dataTransfer: { items: files } })
|
|
283
|
-
component.simulate('dragLeave', { dataTransfer: { items: files } })
|
|
284
|
-
expect(dragStartSpy.callCount).toEqual(1)
|
|
285
|
-
expect(dragEnterSpy.callCount).toEqual(1)
|
|
286
|
-
expect(dragOverSpy.callCount).toEqual(1)
|
|
287
|
-
expect(dragLeaveSpy.callCount).toEqual(1)
|
|
288
|
-
})
|
|
284
|
+
)
|
|
285
|
+
component.simulate('dragStart')
|
|
286
|
+
component.simulate('dragEnter', { dataTransfer: { items: files } })
|
|
287
|
+
component.simulate('dragOver', { dataTransfer: { items: files } })
|
|
288
|
+
component.simulate('dragLeave', { dataTransfer: { items: files } })
|
|
289
|
+
expect(dragStartSpy.callCount).toEqual(1)
|
|
290
|
+
expect(dragEnterSpy.callCount).toEqual(1)
|
|
291
|
+
expect(dragOverSpy.callCount).toEqual(1)
|
|
292
|
+
expect(dragLeaveSpy.callCount).toEqual(1)
|
|
293
|
+
})
|
|
289
294
|
|
|
290
295
|
it('should guard dropEffect in onDragOver for IE', () => {
|
|
291
|
-
const dragStartSpy = spy()
|
|
292
|
-
const dragEnterSpy = spy()
|
|
293
|
-
const dragLeaveSpy = spy()
|
|
296
|
+
const dragStartSpy = spy()
|
|
297
|
+
const dragEnterSpy = spy()
|
|
298
|
+
const dragLeaveSpy = spy()
|
|
294
299
|
const component = mount(
|
|
295
300
|
<Dropzone
|
|
296
301
|
onDragStart={dragStartSpy}
|
|
297
302
|
onDragEnter={dragEnterSpy}
|
|
298
303
|
onDragLeave={dragLeaveSpy}
|
|
299
304
|
/>
|
|
300
|
-
)
|
|
305
|
+
)
|
|
301
306
|
|
|
302
307
|
// Using Proxy we'll emulate IE throwing when setting dataTransfer.dropEffect
|
|
303
|
-
const eventProxy = new Proxy(
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
308
|
+
const eventProxy = new Proxy(
|
|
309
|
+
{},
|
|
310
|
+
{
|
|
311
|
+
get: (target, prop) => {
|
|
312
|
+
switch (prop) {
|
|
313
|
+
case 'dataTransfer':
|
|
314
|
+
throw new Error('IE does not support rrror')
|
|
315
|
+
default:
|
|
316
|
+
return function noop() {}
|
|
317
|
+
}
|
|
310
318
|
}
|
|
311
319
|
}
|
|
312
|
-
|
|
320
|
+
)
|
|
313
321
|
|
|
314
322
|
// And using then we'll call the onDragOver with the proxy instead of event
|
|
315
323
|
const dragOverSpy = stub(
|
|
316
324
|
component.instance(),
|
|
317
325
|
'onDragOver',
|
|
318
326
|
component.instance().onDragOver(eventProxy)
|
|
319
|
-
)
|
|
320
|
-
|
|
321
|
-
component.simulate('dragStart', { dataTransfer: { items: files } })
|
|
322
|
-
component.simulate('dragEnter', { dataTransfer: { items: files } })
|
|
323
|
-
component.simulate('dragOver', { dataTransfer: { items: files } })
|
|
324
|
-
component.simulate('dragLeave', { dataTransfer: { items: files } })
|
|
325
|
-
expect(dragStartSpy.callCount).toEqual(1)
|
|
326
|
-
expect(dragEnterSpy.callCount).toEqual(1)
|
|
327
|
-
expect(dragLeaveSpy.callCount).toEqual(1)
|
|
327
|
+
)
|
|
328
|
+
|
|
329
|
+
component.simulate('dragStart', { dataTransfer: { items: files } })
|
|
330
|
+
component.simulate('dragEnter', { dataTransfer: { items: files } })
|
|
331
|
+
component.simulate('dragOver', { dataTransfer: { items: files } })
|
|
332
|
+
component.simulate('dragLeave', { dataTransfer: { items: files } })
|
|
333
|
+
expect(dragStartSpy.callCount).toEqual(1)
|
|
334
|
+
expect(dragEnterSpy.callCount).toEqual(1)
|
|
335
|
+
expect(dragLeaveSpy.callCount).toEqual(1)
|
|
328
336
|
// It should not throw the error
|
|
329
|
-
expect(dragOverSpy).not.toThrow()
|
|
330
|
-
dragOverSpy.restore()
|
|
331
|
-
})
|
|
337
|
+
expect(dragOverSpy).not.toThrow()
|
|
338
|
+
dragOverSpy.restore()
|
|
339
|
+
})
|
|
332
340
|
|
|
333
341
|
it('should set proper dragActive state on dragEnter', () => {
|
|
334
342
|
const dropzone = mount(
|
|
335
|
-
<Dropzone
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
343
|
+
<Dropzone>
|
|
344
|
+
{props => <DummyChildComponent {...props} />}
|
|
345
|
+
</Dropzone>
|
|
346
|
+
)
|
|
347
|
+
const child = dropzone.find(DummyChildComponent)
|
|
348
|
+
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
349
|
+
expect(child).toHaveProp('isDragActive', true)
|
|
350
|
+
expect(child).toHaveProp('isDragReject', false)
|
|
351
|
+
})
|
|
341
352
|
|
|
342
353
|
it('should set proper dragReject state on dragEnter', () => {
|
|
343
354
|
const dropzone = mount(
|
|
344
|
-
<Dropzone accept="image/*"
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
355
|
+
<Dropzone accept="image/*">
|
|
356
|
+
{props => <DummyChildComponent {...props} />}
|
|
357
|
+
</Dropzone>
|
|
358
|
+
)
|
|
359
|
+
const child = dropzone.find(DummyChildComponent)
|
|
360
|
+
dropzone.simulate('dragEnter', { dataTransfer: { files: files.concat(images) } })
|
|
361
|
+
expect(child).toHaveProp('isDragActive', false)
|
|
362
|
+
expect(child).toHaveProp('isDragReject', true)
|
|
363
|
+
})
|
|
350
364
|
|
|
351
365
|
it('should set proper dragActive state if multiple is false', () => {
|
|
352
366
|
const dropzone = mount(
|
|
353
|
-
<Dropzone
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
)
|
|
358
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
359
|
-
expect(
|
|
360
|
-
expect(
|
|
361
|
-
})
|
|
367
|
+
<Dropzone accept="image/*" multiple={false}>
|
|
368
|
+
{props => <DummyChildComponent {...props} />}
|
|
369
|
+
</Dropzone>
|
|
370
|
+
)
|
|
371
|
+
const child = dropzone.find(DummyChildComponent)
|
|
372
|
+
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
373
|
+
expect(child).toHaveProp('isDragActive', false)
|
|
374
|
+
expect(child).toHaveProp('isDragReject', true)
|
|
375
|
+
})
|
|
362
376
|
|
|
363
377
|
it('should set proper dragActive state if multiple is false', () => {
|
|
364
378
|
const dropzone = mount(
|
|
365
|
-
<Dropzone
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
)
|
|
370
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
371
|
-
expect(
|
|
372
|
-
expect(
|
|
373
|
-
})
|
|
379
|
+
<Dropzone accept="image/*" multiple={false}>
|
|
380
|
+
{props => <DummyChildComponent {...props} />}
|
|
381
|
+
</Dropzone>
|
|
382
|
+
)
|
|
383
|
+
const child = dropzone.find(DummyChildComponent)
|
|
384
|
+
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
385
|
+
expect(child).toHaveProp('isDragActive', true)
|
|
386
|
+
expect(child).toHaveProp('isDragReject', true)
|
|
387
|
+
})
|
|
388
|
+
|
|
389
|
+
it('should set proper dragActive state if accept prop changes mid-drag', () => {
|
|
390
|
+
const dropzone = mount(
|
|
391
|
+
<Dropzone accept="image/*">
|
|
392
|
+
{props => <DummyChildComponent {...props} />}
|
|
393
|
+
</Dropzone>
|
|
394
|
+
)
|
|
395
|
+
const child = dropzone.find(DummyChildComponent)
|
|
396
|
+
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
397
|
+
expect(child).toHaveProp('isDragActive', true)
|
|
398
|
+
expect(child).toHaveProp('isDragReject', false)
|
|
399
|
+
|
|
400
|
+
dropzone.setProps({ accept: 'text/*' })
|
|
401
|
+
expect(child).toHaveProp('isDragActive', false)
|
|
402
|
+
expect(child).toHaveProp('isDragReject', true)
|
|
403
|
+
})
|
|
374
404
|
|
|
375
405
|
it('should expose state to children', () => {
|
|
376
406
|
const dropzone = mount(
|
|
377
407
|
<Dropzone accept="image/*">
|
|
378
408
|
{({ isDragActive, isDragReject }) => {
|
|
379
409
|
if (isDragReject) {
|
|
380
|
-
return 'Rejected'
|
|
410
|
+
return 'Rejected'
|
|
381
411
|
}
|
|
382
412
|
if (isDragActive) {
|
|
383
|
-
return 'Active'
|
|
413
|
+
return 'Active'
|
|
384
414
|
}
|
|
385
|
-
return 'Empty'
|
|
415
|
+
return 'Empty'
|
|
386
416
|
}}
|
|
387
417
|
</Dropzone>
|
|
388
|
-
)
|
|
389
|
-
expect(dropzone.text()).toEqual('Empty')
|
|
390
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
391
|
-
expect(dropzone.text()).toEqual('Active')
|
|
392
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
393
|
-
expect(dropzone.text()).toEqual('Rejected')
|
|
394
|
-
})
|
|
418
|
+
)
|
|
419
|
+
expect(dropzone.text()).toEqual('Empty')
|
|
420
|
+
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
421
|
+
expect(dropzone.text()).toEqual('Active')
|
|
422
|
+
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
423
|
+
expect(dropzone.text()).toEqual('Rejected')
|
|
424
|
+
})
|
|
395
425
|
|
|
396
426
|
it('should reset the dragActive/dragReject state when leaving after a child goes away', () => {
|
|
397
|
-
const DragActiveComponent = () => <p>Active</p
|
|
398
|
-
const ChildComponent = () => <p>Child component content</p
|
|
427
|
+
const DragActiveComponent = () => <p>Active</p>
|
|
428
|
+
const ChildComponent = () => <p>Child component content</p>
|
|
399
429
|
const dropzone = mount(
|
|
400
430
|
<Dropzone>
|
|
401
431
|
{({ isDragActive, isDragReject }) => {
|
|
402
432
|
if (isDragReject) {
|
|
403
|
-
return 'Rejected'
|
|
433
|
+
return 'Rejected'
|
|
404
434
|
}
|
|
405
435
|
if (isDragActive) {
|
|
406
|
-
return <DragActiveComponent
|
|
436
|
+
return <DragActiveComponent isDragActive={isDragActive} isDragReject={isDragReject} />
|
|
407
437
|
}
|
|
408
|
-
return <ChildComponent
|
|
438
|
+
return <ChildComponent isDragActive={isDragActive} isDragReject={isDragReject} />
|
|
409
439
|
}}
|
|
410
440
|
</Dropzone>
|
|
411
|
-
)
|
|
412
|
-
dropzone.find(ChildComponent)
|
|
413
|
-
|
|
441
|
+
)
|
|
442
|
+
const child = dropzone.find(ChildComponent)
|
|
443
|
+
child.simulate('dragEnter', { dataTransfer: { files } })
|
|
444
|
+
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
414
445
|
// make sure we handle any duplicate dragEnter events that the browser may send us
|
|
415
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
416
|
-
|
|
417
|
-
expect(
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
446
|
+
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
447
|
+
const dragActiveChild = dropzone.find(DragActiveComponent)
|
|
448
|
+
expect(dragActiveChild).toBePresent()
|
|
449
|
+
expect(dragActiveChild).toHaveProp('isDragActive', true)
|
|
450
|
+
expect(dragActiveChild).toHaveProp('isDragReject', false)
|
|
451
|
+
|
|
452
|
+
dropzone.simulate('dragLeave', { dataTransfer: { files } })
|
|
453
|
+
expect(dropzone.find(DragActiveComponent)).toBeEmpty()
|
|
454
|
+
expect(child).toHaveProp('isDragActive', false)
|
|
455
|
+
expect(child).toHaveProp('isDragReject', false)
|
|
456
|
+
})
|
|
457
|
+
})
|
|
424
458
|
|
|
425
459
|
describe('onDrop', () => {
|
|
426
|
-
let dropSpy
|
|
427
|
-
let dropAcceptedSpy
|
|
428
|
-
let dropRejectedSpy
|
|
460
|
+
let dropSpy
|
|
461
|
+
let dropAcceptedSpy
|
|
462
|
+
let dropRejectedSpy
|
|
429
463
|
|
|
430
464
|
beforeEach(() => {
|
|
431
|
-
dropSpy = spy()
|
|
432
|
-
dropAcceptedSpy = spy()
|
|
433
|
-
dropRejectedSpy = spy()
|
|
434
|
-
})
|
|
465
|
+
dropSpy = spy()
|
|
466
|
+
dropAcceptedSpy = spy()
|
|
467
|
+
dropRejectedSpy = spy()
|
|
468
|
+
})
|
|
435
469
|
|
|
436
470
|
afterEach(() => {
|
|
437
|
-
dropSpy.reset()
|
|
438
|
-
dropAcceptedSpy.reset()
|
|
439
|
-
dropRejectedSpy.reset()
|
|
440
|
-
})
|
|
471
|
+
dropSpy.reset()
|
|
472
|
+
dropAcceptedSpy.reset()
|
|
473
|
+
dropRejectedSpy.reset()
|
|
474
|
+
})
|
|
441
475
|
|
|
442
476
|
it('should reset the dragActive/dragReject state', () => {
|
|
443
477
|
const dropzone = mount(
|
|
@@ -445,64 +479,56 @@ describe('Dropzone', () => {
|
|
|
445
479
|
onDrop={dropSpy}
|
|
446
480
|
onDropAccepted={dropAcceptedSpy}
|
|
447
481
|
onDropRejected={dropRejectedSpy}
|
|
448
|
-
/>
|
|
449
|
-
);
|
|
450
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files } });
|
|
451
|
-
expect(dropzone.state().isDragActive).toEqual(true);
|
|
452
|
-
expect(dropzone.state().isDragReject).toEqual(false);
|
|
453
|
-
dropzone.simulate('drop', { dataTransfer: { files } });
|
|
454
|
-
expect(dropzone.state().isDragActive).toEqual(false);
|
|
455
|
-
expect(dropzone.state().isDragReject).toEqual(false);
|
|
456
|
-
});
|
|
457
|
-
|
|
458
|
-
it('should expose acceptedFiles and rejectedFiles to children', () => {
|
|
459
|
-
const dropzone = mount(
|
|
460
|
-
<Dropzone
|
|
461
|
-
accept="image/*"
|
|
462
|
-
multiple={false}
|
|
463
482
|
>
|
|
464
|
-
{
|
|
483
|
+
{props => <DummyChildComponent {...props} />}
|
|
465
484
|
</Dropzone>
|
|
466
|
-
)
|
|
467
|
-
dropzone.
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
expect(
|
|
471
|
-
|
|
485
|
+
)
|
|
486
|
+
const child = dropzone.find(DummyChildComponent)
|
|
487
|
+
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
488
|
+
expect(child).toHaveProp('isDragActive', true)
|
|
489
|
+
expect(child).toHaveProp('isDragReject', false)
|
|
490
|
+
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
491
|
+
expect(child).toHaveProp('isDragActive', false)
|
|
492
|
+
expect(child).toHaveProp('isDragReject', false)
|
|
493
|
+
})
|
|
494
|
+
|
|
495
|
+
it('should add valid files to rejected files on a multple drop when multiple false', () => {
|
|
496
|
+
const dropzone = mount(<Dropzone accept="image/*" onDrop={dropSpy} multiple={false} />)
|
|
497
|
+
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
498
|
+
const rejected = dropSpy.firstCall.args[0]
|
|
499
|
+
expect(rejected.length).toEqual(1)
|
|
500
|
+
})
|
|
501
|
+
|
|
502
|
+
it('should add invalid files to rejected when multiple is false', () => {
|
|
503
|
+
const dropzone = mount(<Dropzone accept="image/*" onDrop={dropSpy} multiple={false} />)
|
|
504
|
+
dropzone.simulate('drop', { dataTransfer: { files: images.concat(files) } })
|
|
505
|
+
const rejected = dropSpy.firstCall.args[1]
|
|
506
|
+
expect(rejected.length).toEqual(2)
|
|
507
|
+
})
|
|
508
|
+
|
|
509
|
+
it('should allow single files to be dropped if multiple is false', () => {
|
|
510
|
+
const dropzone = mount(<Dropzone accept="image/*" onDrop={dropSpy} multiple={false} />)
|
|
511
|
+
|
|
512
|
+
dropzone.simulate('drop', { dataTransfer: { files: [images[0]] } })
|
|
513
|
+
const [accepted, rejected] = dropSpy.firstCall.args
|
|
514
|
+
expect(accepted.length).toEqual(1)
|
|
515
|
+
expect(rejected.length).toEqual(0)
|
|
516
|
+
})
|
|
472
517
|
|
|
473
518
|
it('should take all dropped files if multiple is true', () => {
|
|
474
|
-
const dropzone = mount(
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } });
|
|
481
|
-
expect(dropSpy.firstCall.args[0]).toHaveLength(2);
|
|
482
|
-
expect(dropSpy.firstCall.args[0][0].name).toEqual(images[0].name);
|
|
483
|
-
expect(dropSpy.firstCall.args[0][1].name).toEqual(images[1].name);
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
it('should take first file out of dropped files if multiple is false', () => {
|
|
487
|
-
const dropzone = mount(
|
|
488
|
-
<Dropzone
|
|
489
|
-
onDrop={dropSpy}
|
|
490
|
-
multiple={false}
|
|
491
|
-
/>
|
|
492
|
-
);
|
|
493
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } });
|
|
494
|
-
expect(dropSpy.firstCall.args[0]).toHaveLength(1);
|
|
495
|
-
expect(dropSpy.firstCall.args[0][0].name).toEqual(images[0].name);
|
|
496
|
-
});
|
|
519
|
+
const dropzone = mount(<Dropzone onDrop={dropSpy} multiple />)
|
|
520
|
+
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
521
|
+
expect(dropSpy.firstCall.args[0]).toHaveLength(2)
|
|
522
|
+
expect(dropSpy.firstCall.args[0][0].name).toEqual(images[0].name)
|
|
523
|
+
expect(dropSpy.firstCall.args[0][1].name).toEqual(images[1].name)
|
|
524
|
+
})
|
|
497
525
|
|
|
498
526
|
it('should set this.isFileDialogActive to false', () => {
|
|
499
|
-
const dropzone = mount(
|
|
500
|
-
|
|
501
|
-
)
|
|
502
|
-
dropzone.instance().isFileDialogActive
|
|
503
|
-
|
|
504
|
-
expect(dropzone.instance().isFileDialogActive).toEqual(false);
|
|
505
|
-
});
|
|
527
|
+
const dropzone = mount(<Dropzone />)
|
|
528
|
+
dropzone.instance().isFileDialogActive = true
|
|
529
|
+
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
530
|
+
expect(dropzone.instance().isFileDialogActive).toEqual(false)
|
|
531
|
+
})
|
|
506
532
|
|
|
507
533
|
it('should always call onDrop callback with accepted and rejected arguments', () => {
|
|
508
534
|
const dropzone = mount(
|
|
@@ -512,17 +538,17 @@ describe('Dropzone', () => {
|
|
|
512
538
|
onDropRejected={dropRejectedSpy}
|
|
513
539
|
accept="image/*"
|
|
514
540
|
/>
|
|
515
|
-
)
|
|
516
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
517
|
-
expect(dropSpy.callCount).toEqual(1)
|
|
518
|
-
expect(dropSpy.firstCall.args[0]).toEqual([], [...files])
|
|
519
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
520
|
-
expect(dropSpy.callCount).toEqual(2)
|
|
521
|
-
expect(dropSpy.lastCall.args[0]).toEqual([...images], [])
|
|
522
|
-
dropzone.simulate('drop', { dataTransfer: { files: files.concat(images) } })
|
|
523
|
-
expect(dropSpy.callCount).toEqual(3)
|
|
524
|
-
expect(dropSpy.lastCall.args[0]).toEqual([...images], [...files])
|
|
525
|
-
})
|
|
541
|
+
)
|
|
542
|
+
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
543
|
+
expect(dropSpy.callCount).toEqual(1)
|
|
544
|
+
expect(dropSpy.firstCall.args[0]).toEqual([], [...files])
|
|
545
|
+
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
546
|
+
expect(dropSpy.callCount).toEqual(2)
|
|
547
|
+
expect(dropSpy.lastCall.args[0]).toEqual([...images], [])
|
|
548
|
+
dropzone.simulate('drop', { dataTransfer: { files: files.concat(images) } })
|
|
549
|
+
expect(dropSpy.callCount).toEqual(3)
|
|
550
|
+
expect(dropSpy.lastCall.args[0]).toEqual([...images], [...files])
|
|
551
|
+
})
|
|
526
552
|
|
|
527
553
|
it('should call onDropAccepted callback if some files were accepted', () => {
|
|
528
554
|
const dropzone = mount(
|
|
@@ -532,16 +558,16 @@ describe('Dropzone', () => {
|
|
|
532
558
|
onDropRejected={dropRejectedSpy}
|
|
533
559
|
accept="image/*"
|
|
534
560
|
/>
|
|
535
|
-
)
|
|
536
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
537
|
-
expect(dropAcceptedSpy.callCount).toEqual(0)
|
|
538
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
539
|
-
expect(dropAcceptedSpy.callCount).toEqual(1)
|
|
540
|
-
expect(dropAcceptedSpy.lastCall.args[0]).toEqual([...images])
|
|
541
|
-
dropzone.simulate('drop', { dataTransfer: { files: files.concat(images) } })
|
|
542
|
-
expect(dropAcceptedSpy.callCount).toEqual(2)
|
|
543
|
-
expect(dropAcceptedSpy.lastCall.args[0]).toEqual([...images])
|
|
544
|
-
})
|
|
561
|
+
)
|
|
562
|
+
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
563
|
+
expect(dropAcceptedSpy.callCount).toEqual(0)
|
|
564
|
+
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
565
|
+
expect(dropAcceptedSpy.callCount).toEqual(1)
|
|
566
|
+
expect(dropAcceptedSpy.lastCall.args[0]).toEqual([...images])
|
|
567
|
+
dropzone.simulate('drop', { dataTransfer: { files: files.concat(images) } })
|
|
568
|
+
expect(dropAcceptedSpy.callCount).toEqual(2)
|
|
569
|
+
expect(dropAcceptedSpy.lastCall.args[0]).toEqual([...images])
|
|
570
|
+
})
|
|
545
571
|
|
|
546
572
|
it('should call onDropRejected callback if some files were rejected', () => {
|
|
547
573
|
const dropzone = mount(
|
|
@@ -551,16 +577,16 @@ describe('Dropzone', () => {
|
|
|
551
577
|
onDropRejected={dropRejectedSpy}
|
|
552
578
|
accept="image/*"
|
|
553
579
|
/>
|
|
554
|
-
)
|
|
555
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
556
|
-
expect(dropRejectedSpy.callCount).toEqual(1)
|
|
557
|
-
expect(dropRejectedSpy.lastCall.args[0]).toEqual([...files])
|
|
558
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
559
|
-
expect(dropRejectedSpy.callCount).toEqual(1)
|
|
560
|
-
dropzone.simulate('drop', { dataTransfer: { files: files.concat(images) } })
|
|
561
|
-
expect(dropRejectedSpy.callCount).toEqual(2)
|
|
562
|
-
expect(dropRejectedSpy.lastCall.args[0]).toEqual([...files])
|
|
563
|
-
})
|
|
580
|
+
)
|
|
581
|
+
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
582
|
+
expect(dropRejectedSpy.callCount).toEqual(1)
|
|
583
|
+
expect(dropRejectedSpy.lastCall.args[0]).toEqual([...files])
|
|
584
|
+
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
585
|
+
expect(dropRejectedSpy.callCount).toEqual(1)
|
|
586
|
+
dropzone.simulate('drop', { dataTransfer: { files: files.concat(images) } })
|
|
587
|
+
expect(dropRejectedSpy.callCount).toEqual(2)
|
|
588
|
+
expect(dropRejectedSpy.lastCall.args[0]).toEqual([...files])
|
|
589
|
+
})
|
|
564
590
|
|
|
565
591
|
it('applies the accept prop to the dropped files', () => {
|
|
566
592
|
const dropzone = mount(
|
|
@@ -570,15 +596,15 @@ describe('Dropzone', () => {
|
|
|
570
596
|
onDropRejected={dropRejectedSpy}
|
|
571
597
|
accept="image/*"
|
|
572
598
|
/>
|
|
573
|
-
)
|
|
574
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
575
|
-
expect(dropSpy.callCount).toEqual(1)
|
|
576
|
-
expect(dropSpy.firstCall.args[0]).toHaveLength(0)
|
|
577
|
-
expect(dropSpy.firstCall.args[1]).toHaveLength(1)
|
|
578
|
-
expect(dropAcceptedSpy.callCount).toEqual(0)
|
|
579
|
-
expect(dropRejectedSpy.callCount).toEqual(1)
|
|
580
|
-
expect(dropRejectedSpy.firstCall.args[0]).toHaveLength(1)
|
|
581
|
-
})
|
|
599
|
+
)
|
|
600
|
+
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
601
|
+
expect(dropSpy.callCount).toEqual(1)
|
|
602
|
+
expect(dropSpy.firstCall.args[0]).toHaveLength(0)
|
|
603
|
+
expect(dropSpy.firstCall.args[1]).toHaveLength(1)
|
|
604
|
+
expect(dropAcceptedSpy.callCount).toEqual(0)
|
|
605
|
+
expect(dropRejectedSpy.callCount).toEqual(1)
|
|
606
|
+
expect(dropRejectedSpy.firstCall.args[0]).toHaveLength(1)
|
|
607
|
+
})
|
|
582
608
|
|
|
583
609
|
it('applies the accept prop to the dropped images', () => {
|
|
584
610
|
const dropzone = mount(
|
|
@@ -588,16 +614,16 @@ describe('Dropzone', () => {
|
|
|
588
614
|
onDropRejected={dropRejectedSpy}
|
|
589
615
|
accept="image/*"
|
|
590
616
|
/>
|
|
591
|
-
)
|
|
617
|
+
)
|
|
592
618
|
|
|
593
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
594
|
-
expect(dropSpy.callCount).toEqual(1)
|
|
595
|
-
expect(dropSpy.firstCall.args[0]).toHaveLength(2)
|
|
596
|
-
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
597
|
-
expect(dropAcceptedSpy.callCount).toEqual(1)
|
|
598
|
-
expect(dropAcceptedSpy.firstCall.args[0]).toHaveLength(2)
|
|
599
|
-
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
600
|
-
})
|
|
619
|
+
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
620
|
+
expect(dropSpy.callCount).toEqual(1)
|
|
621
|
+
expect(dropSpy.firstCall.args[0]).toHaveLength(2)
|
|
622
|
+
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
623
|
+
expect(dropAcceptedSpy.callCount).toEqual(1)
|
|
624
|
+
expect(dropAcceptedSpy.firstCall.args[0]).toHaveLength(2)
|
|
625
|
+
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
626
|
+
})
|
|
601
627
|
|
|
602
628
|
it('accepts a dropped image when Firefox provides a bogus file type', () => {
|
|
603
629
|
const dropzone = mount(
|
|
@@ -607,21 +633,23 @@ describe('Dropzone', () => {
|
|
|
607
633
|
onDropRejected={dropRejectedSpy}
|
|
608
634
|
accept="image/*"
|
|
609
635
|
/>
|
|
610
|
-
)
|
|
611
|
-
const bogusImages = [
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
expect(dropSpy.
|
|
621
|
-
expect(
|
|
622
|
-
expect(
|
|
623
|
-
expect(
|
|
624
|
-
|
|
636
|
+
)
|
|
637
|
+
const bogusImages = [
|
|
638
|
+
{
|
|
639
|
+
name: 'bogus.gif',
|
|
640
|
+
size: 1234,
|
|
641
|
+
type: 'application/x-moz-file'
|
|
642
|
+
}
|
|
643
|
+
]
|
|
644
|
+
|
|
645
|
+
dropzone.simulate('drop', { dataTransfer: { files: bogusImages } })
|
|
646
|
+
expect(dropSpy.callCount).toEqual(1)
|
|
647
|
+
expect(dropSpy.firstCall.args[0]).toHaveLength(1)
|
|
648
|
+
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
649
|
+
expect(dropAcceptedSpy.callCount).toEqual(1)
|
|
650
|
+
expect(dropAcceptedSpy.firstCall.args[0]).toHaveLength(1)
|
|
651
|
+
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
652
|
+
})
|
|
625
653
|
|
|
626
654
|
it('accepts all dropped files and images when no accept prop is specified', () => {
|
|
627
655
|
const dropzone = mount(
|
|
@@ -630,15 +658,15 @@ describe('Dropzone', () => {
|
|
|
630
658
|
onDropAccepted={dropAcceptedSpy}
|
|
631
659
|
onDropRejected={dropRejectedSpy}
|
|
632
660
|
/>
|
|
633
|
-
)
|
|
634
|
-
dropzone.simulate('drop', { dataTransfer: { files: files.concat(images) } })
|
|
635
|
-
expect(dropSpy.callCount).toEqual(1)
|
|
636
|
-
expect(dropSpy.firstCall.args[0]).toHaveLength(3)
|
|
637
|
-
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
638
|
-
expect(dropAcceptedSpy.callCount).toEqual(1)
|
|
639
|
-
expect(dropAcceptedSpy.firstCall.args[0]).toHaveLength(3)
|
|
640
|
-
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
641
|
-
})
|
|
661
|
+
)
|
|
662
|
+
dropzone.simulate('drop', { dataTransfer: { files: files.concat(images) } })
|
|
663
|
+
expect(dropSpy.callCount).toEqual(1)
|
|
664
|
+
expect(dropSpy.firstCall.args[0]).toHaveLength(3)
|
|
665
|
+
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
666
|
+
expect(dropAcceptedSpy.callCount).toEqual(1)
|
|
667
|
+
expect(dropAcceptedSpy.firstCall.args[0]).toHaveLength(3)
|
|
668
|
+
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
669
|
+
})
|
|
642
670
|
|
|
643
671
|
it('applies the maxSize prop to the dropped files', () => {
|
|
644
672
|
const dropzone = mount(
|
|
@@ -648,16 +676,16 @@ describe('Dropzone', () => {
|
|
|
648
676
|
onDropRejected={dropRejectedSpy}
|
|
649
677
|
maxSize={1111}
|
|
650
678
|
/>
|
|
651
|
-
)
|
|
679
|
+
)
|
|
652
680
|
|
|
653
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
654
|
-
expect(dropSpy.callCount).toEqual(1)
|
|
655
|
-
expect(dropSpy.firstCall.args[0]).toHaveLength(1)
|
|
656
|
-
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
657
|
-
expect(dropAcceptedSpy.callCount).toEqual(1)
|
|
658
|
-
expect(dropAcceptedSpy.firstCall.args[0]).toHaveLength(1)
|
|
659
|
-
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
660
|
-
})
|
|
681
|
+
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
682
|
+
expect(dropSpy.callCount).toEqual(1)
|
|
683
|
+
expect(dropSpy.firstCall.args[0]).toHaveLength(1)
|
|
684
|
+
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
685
|
+
expect(dropAcceptedSpy.callCount).toEqual(1)
|
|
686
|
+
expect(dropAcceptedSpy.firstCall.args[0]).toHaveLength(1)
|
|
687
|
+
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
688
|
+
})
|
|
661
689
|
|
|
662
690
|
it('applies the maxSize prop to the dropped images', () => {
|
|
663
691
|
const dropzone = mount(
|
|
@@ -667,15 +695,15 @@ describe('Dropzone', () => {
|
|
|
667
695
|
onDropRejected={dropRejectedSpy}
|
|
668
696
|
maxSize={1111}
|
|
669
697
|
/>
|
|
670
|
-
)
|
|
671
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
672
|
-
expect(dropSpy.callCount).toEqual(1)
|
|
673
|
-
expect(dropSpy.firstCall.args[0]).toHaveLength(0)
|
|
674
|
-
expect(dropSpy.firstCall.args[1]).toHaveLength(2)
|
|
675
|
-
expect(dropAcceptedSpy.callCount).toEqual(0)
|
|
676
|
-
expect(dropRejectedSpy.callCount).toEqual(1)
|
|
677
|
-
expect(dropRejectedSpy.firstCall.args[0]).toHaveLength(2)
|
|
678
|
-
})
|
|
698
|
+
)
|
|
699
|
+
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
700
|
+
expect(dropSpy.callCount).toEqual(1)
|
|
701
|
+
expect(dropSpy.firstCall.args[0]).toHaveLength(0)
|
|
702
|
+
expect(dropSpy.firstCall.args[1]).toHaveLength(2)
|
|
703
|
+
expect(dropAcceptedSpy.callCount).toEqual(0)
|
|
704
|
+
expect(dropRejectedSpy.callCount).toEqual(1)
|
|
705
|
+
expect(dropRejectedSpy.firstCall.args[0]).toHaveLength(2)
|
|
706
|
+
})
|
|
679
707
|
|
|
680
708
|
it('applies the minSize prop to the dropped files', () => {
|
|
681
709
|
const dropzone = mount(
|
|
@@ -685,15 +713,15 @@ describe('Dropzone', () => {
|
|
|
685
713
|
onDropRejected={dropRejectedSpy}
|
|
686
714
|
minSize={1112}
|
|
687
715
|
/>
|
|
688
|
-
)
|
|
689
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
690
|
-
expect(dropSpy.callCount).toEqual(1)
|
|
691
|
-
expect(dropSpy.firstCall.args[0]).toHaveLength(0)
|
|
692
|
-
expect(dropSpy.firstCall.args[1]).toHaveLength(1)
|
|
693
|
-
expect(dropAcceptedSpy.callCount).toEqual(0)
|
|
694
|
-
expect(dropRejectedSpy.callCount).toEqual(1)
|
|
695
|
-
expect(dropRejectedSpy.firstCall.args[0]).toHaveLength(1)
|
|
696
|
-
})
|
|
716
|
+
)
|
|
717
|
+
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
718
|
+
expect(dropSpy.callCount).toEqual(1)
|
|
719
|
+
expect(dropSpy.firstCall.args[0]).toHaveLength(0)
|
|
720
|
+
expect(dropSpy.firstCall.args[1]).toHaveLength(1)
|
|
721
|
+
expect(dropAcceptedSpy.callCount).toEqual(0)
|
|
722
|
+
expect(dropRejectedSpy.callCount).toEqual(1)
|
|
723
|
+
expect(dropRejectedSpy.firstCall.args[0]).toHaveLength(1)
|
|
724
|
+
})
|
|
697
725
|
|
|
698
726
|
it('applies the minSize prop to the dropped images', () => {
|
|
699
727
|
const dropzone = mount(
|
|
@@ -703,15 +731,15 @@ describe('Dropzone', () => {
|
|
|
703
731
|
onDropRejected={dropRejectedSpy}
|
|
704
732
|
minSize={1112}
|
|
705
733
|
/>
|
|
706
|
-
)
|
|
707
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
708
|
-
expect(dropSpy.callCount).toEqual(1)
|
|
709
|
-
expect(dropSpy.firstCall.args[0]).toHaveLength(2)
|
|
710
|
-
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
711
|
-
expect(dropAcceptedSpy.callCount).toEqual(1)
|
|
712
|
-
expect(dropAcceptedSpy.firstCall.args[0]).toHaveLength(2)
|
|
713
|
-
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
714
|
-
})
|
|
734
|
+
)
|
|
735
|
+
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
736
|
+
expect(dropSpy.callCount).toEqual(1)
|
|
737
|
+
expect(dropSpy.firstCall.args[0]).toHaveLength(2)
|
|
738
|
+
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
739
|
+
expect(dropAcceptedSpy.callCount).toEqual(1)
|
|
740
|
+
expect(dropAcceptedSpy.firstCall.args[0]).toHaveLength(2)
|
|
741
|
+
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
742
|
+
})
|
|
715
743
|
|
|
716
744
|
it('accepts all dropped files and images when no size prop is specified', () => {
|
|
717
745
|
const dropzone = mount(
|
|
@@ -720,124 +748,112 @@ describe('Dropzone', () => {
|
|
|
720
748
|
onDropAccepted={dropAcceptedSpy}
|
|
721
749
|
onDropRejected={dropRejectedSpy}
|
|
722
750
|
/>
|
|
723
|
-
)
|
|
724
|
-
dropzone.simulate('drop', { dataTransfer: { files: files.concat(images) } })
|
|
725
|
-
expect(dropSpy.callCount).toEqual(1)
|
|
726
|
-
expect(dropSpy.firstCall.args[0]).toHaveLength(3)
|
|
727
|
-
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
728
|
-
expect(dropAcceptedSpy.callCount).toEqual(1)
|
|
729
|
-
expect(dropAcceptedSpy.firstCall.args[0]).toHaveLength(3)
|
|
730
|
-
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
731
|
-
})
|
|
732
|
-
})
|
|
751
|
+
)
|
|
752
|
+
dropzone.simulate('drop', { dataTransfer: { files: files.concat(images) } })
|
|
753
|
+
expect(dropSpy.callCount).toEqual(1)
|
|
754
|
+
expect(dropSpy.firstCall.args[0]).toHaveLength(3)
|
|
755
|
+
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
756
|
+
expect(dropAcceptedSpy.callCount).toEqual(1)
|
|
757
|
+
expect(dropAcceptedSpy.firstCall.args[0]).toHaveLength(3)
|
|
758
|
+
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
759
|
+
})
|
|
760
|
+
})
|
|
733
761
|
|
|
734
762
|
describe('preview', () => {
|
|
735
763
|
it('should generate previews for non-images', () => {
|
|
736
|
-
const dropSpy = spy()
|
|
737
|
-
const dropzone = mount(
|
|
738
|
-
|
|
739
|
-
)
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
expect(dropSpy.firstCall.args[0][0].preview).toContain('data://file1.pdf');
|
|
743
|
-
});
|
|
764
|
+
const dropSpy = spy()
|
|
765
|
+
const dropzone = mount(<Dropzone onDrop={dropSpy} />)
|
|
766
|
+
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
767
|
+
expect(Object.keys(dropSpy.firstCall.args[0][0])).toContain('preview')
|
|
768
|
+
expect(dropSpy.firstCall.args[0][0].preview).toContain('data://file1.pdf')
|
|
769
|
+
})
|
|
744
770
|
|
|
745
771
|
it('should generate previews for images', () => {
|
|
746
|
-
const dropSpy = spy()
|
|
747
|
-
const dropzone = mount(
|
|
748
|
-
|
|
749
|
-
)
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
expect(dropSpy.firstCall.args[0][0].preview).toContain('data://cats.gif');
|
|
753
|
-
});
|
|
772
|
+
const dropSpy = spy()
|
|
773
|
+
const dropzone = mount(<Dropzone onDrop={dropSpy} />)
|
|
774
|
+
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
775
|
+
expect(Object.keys(dropSpy.firstCall.args[0][0])).toContain('preview')
|
|
776
|
+
expect(dropSpy.firstCall.args[0][0].preview).toContain('data://cats.gif')
|
|
777
|
+
})
|
|
754
778
|
|
|
755
779
|
it('should not throw error when preview cannot be created', () => {
|
|
756
|
-
const dropSpy = spy()
|
|
757
|
-
const dropzone = mount(
|
|
758
|
-
<Dropzone onDrop={dropSpy} />
|
|
759
|
-
);
|
|
780
|
+
const dropSpy = spy()
|
|
781
|
+
const dropzone = mount(<Dropzone onDrop={dropSpy} />)
|
|
760
782
|
|
|
783
|
+
dropzone.simulate('drop', { dataTransfer: { files: ['bad_val'] } })
|
|
761
784
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
expect(Object.keys(dropSpy.firstCall.args[1][0])).not.toContain('preview');
|
|
765
|
-
});
|
|
785
|
+
expect(Object.keys(dropSpy.firstCall.args[1][0])).not.toContain('preview')
|
|
786
|
+
})
|
|
766
787
|
|
|
767
788
|
it('should not generate previews if disablePreview is true', () => {
|
|
768
|
-
const dropSpy = spy()
|
|
769
|
-
const dropzone = mount(
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
)
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
expect(Object.keys(dropSpy.lastCall.args[0][0])).not.toContain('preview');
|
|
780
|
-
});
|
|
781
|
-
});
|
|
782
|
-
|
|
783
|
-
describe('onClick', () => {});
|
|
789
|
+
const dropSpy = spy()
|
|
790
|
+
const dropzone = mount(<Dropzone disablePreview onDrop={dropSpy} />)
|
|
791
|
+
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
792
|
+
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
793
|
+
expect(dropSpy.callCount).toEqual(2)
|
|
794
|
+
expect(Object.keys(dropSpy.firstCall.args[0][0])).not.toContain('preview')
|
|
795
|
+
expect(Object.keys(dropSpy.lastCall.args[0][0])).not.toContain('preview')
|
|
796
|
+
})
|
|
797
|
+
})
|
|
798
|
+
|
|
799
|
+
describe('onClick', () => {})
|
|
784
800
|
|
|
785
801
|
describe('onCancel', () => {
|
|
786
|
-
it('should not invoke onFileDialogCancel everytime window receives focus',
|
|
787
|
-
const onCancelSpy = spy()
|
|
788
|
-
mount(
|
|
789
|
-
<Dropzone id="on-cancel-example" onFileDialogCancel={onCancelSpy} />
|
|
790
|
-
);
|
|
802
|
+
it('should not invoke onFileDialogCancel everytime window receives focus', done => {
|
|
803
|
+
const onCancelSpy = spy()
|
|
804
|
+
mount(<Dropzone id="on-cancel-example" onFileDialogCancel={onCancelSpy} />)
|
|
791
805
|
// Simulated DOM event - onfocus
|
|
792
|
-
document.body.addEventListener('focus', () => {})
|
|
793
|
-
const evt = document.createEvent('HTMLEvents')
|
|
794
|
-
evt.initEvent('focus', false, true)
|
|
795
|
-
document.body.dispatchEvent(evt)
|
|
806
|
+
document.body.addEventListener('focus', () => {})
|
|
807
|
+
const evt = document.createEvent('HTMLEvents')
|
|
808
|
+
evt.initEvent('focus', false, true)
|
|
809
|
+
document.body.dispatchEvent(evt)
|
|
796
810
|
// setTimeout to match the event callback from actual Component
|
|
797
811
|
setTimeout(() => {
|
|
798
|
-
expect(onCancelSpy.callCount).toEqual(0)
|
|
799
|
-
done()
|
|
800
|
-
}, 300)
|
|
801
|
-
})
|
|
812
|
+
expect(onCancelSpy.callCount).toEqual(0)
|
|
813
|
+
done()
|
|
814
|
+
}, 300)
|
|
815
|
+
})
|
|
802
816
|
|
|
803
|
-
it('should invoke onFileDialogCancel when window receives focus via cancel button',
|
|
804
|
-
const onCancelSpy = spy()
|
|
817
|
+
it('should invoke onFileDialogCancel when window receives focus via cancel button', done => {
|
|
818
|
+
const onCancelSpy = spy()
|
|
805
819
|
const component = mount(
|
|
806
820
|
<Dropzone className="dropzone-content" onFileDialogCancel={onCancelSpy} />
|
|
807
|
-
)
|
|
821
|
+
)
|
|
808
822
|
|
|
809
823
|
// Test / invoke the click event
|
|
810
|
-
spy(component.instance(), 'open')
|
|
811
|
-
component.simulate('click')
|
|
812
|
-
expect(component.instance().open.callCount).toEqual(1);
|
|
813
|
-
|
|
814
|
-
// Simulated DOM event - onfocus
|
|
815
|
-
document.body.addEventListener('focus', () => {});
|
|
816
|
-
const evt = document.createEvent('HTMLEvents');
|
|
817
|
-
evt.initEvent('focus', false, true);
|
|
818
|
-
document.body.dispatchEvent(evt);
|
|
824
|
+
spy(component.instance(), 'open')
|
|
825
|
+
component.simulate('click')
|
|
819
826
|
|
|
820
|
-
// setTimeout to match the event callback from actual Component
|
|
821
827
|
setTimeout(() => {
|
|
822
|
-
expect(
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
+
expect(component.instance().open.callCount).toEqual(1)
|
|
829
|
+
|
|
830
|
+
// Simulated DOM event - onfocus
|
|
831
|
+
document.body.addEventListener('focus', () => {})
|
|
832
|
+
const evt = document.createEvent('HTMLEvents')
|
|
833
|
+
evt.initEvent('focus', false, true)
|
|
834
|
+
document.body.dispatchEvent(evt)
|
|
835
|
+
|
|
836
|
+
// setTimeout to match the event callback from actual Component
|
|
837
|
+
setTimeout(() => {
|
|
838
|
+
expect(onCancelSpy.callCount).toEqual(1)
|
|
839
|
+
done()
|
|
840
|
+
}, 300)
|
|
841
|
+
}, 0)
|
|
842
|
+
})
|
|
843
|
+
})
|
|
828
844
|
|
|
829
845
|
describe('nested Dropzone component behavior', () => {
|
|
830
|
-
let outerDropzone
|
|
831
|
-
let innerDropzone
|
|
832
|
-
let outerDropSpy
|
|
833
|
-
let outerDropAcceptedSpy
|
|
834
|
-
let outerDropRejectedSpy
|
|
835
|
-
let innerDropSpy
|
|
836
|
-
let innerDropAcceptedSpy
|
|
837
|
-
let innerDropRejectedSpy
|
|
838
|
-
|
|
839
|
-
const InnerDragAccepted = () => <p>Accepted</p
|
|
840
|
-
const InnerDragRejected = () => <p>Rejected</p
|
|
846
|
+
let outerDropzone
|
|
847
|
+
let innerDropzone
|
|
848
|
+
let outerDropSpy
|
|
849
|
+
let outerDropAcceptedSpy
|
|
850
|
+
let outerDropRejectedSpy
|
|
851
|
+
let innerDropSpy
|
|
852
|
+
let innerDropAcceptedSpy
|
|
853
|
+
let innerDropRejectedSpy
|
|
854
|
+
|
|
855
|
+
const InnerDragAccepted = () => <p>Accepted</p>
|
|
856
|
+
const InnerDragRejected = () => <p>Rejected</p>
|
|
841
857
|
const InnerDropzone = () => (
|
|
842
858
|
<Dropzone
|
|
843
859
|
onDrop={innerDropSpy}
|
|
@@ -846,21 +862,21 @@ describe('Dropzone', () => {
|
|
|
846
862
|
accept="image/*"
|
|
847
863
|
>
|
|
848
864
|
{({ isDragActive, isDragReject }) => {
|
|
849
|
-
if (isDragReject) return <InnerDragRejected
|
|
850
|
-
if (isDragActive) return <InnerDragAccepted
|
|
851
|
-
return <p>No drag</p
|
|
865
|
+
if (isDragReject) return <InnerDragRejected />
|
|
866
|
+
if (isDragActive) return <InnerDragAccepted />
|
|
867
|
+
return <p>No drag</p>
|
|
852
868
|
}}
|
|
853
869
|
</Dropzone>
|
|
854
|
-
)
|
|
870
|
+
)
|
|
855
871
|
|
|
856
872
|
describe('dropping on the inner dropzone', () => {
|
|
857
873
|
it('mounts both dropzones', () => {
|
|
858
|
-
outerDropSpy = spy()
|
|
859
|
-
outerDropAcceptedSpy = spy()
|
|
860
|
-
outerDropRejectedSpy = spy()
|
|
861
|
-
innerDropSpy = spy()
|
|
862
|
-
innerDropAcceptedSpy = spy()
|
|
863
|
-
innerDropRejectedSpy = spy()
|
|
874
|
+
outerDropSpy = spy()
|
|
875
|
+
outerDropAcceptedSpy = spy()
|
|
876
|
+
outerDropRejectedSpy = spy()
|
|
877
|
+
innerDropSpy = spy()
|
|
878
|
+
innerDropAcceptedSpy = spy()
|
|
879
|
+
innerDropRejectedSpy = spy()
|
|
864
880
|
outerDropzone = mount(
|
|
865
881
|
<Dropzone
|
|
866
882
|
onDrop={outerDropSpy}
|
|
@@ -868,60 +884,56 @@ describe('Dropzone', () => {
|
|
|
868
884
|
onDropRejected={outerDropRejectedSpy}
|
|
869
885
|
accept="image/*"
|
|
870
886
|
>
|
|
871
|
-
<
|
|
872
|
-
<InnerDropzone />
|
|
887
|
+
{props => <InnerDropzone {...props} />}
|
|
873
888
|
</Dropzone>
|
|
874
|
-
)
|
|
875
|
-
innerDropzone = outerDropzone.find(InnerDropzone)
|
|
876
|
-
})
|
|
889
|
+
)
|
|
890
|
+
innerDropzone = outerDropzone.find(InnerDropzone)
|
|
891
|
+
})
|
|
877
892
|
|
|
878
893
|
it('does dragEnter on both dropzones', () => {
|
|
879
|
-
innerDropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
880
|
-
expect(
|
|
881
|
-
expect(
|
|
882
|
-
expect(innerDropzone.find(InnerDragAccepted).exists()).toEqual(true)
|
|
883
|
-
expect(innerDropzone.find(InnerDragRejected).exists()).toEqual(false)
|
|
884
|
-
})
|
|
894
|
+
innerDropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
895
|
+
expect(innerDropzone).toHaveProp('isDragActive', true)
|
|
896
|
+
expect(innerDropzone).toHaveProp('isDragReject', false)
|
|
897
|
+
expect(innerDropzone.find(InnerDragAccepted).exists()).toEqual(true)
|
|
898
|
+
expect(innerDropzone.find(InnerDragRejected).exists()).toEqual(false)
|
|
899
|
+
})
|
|
885
900
|
|
|
886
901
|
it('drops on the child dropzone', () => {
|
|
887
|
-
innerDropzone.simulate('drop', { dataTransfer: { files: files.concat(images) } })
|
|
888
|
-
})
|
|
902
|
+
innerDropzone.simulate('drop', { dataTransfer: { files: files.concat(images) } })
|
|
903
|
+
})
|
|
889
904
|
|
|
890
905
|
it('accepts the drop on the inner dropzone', () => {
|
|
891
|
-
expect(innerDropSpy.callCount).toEqual(1)
|
|
892
|
-
expect(innerDropSpy.firstCall.args[0]).toHaveLength(2)
|
|
893
|
-
expect(innerDropSpy.firstCall.args[1]).toHaveLength(1)
|
|
894
|
-
expect(innerDropAcceptedSpy.callCount).toEqual(1)
|
|
895
|
-
expect(innerDropAcceptedSpy.firstCall.args[0]).toHaveLength(2)
|
|
896
|
-
expect(innerDropRejectedSpy.callCount).toEqual(1)
|
|
897
|
-
expect(innerDropRejectedSpy.firstCall.args[0]).toHaveLength(1)
|
|
898
|
-
expect(innerDropzone.find(InnerDragAccepted).exists()).toEqual(false)
|
|
899
|
-
expect(innerDropzone.find(InnerDragRejected).exists()).toEqual(false)
|
|
900
|
-
})
|
|
906
|
+
expect(innerDropSpy.callCount).toEqual(1)
|
|
907
|
+
expect(innerDropSpy.firstCall.args[0]).toHaveLength(2)
|
|
908
|
+
expect(innerDropSpy.firstCall.args[1]).toHaveLength(1)
|
|
909
|
+
expect(innerDropAcceptedSpy.callCount).toEqual(1)
|
|
910
|
+
expect(innerDropAcceptedSpy.firstCall.args[0]).toHaveLength(2)
|
|
911
|
+
expect(innerDropRejectedSpy.callCount).toEqual(1)
|
|
912
|
+
expect(innerDropRejectedSpy.firstCall.args[0]).toHaveLength(1)
|
|
913
|
+
expect(innerDropzone.find(InnerDragAccepted).exists()).toEqual(false)
|
|
914
|
+
expect(innerDropzone.find(InnerDragRejected).exists()).toEqual(false)
|
|
915
|
+
})
|
|
901
916
|
|
|
902
917
|
it('also accepts the drop on the outer dropzone', () => {
|
|
903
|
-
expect(outerDropSpy.callCount).toEqual(1)
|
|
904
|
-
expect(outerDropSpy.firstCall.args[0]).toHaveLength(2)
|
|
905
|
-
expect(outerDropSpy.firstCall.args[1]).toHaveLength(1)
|
|
906
|
-
expect(outerDropAcceptedSpy.callCount).toEqual(1)
|
|
907
|
-
expect(outerDropAcceptedSpy.firstCall.args[0]).toHaveLength(2)
|
|
908
|
-
expect(outerDropRejectedSpy.callCount).toEqual(1)
|
|
909
|
-
expect(outerDropRejectedSpy.firstCall.args[0]).toHaveLength(1)
|
|
910
|
-
expect(
|
|
911
|
-
expect(
|
|
912
|
-
})
|
|
913
|
-
})
|
|
914
|
-
})
|
|
918
|
+
expect(outerDropSpy.callCount).toEqual(1)
|
|
919
|
+
expect(outerDropSpy.firstCall.args[0]).toHaveLength(2)
|
|
920
|
+
expect(outerDropSpy.firstCall.args[1]).toHaveLength(1)
|
|
921
|
+
expect(outerDropAcceptedSpy.callCount).toEqual(1)
|
|
922
|
+
expect(outerDropAcceptedSpy.firstCall.args[0]).toHaveLength(2)
|
|
923
|
+
expect(outerDropRejectedSpy.callCount).toEqual(1)
|
|
924
|
+
expect(outerDropRejectedSpy.firstCall.args[0]).toHaveLength(1)
|
|
925
|
+
expect(innerDropzone).toHaveProp('isDragActive', false)
|
|
926
|
+
expect(innerDropzone).toHaveProp('isDragReject', false)
|
|
927
|
+
})
|
|
928
|
+
})
|
|
929
|
+
})
|
|
915
930
|
|
|
916
931
|
describe('behavior', () => {
|
|
917
932
|
it('does not throw an error when html is dropped instead of files and multiple is false', () => {
|
|
918
|
-
const dropzone = mount(
|
|
919
|
-
<Dropzone multiple={false} />
|
|
920
|
-
);
|
|
921
|
-
|
|
922
|
-
const fn = () => dropzone.simulate('drop', { dataTransfer: { files: [] } });
|
|
923
|
-
expect(fn).not.toThrow();
|
|
924
|
-
});
|
|
925
|
-
});
|
|
933
|
+
const dropzone = mount(<Dropzone multiple={false} />)
|
|
926
934
|
|
|
927
|
-
})
|
|
935
|
+
const fn = () => dropzone.simulate('drop', { dataTransfer: { files: [] } })
|
|
936
|
+
expect(fn).not.toThrow()
|
|
937
|
+
})
|
|
938
|
+
})
|
|
939
|
+
})
|