Skip to content

Commit 5745215

Browse files
committed
Add test for input changes
1 parent 06902e6 commit 5745215

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

test/test.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ describe('file-attachment', function() {
5858
})
5959

6060
describe('element', function() {
61-
let fileAttachment
61+
let fileAttachment, input
6262
beforeEach(function() {
63-
document.body.innerHTML = `<file-attachment></file-attachment>`
63+
document.body.innerHTML = `<file-attachment><input type="file"></file-attachment>`
6464

6565
fileAttachment = document.querySelector('file-attachment')
66+
input = document.querySelector('input')
6667
})
6768

6869
afterEach(function() {
@@ -106,6 +107,20 @@ describe('file-attachment', function() {
106107
const event = await listener
107108
assert.equal('test.png', event.detail.attachments[0].file.name)
108109
})
110+
111+
it('attaches files via input', async function() {
112+
const listener = once('file-attachment-accepted')
113+
114+
const dataTransfer = new DataTransfer()
115+
const file = new File(['hubot'], 'test.png', {type: 'image/png'})
116+
dataTransfer.items.add(file)
117+
input.files = dataTransfer.files
118+
input.dispatchEvent(new Event('change', {bubbles: true}))
119+
120+
const event = await listener
121+
assert.equal('test.png', event.detail.attachments[0].file.name)
122+
assert.equal(0, input.files.length)
123+
})
109124
})
110125
})
111126

0 commit comments

Comments
 (0)