@@ -363,5 +363,42 @@ describe('useClipboard', () => {
363
363
expect ( await onPaste . mock . calls [ 0 ] [ 0 ] [ 1 ] . getText ( 'test' ) ) . toBe ( 'item 2' ) ;
364
364
expect ( await onPaste . mock . calls [ 0 ] [ 0 ] [ 1 ] . getText ( 'text/plain' ) ) . toBe ( 'item 2' ) ;
365
365
} ) ;
366
+
367
+ it ( 'should show the type of the clipboard event if cutting' , async ( ) => {
368
+ let getItems = ( details ) => [ {
369
+ [ details . type ] : 'test data'
370
+ } ] ;
371
+
372
+ let onCut = jest . fn ( ) ;
373
+ let tree = render ( < Copyable getItems = { getItems } onCut = { onCut } /> ) ;
374
+ let button = tree . getByRole ( 'button' ) ;
375
+
376
+ await user . tab ( ) ;
377
+ expect ( document . activeElement ) . toBe ( button ) ;
378
+
379
+ let clipboardData = new DataTransfer ( ) ;
380
+ fireEvent ( button , new ClipboardEvent ( 'cut' , { clipboardData} ) ) ;
381
+ expect ( [ ...clipboardData . items ] ) . toEqual ( [ new DataTransferItem ( 'cut' , 'test data' ) ] ) ;
382
+ expect ( onCut ) . toHaveBeenCalledTimes ( 1 ) ;
383
+ } ) ;
384
+
385
+ it ( 'should show the type of the clipboard event if copying' , async ( ) => {
386
+ let getItems = ( details ) => [ {
387
+ [ details . type ] : 'test data'
388
+ } ] ;
389
+
390
+ let onCopy = jest . fn ( ) ;
391
+ let tree = render ( < Copyable getItems = { getItems } onCopy = { onCopy } /> ) ;
392
+ let button = tree . getByRole ( 'button' ) ;
393
+
394
+ await user . tab ( ) ;
395
+ expect ( document . activeElement ) . toBe ( button ) ;
396
+
397
+ let clipboardData = new DataTransfer ( ) ;
398
+ fireEvent ( button , new ClipboardEvent ( 'copy' , { clipboardData} ) ) ;
399
+ expect ( [ ...clipboardData . items ] ) . toEqual ( [ new DataTransferItem ( 'copy' , 'test data' ) ] ) ;
400
+ expect ( onCopy ) . toHaveBeenCalledTimes ( 1 ) ;
401
+ } ) ;
366
402
} ) ;
367
403
} ) ;
404
+
0 commit comments