@@ -80,32 +80,16 @@ describe('NgsgItemDirective', () => {
8080 } ) ;
8181
8282 it ( 'should call sort with the host if the event occured on the host' , ( ) => {
83- const event = { target : { matches : ( ) => true } } ;
8483 ngsgStore . hasSelectedItems . and . returnValue ( true ) ;
8584
86- sut . dragEnter ( event ) ;
87- expect ( ngsgSortService . sort ) . toHaveBeenCalledWith ( event . target ) ;
88- } ) ;
89-
90- it ( 'should call sort with the host, even if the event did not occure on it' , ( ) => {
91- const event = { target : { matches : ( ) => false } } ;
92- const host = 'Some element' as any ;
93- ngsgStore . hasSelectedItems . and . returnValue ( true ) ;
94- NgsgElementsHelper . findHost = ( ) => host ;
95-
96- sut . dragEnter ( event ) ;
97- expect ( ngsgSortService . sort ) . toHaveBeenCalledWith ( host ) ;
85+ sut . dragEnter ( ) ;
86+ expect ( ngsgSortService . sort ) . toHaveBeenCalledWith ( elementRef . nativeElement ) ;
9887 } ) ;
9988
10089 it ( 'should sort the items if the event occured on the host and on the correct group' , ( ) => {
10190 ngsgStore . hasSelectedItems . and . returnValue ( true ) ;
102- const event = {
103- target : {
104- matches : ( ) => true
105- }
106- } ;
107- sut . dragEnter ( event ) ;
108- expect ( ngsgSortService . sort ) . toHaveBeenCalledWith ( event . target ) ;
91+ sut . dragEnter ( ) ;
92+ expect ( ngsgSortService . sort ) . toHaveBeenCalledWith ( elementRef . nativeElement ) ;
10993 } ) ;
11094
11195 it ( 'must call event preventDefault' , ( ) => {
@@ -122,46 +106,28 @@ describe('NgsgItemDirective', () => {
122106
123107 it ( 'should not call endSort if the group does not contain selectedItems' , ( ) => {
124108 ngsgStore . hasSelectedItems . and . returnValue ( false ) ;
125- sut . drop ( { } ) ;
109+ sut . drop ( ) ;
126110 expect ( ngsgSortService . endSort ) . not . toHaveBeenCalled ( ) ;
127111 } ) ;
128112
129113 it ( 'should sort if the group contains selectedItems' , ( ) => {
130114 ngsgStore . hasSelectedItems . and . returnValue ( true ) ;
131115 ngsgStore . hasItems . and . returnValue ( true ) ;
132- sut . drop ( { target : { matches : ( ) => true } } ) ;
116+ sut . drop ( ) ;
133117 expect ( ngsgSortService . endSort ) . toHaveBeenCalled ( ) ;
134118 } ) ;
135119
136120 it ( 'should call the reflection service with the host if the event occured on it' , ( ) => {
137121 const group = 'test-group' ;
138- const event = { target : { matches : ( ) => true } } ;
139122 sut . ngSortGridGroup = group ;
140123 ngsgStore . hasSelectedItems . and . returnValue ( true ) ;
141124
142- sut . drop ( event ) ;
143- expect ( ngsgReflectService . reflectChanges ) . toHaveBeenCalledWith ( group , event . target ) ;
144- } ) ;
145-
146- it ( 'should call the reflection service with the host even if the event did not occured on it' , ( ) => {
147- const group = 'test-group' ;
148- const event = { target : { matches : ( ) => false } } ;
149- const host = 'Some element' as any ;
150- NgsgElementsHelper . findHost = ( ) => host ;
151- sut . ngSortGridGroup = group ;
152- ngsgStore . hasSelectedItems . and . returnValue ( true ) ;
153-
154- sut . drop ( event ) ;
155- expect ( ngsgReflectService . reflectChanges ) . toHaveBeenCalledWith ( group , host ) ;
125+ sut . drop ( ) ;
126+ expect ( ngsgReflectService . reflectChanges ) . toHaveBeenCalledWith ( group , elementRef . nativeElement ) ;
156127 } ) ;
157128
158129 it ( 'should get the reflected changes from the reflection service and emit them' , done => {
159130 const group = 'test-group' ;
160- const event = {
161- target : {
162- matches : ( ) => true
163- }
164- } ;
165131 const reflectedChanges = [ 'item two' , 'item one' , 'item three' ] ;
166132
167133 ngsgStore . hasSelectedItems . and . returnValue ( true ) ;
@@ -173,40 +139,26 @@ describe('NgsgItemDirective', () => {
173139 expect ( reflectedChanges ) . toEqual ( changes ) ;
174140 done ( ) ;
175141 } ) ;
176- sut . drop ( event ) ;
177- expect ( ngsgReflectService . reflectChanges ) . toHaveBeenCalledWith ( group , event . target ) ;
142+ sut . drop ( ) ;
143+ expect ( ngsgReflectService . reflectChanges ) . toHaveBeenCalledWith ( group , elementRef . nativeElement ) ;
178144 } ) ;
179145
180146 it ( 'should reset the selected items on drop' , ( ) => {
181- const event = { target : { matches : ( ) => true } } ;
182- sut . drop ( event ) ;
147+ sut . drop ( ) ;
183148 expect ( ngsgStore . resetSelectedItems ) . toHaveBeenCalled ( ) ;
184149 } ) ;
185150
186151 it ( 'should stream the dropped event on the eventservice' , done => {
187- const event = { target : { matches : ( ) => true } } ;
188152 ngsgEventService . dropped$ . subscribe ( ( ) => done ( ) ) ;
189- sut . drop ( event ) ;
153+ sut . drop ( ) ;
190154 } ) ;
191155
192156 it ( 'should call the selctionservice with the host if the event occured on the host' , ( ) => {
193157 const group = 'test-group' ;
194- const event = { target : { matches : ( ) => true } } ;
195- sut . ngSortGridGroup = group ;
196-
197- sut . clicked ( event ) ;
198- expect ( ngsgSelectionService . updateSelectedDragItem ) . toHaveBeenCalledWith ( group , event . target , true ) ;
199- } ) ;
200-
201- it ( 'should call the selctionservice with the host, even if the event did not occure on it' , ( ) => {
202- const group = 'test-group' ;
203- const event = { target : { matches : ( ) => false } } ;
204- const host = 'Some element' as any ;
205- NgsgElementsHelper . findHost = ( ) => host ;
206158 sut . ngSortGridGroup = group ;
207159
208- sut . clicked ( event ) ;
209- expect ( ngsgSelectionService . updateSelectedDragItem ) . toHaveBeenCalledWith ( group , host , true ) ;
160+ sut . clicked ( ) ;
161+ expect ( ngsgSelectionService . updateSelectedDragItem ) . toHaveBeenCalledWith ( group , elementRef . nativeElement , true ) ;
210162 } ) ;
211163
212164 it ( `should init the state with empty items if group has yet not been
@@ -260,7 +212,7 @@ describe('NgsgItemDirective', () => {
260212 const consoleWarnSpy = spyOn ( console , 'warn' ) ;
261213 ngsgStore . hasItems . and . returnValue ( false ) ;
262214
263- sut . drop ( event ) ;
215+ sut . drop ( ) ;
264216 expect ( consoleWarnSpy ) . toHaveBeenCalledWith ( expectedWarniningMessage ) ;
265217 } ) ;
266218} ) ;
0 commit comments