@@ -72,15 +72,24 @@ describe('UiFileDropZoneDirective', () => {
7272 } ) ;
7373
7474 describe ( 'dragging and dropping files' , ( ) => {
75- it ( 'should add class to drop zone when dragging over' , ( ) => {
75+ it ( 'should not add class to drop zone when entering the drag zone' , ( ) => {
76+ spectator . dispatchMouseEvent ( byTestId ( 'custom-drop-zone' ) , 'dragenter' , 0 , 0 , getDragEventWithDataTransfer ( 'dragover' ) ) ;
77+ spectator . detectChanges ( ) ;
78+
79+ expect ( spectator . query ( byTestId ( 'custom-drop-zone' ) ) ) . not . toHaveClass ( 'ui-file-drop-zone-highlight' ) ;
80+ } ) ;
81+
82+ it ( 'should not add class to drop zone when entering the drag zone with data that does not include files' , ( ) => {
7683 spectator . dispatchMouseEvent ( byTestId ( 'custom-drop-zone' ) , 'dragenter' ) ;
84+ spectator . dispatchMouseEvent ( byTestId ( 'custom-drop-zone' ) , 'dragover' , 0 , 0 , getDragEventWithDataTransfer ( 'dragover' , false ) ) ;
7785 spectator . detectChanges ( ) ;
7886
79- expect ( spectator . query ( byTestId ( 'custom-drop-zone' ) ) ) . toHaveClass ( 'ui-file-drop-zone-highlight' ) ;
87+ expect ( spectator . query ( byTestId ( 'custom-drop-zone' ) ) ) . not . toHaveClass ( 'ui-file-drop-zone-highlight' ) ;
8088 } ) ;
8189
8290 it ( 'should not remove highlight class when dragging over an element inside the dropzone' , ( ) => {
8391 spectator . dispatchMouseEvent ( byTestId ( 'custom-drop-zone' ) , 'dragenter' ) ;
92+ spectator . dispatchMouseEvent ( byTestId ( 'custom-drop-zone' ) , 'dragover' , 0 , 0 , getDragEventWithDataTransfer ( 'dragover' ) ) ;
8493 spectator . dispatchMouseEvent ( 'button' , 'dragenter' ) ;
8594 spectator . dispatchMouseEvent ( byTestId ( 'custom-drop-zone' ) , 'dragleave' ) ;
8695 spectator . detectChanges ( ) ;
@@ -90,14 +99,17 @@ describe('UiFileDropZoneDirective', () => {
9099
91100 it ( 'should remove highlight when dropping files' , ( ) => {
92101 spectator . dispatchMouseEvent ( byTestId ( 'custom-drop-zone' ) , 'dragenter' ) ;
93- spectator . dispatchMouseEvent ( byTestId ( 'custom-drop-zone' ) , 'drop' ) ;
102+ spectator . dispatchMouseEvent ( byTestId ( 'custom-drop-zone' ) , 'dragover' , 0 , 0 , getDragEventWithDataTransfer ( 'dragover' ) ) ;
103+ expect ( spectator . query ( byTestId ( 'custom-drop-zone' ) ) ) . toHaveClass ( 'ui-file-drop-zone-highlight' ) ;
104+
105+ spectator . dispatchMouseEvent ( byTestId ( 'custom-drop-zone' ) , 'drop' , 0 , 0 , getDragEventWithDataTransfer ( 'drop' ) ) ;
94106 spectator . detectChanges ( ) ;
95107
96108 expect ( spectator . query ( byTestId ( 'custom-drop-zone' ) ) ) . not . toHaveClass ( 'ui-file-drop-zone-highlight' ) ;
97109 } ) ;
98110
99111 it ( 'should call service with files that were dropped' , ( ) => {
100- const mouseEvent = createMouseEvent ( 'drop' ) ;
112+ const mouseEvent = getDragEventWithDataTransfer ( 'drop' ) ;
101113
102114 spectator . dispatchMouseEvent ( byTestId ( 'custom-drop-zone' ) , 'drop' , undefined , undefined , mouseEvent ) ;
103115 spectator . detectChanges ( ) ;
@@ -155,3 +167,12 @@ describe('UiFileDropZoneDirective', () => {
155167 } ) ;
156168 } ) ;
157169} ) ;
170+
171+ const getDragEventWithDataTransfer = ( type : 'dragover' | 'drop' , containsFiles = true ) => {
172+ const dataTransfer = new DataTransfer ( ) ;
173+ if ( containsFiles ) {
174+ const file = new File ( [ '' ] , 'file.jog' ) ;
175+ dataTransfer . items . add ( file ) ;
176+ }
177+ return new DragEvent ( type , { dataTransfer } ) ;
178+ } ;
0 commit comments