@@ -56,4 +56,59 @@ describe('file-attachment', function() {
56
56
assert . equal ( '/s3/saved.txt' , attachment . href )
57
57
} )
58
58
} )
59
+
60
+ describe ( 'element' , function ( ) {
61
+ let fileAttachment
62
+ beforeEach ( function ( ) {
63
+ document . body . innerHTML = `<file-attachment></file-attachment>`
64
+
65
+ fileAttachment = document . querySelector ( 'file-attachment' )
66
+ } )
67
+
68
+ afterEach ( function ( ) {
69
+ document . body . innerHTML = ''
70
+ } )
71
+
72
+ it ( 'attaches files via .attach' , async function ( ) {
73
+ const listener = once ( 'file-attachment-accepted' )
74
+
75
+ const dataTransfer = new DataTransfer ( )
76
+ const file = new File ( [ 'hubot' ] , 'test.txt' , { type : 'text/plain' } )
77
+ dataTransfer . items . add ( file )
78
+ fileAttachment . attach ( dataTransfer )
79
+
80
+ const event = await listener
81
+ assert . equal ( 'test.txt' , event . detail . attachments [ 0 ] . file . name )
82
+ } )
83
+
84
+ it ( 'attaches files via drop' , async function ( ) {
85
+ const listener = once ( 'file-attachment-accepted' )
86
+
87
+ const dataTransfer = new DataTransfer ( )
88
+ const file = new File ( [ 'hubot' ] , 'test.txt' , { type : 'text/plain' } )
89
+ dataTransfer . items . add ( file )
90
+ const dropEvent = new DragEvent ( 'drop' , { bubbles : true , dataTransfer} )
91
+ fileAttachment . dispatchEvent ( dropEvent )
92
+
93
+ const event = await listener
94
+ assert . equal ( 'test.txt' , event . detail . attachments [ 0 ] . file . name )
95
+ } )
96
+
97
+ it ( 'attaches images via paste' , async function ( ) {
98
+ const listener = once ( 'file-attachment-accepted' )
99
+
100
+ const dataTransfer = new DataTransfer ( )
101
+ const file = new File ( [ 'hubot' ] , 'test.png' , { type : 'image/png' } )
102
+ dataTransfer . items . add ( file )
103
+ const dropEvent = new ClipboardEvent ( 'paste' , { bubbles : true , clipboardData : dataTransfer } )
104
+ fileAttachment . dispatchEvent ( dropEvent )
105
+
106
+ const event = await listener
107
+ assert . equal ( 'test.png' , event . detail . attachments [ 0 ] . file . name )
108
+ } )
109
+ } )
59
110
} )
111
+
112
+ function once ( eventName ) {
113
+ return new Promise ( resolve => document . addEventListener ( eventName , resolve , { once : true } ) )
114
+ }
0 commit comments