@@ -80,32 +80,16 @@ describe('NgsgItemDirective', () => {
80
80
} ) ;
81
81
82
82
it ( 'should call sort with the host if the event occured on the host' , ( ) => {
83
- const event = { target : { matches : ( ) => true } } ;
84
83
ngsgStore . hasSelectedItems . and . returnValue ( true ) ;
85
84
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 ) ;
98
87
} ) ;
99
88
100
89
it ( 'should sort the items if the event occured on the host and on the correct group' , ( ) => {
101
90
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 ) ;
109
93
} ) ;
110
94
111
95
it ( 'must call event preventDefault' , ( ) => {
@@ -122,46 +106,28 @@ describe('NgsgItemDirective', () => {
122
106
123
107
it ( 'should not call endSort if the group does not contain selectedItems' , ( ) => {
124
108
ngsgStore . hasSelectedItems . and . returnValue ( false ) ;
125
- sut . drop ( { } ) ;
109
+ sut . drop ( ) ;
126
110
expect ( ngsgSortService . endSort ) . not . toHaveBeenCalled ( ) ;
127
111
} ) ;
128
112
129
113
it ( 'should sort if the group contains selectedItems' , ( ) => {
130
114
ngsgStore . hasSelectedItems . and . returnValue ( true ) ;
131
115
ngsgStore . hasItems . and . returnValue ( true ) ;
132
- sut . drop ( { target : { matches : ( ) => true } } ) ;
116
+ sut . drop ( ) ;
133
117
expect ( ngsgSortService . endSort ) . toHaveBeenCalled ( ) ;
134
118
} ) ;
135
119
136
120
it ( 'should call the reflection service with the host if the event occured on it' , ( ) => {
137
121
const group = 'test-group' ;
138
- const event = { target : { matches : ( ) => true } } ;
139
122
sut . ngSortGridGroup = group ;
140
123
ngsgStore . hasSelectedItems . and . returnValue ( true ) ;
141
124
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 ) ;
156
127
} ) ;
157
128
158
129
it ( 'should get the reflected changes from the reflection service and emit them' , done => {
159
130
const group = 'test-group' ;
160
- const event = {
161
- target : {
162
- matches : ( ) => true
163
- }
164
- } ;
165
131
const reflectedChanges = [ 'item two' , 'item one' , 'item three' ] ;
166
132
167
133
ngsgStore . hasSelectedItems . and . returnValue ( true ) ;
@@ -173,40 +139,26 @@ describe('NgsgItemDirective', () => {
173
139
expect ( reflectedChanges ) . toEqual ( changes ) ;
174
140
done ( ) ;
175
141
} ) ;
176
- sut . drop ( event ) ;
177
- expect ( ngsgReflectService . reflectChanges ) . toHaveBeenCalledWith ( group , event . target ) ;
142
+ sut . drop ( ) ;
143
+ expect ( ngsgReflectService . reflectChanges ) . toHaveBeenCalledWith ( group , elementRef . nativeElement ) ;
178
144
} ) ;
179
145
180
146
it ( 'should reset the selected items on drop' , ( ) => {
181
- const event = { target : { matches : ( ) => true } } ;
182
- sut . drop ( event ) ;
147
+ sut . drop ( ) ;
183
148
expect ( ngsgStore . resetSelectedItems ) . toHaveBeenCalled ( ) ;
184
149
} ) ;
185
150
186
151
it ( 'should stream the dropped event on the eventservice' , done => {
187
- const event = { target : { matches : ( ) => true } } ;
188
152
ngsgEventService . dropped$ . subscribe ( ( ) => done ( ) ) ;
189
- sut . drop ( event ) ;
153
+ sut . drop ( ) ;
190
154
} ) ;
191
155
192
156
it ( 'should call the selctionservice with the host if the event occured on the host' , ( ) => {
193
157
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 ;
206
158
sut . ngSortGridGroup = group ;
207
159
208
- sut . clicked ( event ) ;
209
- expect ( ngsgSelectionService . updateSelectedDragItem ) . toHaveBeenCalledWith ( group , host , true ) ;
160
+ sut . clicked ( ) ;
161
+ expect ( ngsgSelectionService . updateSelectedDragItem ) . toHaveBeenCalledWith ( group , elementRef . nativeElement , true ) ;
210
162
} ) ;
211
163
212
164
it ( `should init the state with empty items if group has yet not been
@@ -260,7 +212,7 @@ describe('NgsgItemDirective', () => {
260
212
const consoleWarnSpy = spyOn ( console , 'warn' ) ;
261
213
ngsgStore . hasItems . and . returnValue ( false ) ;
262
214
263
- sut . drop ( event ) ;
215
+ sut . drop ( ) ;
264
216
expect ( consoleWarnSpy ) . toHaveBeenCalledWith ( expectedWarniningMessage ) ;
265
217
} ) ;
266
218
} ) ;
0 commit comments