Skip to content

Commit a8cfaf7

Browse files
134770: Test fixes
- Cast the store.dispatch method in expect calls, because ngrx now has multiple methods with the same name and jest can't deal with it - Removed the APP_INITIALIZER tests since it can't be tested like that anymore with the new provider format (cherry picked from commit d181c03)
1 parent cb3c68c commit a8cfaf7

18 files changed

+66
-91
lines changed

src/app/app.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ describe('App component', () => {
145145
});
146146

147147
it('should dispatch a HostWindowResizeAction with the width and height of the window as its payload', () => {
148-
expect(store.dispatch).toHaveBeenCalledWith(new HostWindowResizeAction(width, height));
148+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new HostWindowResizeAction(width, height));
149149
});
150150

151151
});

src/app/core/auth/auth.service.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ describe('AuthService test', () => {
242242
});
243243

244244
it('store should dispatch SetUserAsIdleAction', () => {
245-
expect(mockStore.dispatch).toHaveBeenCalledWith(new SetUserAsIdleAction());
245+
expect(mockStore.dispatch as jasmine.Spy).toHaveBeenCalledWith(new SetUserAsIdleAction());
246246
});
247247
});
248248

@@ -252,7 +252,7 @@ describe('AuthService test', () => {
252252
});
253253

254254
it('store should dispatch UnsetUserAsIdleAction', () => {
255-
expect(mockStore.dispatch).toHaveBeenCalledWith(new UnsetUserAsIdleAction());
255+
expect(mockStore.dispatch as jasmine.Spy).toHaveBeenCalledWith(new UnsetUserAsIdleAction());
256256
});
257257
});
258258
});

src/app/core/cache/object-cache.service.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ describe('ObjectCacheService', () => {
145145
describe('add', () => {
146146
it('should dispatch an ADD action with the object to add, the time to live, and the current timestamp', () => {
147147
service.add(objectToCache, msToLive, requestUUID, alternativeLink);
148-
expect(store.dispatch).toHaveBeenCalledWith(new AddToObjectCacheAction(objectToCache, timestamp, msToLive, requestUUID, alternativeLink));
148+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new AddToObjectCacheAction(objectToCache, timestamp, msToLive, requestUUID, alternativeLink));
149149
expect(linkServiceStub.removeResolvedLinks).toHaveBeenCalledWith(objectToCache);
150150
});
151151
});
@@ -157,20 +157,20 @@ describe('ObjectCacheService', () => {
157157

158158
it('should dispatch a REMOVE action with the self link of the object to remove', () => {
159159
service.remove(selfLink);
160-
expect(store.dispatch).toHaveBeenCalledWith(new RemoveFromObjectCacheAction(selfLink));
160+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new RemoveFromObjectCacheAction(selfLink));
161161
});
162162

163163
it('should dispatch a REMOVE_BY_SUBSTRING action on the index state for each alternativeLink in the object', () => {
164164
service.remove(selfLink);
165165
cacheEntry.alternativeLinks.forEach(
166-
(link: string) => expect(store.dispatch).toHaveBeenCalledWith(new RemoveFromIndexBySubstringAction(IndexName.ALTERNATIVE_OBJECT_LINK, link)));
166+
(link: string) => expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new RemoveFromIndexBySubstringAction(IndexName.ALTERNATIVE_OBJECT_LINK, link)));
167167
});
168168

169169
it('should dispatch a REMOVE_BY_SUBSTRING action on the index state for each _links in the object, except the self link', () => {
170170
service.remove(selfLink);
171171
Object.entries(objectToCache._links).forEach(([key, value]: [string, HALLink]) => {
172172
if (key !== 'self') {
173-
expect(store.dispatch).toHaveBeenCalledWith(new RemoveFromIndexBySubstringAction(IndexName.ALTERNATIVE_OBJECT_LINK, value.href));
173+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new RemoveFromIndexBySubstringAction(IndexName.ALTERNATIVE_OBJECT_LINK, value.href));
174174
}
175175
});
176176
});
@@ -339,8 +339,8 @@ describe('ObjectCacheService', () => {
339339
describe('patch methods', () => {
340340
it('should dispatch the correct actions when addPatch is called', () => {
341341
service.addPatch(selfLink, operations);
342-
expect(store.dispatch).toHaveBeenCalledWith(new AddPatchObjectCacheAction(selfLink, operations));
343-
expect(store.dispatch).toHaveBeenCalledWith(new AddToSSBAction(selfLink, RestRequestMethod.PATCH));
342+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new AddPatchObjectCacheAction(selfLink, operations));
343+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new AddToSSBAction(selfLink, RestRequestMethod.PATCH));
344344
});
345345

346346
it('isDirty should return true when the patches list in the cache entry is not empty', () => {
@@ -360,7 +360,7 @@ describe('ObjectCacheService', () => {
360360
});
361361
it('should dispatch the correct actions when applyPatchesToCachedObject is called', () => {
362362
(service as any).applyPatchesToCachedObject(selfLink);
363-
expect(store.dispatch).toHaveBeenCalledWith(new ApplyPatchObjectCacheAction(selfLink));
363+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new ApplyPatchObjectCacheAction(selfLink));
364364
});
365365
});
366366

@@ -392,12 +392,12 @@ describe('ObjectCacheService', () => {
392392
describe('addDependency', () => {
393393
it('should dispatch an ADD_DEPENDENTS action', () => {
394394
service.addDependency(selfLink, 'objectWithoutDependents');
395-
expect(store.dispatch).toHaveBeenCalledOnceWith(new AddDependentsObjectCacheAction('objectWithoutDependents', [requestUUID]));
395+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledOnceWith(new AddDependentsObjectCacheAction('objectWithoutDependents', [requestUUID]));
396396
});
397397

398398
it('should resolve alt links', () => {
399399
service.addDependency(anotherLink, 'objectWithoutDependentsAlt');
400-
expect(store.dispatch).toHaveBeenCalledOnceWith(new AddDependentsObjectCacheAction('objectWithoutDependents', [requestUUID]));
400+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledOnceWith(new AddDependentsObjectCacheAction('objectWithoutDependents', [requestUUID]));
401401
});
402402

403403
it('should not dispatch if either href cannot be resolved to a cached self link', () => {
@@ -421,7 +421,7 @@ describe('ObjectCacheService', () => {
421421

422422
it('should work with observable hrefs', () => {
423423
service.addDependency(of(selfLink), of('objectWithoutDependents'));
424-
expect(store.dispatch).toHaveBeenCalledOnceWith(new AddDependentsObjectCacheAction('objectWithoutDependents', [requestUUID]));
424+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledOnceWith(new AddDependentsObjectCacheAction('objectWithoutDependents', [requestUUID]));
425425
});
426426

427427
it('should only dispatch once for the first value of either observable href', () => {
@@ -442,7 +442,7 @@ describe('ObjectCacheService', () => {
442442
service.addDependency(href$, dependsOnHref$);
443443
flush();
444444

445-
expect(store.dispatch).toHaveBeenCalledOnceWith(new AddDependentsObjectCacheAction('objectWithoutDependents', [requestUUID]));
445+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledOnceWith(new AddDependentsObjectCacheAction('objectWithoutDependents', [requestUUID]));
446446
});
447447
});
448448

@@ -467,12 +467,12 @@ describe('ObjectCacheService', () => {
467467
describe('removeDependents', () => {
468468
it('should dispatch a REMOVE_DEPENDENTS action', () => {
469469
service.removeDependents('objectWithDependents');
470-
expect(store.dispatch).toHaveBeenCalledOnceWith(new RemoveDependentsObjectCacheAction('objectWithDependents'));
470+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledOnceWith(new RemoveDependentsObjectCacheAction('objectWithDependents'));
471471
});
472472

473473
it('should resolve alt links', () => {
474474
service.removeDependents('objectWithDependentsAlt');
475-
expect(store.dispatch).toHaveBeenCalledOnceWith(new RemoveDependentsObjectCacheAction('objectWithDependents'));
475+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledOnceWith(new RemoveDependentsObjectCacheAction('objectWithDependents'));
476476
});
477477

478478
it('should not dispatch if the href cannot be resolved to a cached self link', () => {

src/app/core/data/bitstream-format-data.service.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ describe('BitstreamFormatDataService', () => {
247247
format.uuid = 'uuid';
248248

249249
service.selectBitstreamFormat(format);
250-
expect(store.dispatch).toHaveBeenCalledWith(new BitstreamFormatsRegistrySelectAction(format));
250+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new BitstreamFormatsRegistrySelectAction(format));
251251
});
252252
});
253253

@@ -270,7 +270,7 @@ describe('BitstreamFormatDataService', () => {
270270
format.uuid = 'uuid';
271271

272272
service.deselectBitstreamFormat(format);
273-
expect(store.dispatch).toHaveBeenCalledWith(new BitstreamFormatsRegistryDeselectAction(format));
273+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new BitstreamFormatsRegistryDeselectAction(format));
274274
});
275275
});
276276

@@ -291,7 +291,7 @@ describe('BitstreamFormatDataService', () => {
291291
}));
292292
it('should remove all bitstreamFormats from the store', () => {
293293
service.deselectAllBitstreamFormats();
294-
expect(store.dispatch).toHaveBeenCalledWith(new BitstreamFormatsRegistryDeselectAllAction());
294+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new BitstreamFormatsRegistryDeselectAllAction());
295295
});
296296
});
297297

src/app/core/data/object-updates/object-updates.service.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('ObjectUpdatesService', () => {
7070
describe('initialize', () => {
7171
it('should dispatch an INITIALIZE action with the correct URL, initial identifiables and the last modified date', () => {
7272
service.initialize(url, identifiables, modDate);
73-
expect(store.dispatch).toHaveBeenCalledWith(new InitializeFieldsAction(url, identifiables, modDate));
73+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new InitializeFieldsAction(url, identifiables, modDate));
7474
});
7575
});
7676

@@ -168,34 +168,34 @@ describe('ObjectUpdatesService', () => {
168168
describe('setEditableFieldUpdate', () => {
169169
it('should dispatch a SetEditableFieldUpdateAction action with the correct URL, uuid and true when true was set', () => {
170170
service.setEditableFieldUpdate(url, identifiable1.uuid, true);
171-
expect(store.dispatch).toHaveBeenCalledWith(new SetEditableFieldUpdateAction(url, identifiable1.uuid, true));
171+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new SetEditableFieldUpdateAction(url, identifiable1.uuid, true));
172172
});
173173

174174
it('should dispatch an SetEditableFieldUpdateAction action with the correct URL, uuid and false when false was set', () => {
175175
service.setEditableFieldUpdate(url, identifiable1.uuid, false);
176-
expect(store.dispatch).toHaveBeenCalledWith(new SetEditableFieldUpdateAction(url, identifiable1.uuid, false));
176+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new SetEditableFieldUpdateAction(url, identifiable1.uuid, false));
177177
});
178178
});
179179

180180
describe('discardFieldUpdates', () => {
181181
it('should dispatch a DiscardObjectUpdatesAction action with the correct URL and passed notification ', () => {
182182
const undoNotification = new Notification('id', NotificationType.Info, 'undo');
183183
service.discardFieldUpdates(url, undoNotification);
184-
expect(store.dispatch).toHaveBeenCalledWith(new DiscardObjectUpdatesAction(url, undoNotification));
184+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new DiscardObjectUpdatesAction(url, undoNotification));
185185
});
186186
});
187187

188188
describe('reinstateFieldUpdates', () => {
189189
it('should dispatch a ReinstateObjectUpdatesAction action with the correct URL ', () => {
190190
service.reinstateFieldUpdates(url);
191-
expect(store.dispatch).toHaveBeenCalledWith(new ReinstateObjectUpdatesAction(url));
191+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new ReinstateObjectUpdatesAction(url));
192192
});
193193
});
194194

195195
describe('removeSingleFieldUpdate', () => {
196196
it('should dispatch a RemoveFieldUpdateAction action with the correct URL and uuid', () => {
197197
service.removeSingleFieldUpdate(url, identifiable1.uuid);
198-
expect(store.dispatch).toHaveBeenCalledWith(new RemoveFieldUpdateAction(url, identifiable1.uuid));
198+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new RemoveFieldUpdateAction(url, identifiable1.uuid));
199199
});
200200
});
201201

@@ -287,7 +287,7 @@ describe('ObjectUpdatesService', () => {
287287
describe('setSelectedVirtualMetadata', () => {
288288
it('should dispatch a SELECT_VIRTUAL_METADATA action with the correct URL, relationship, identifiable and boolean', () => {
289289
service.setSelectedVirtualMetadata(url, relationship.uuid, identifiable1.uuid, true);
290-
expect(store.dispatch).toHaveBeenCalledWith(new SelectVirtualMetadataAction(url, relationship.uuid, identifiable1.uuid, true));
290+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new SelectVirtualMetadataAction(url, relationship.uuid, identifiable1.uuid, true));
291291
});
292292
});
293293

src/app/core/data/request.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ describe('RequestService', () => {
690690
service.setStaleByHref(href).subscribe(() => {
691691
const requestStaleAction = new RequestStaleAction(uuid);
692692
requestStaleAction.lastUpdated = jasmine.any(Number) as any;
693-
expect(store.dispatch).toHaveBeenCalledWith(requestStaleAction);
693+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(requestStaleAction);
694694
done();
695695
});
696696
});

src/app/core/eperson/eperson-data.service.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,14 @@ describe('EPersonDataService', () => {
343343
describe('cancelEditEPerson', () => {
344344
it('should dispatch a CANCEL_EDIT_EPERSON action', () => {
345345
service.cancelEditEPerson();
346-
expect(store.dispatch).toHaveBeenCalledWith(new EPeopleRegistryCancelEPersonAction());
346+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new EPeopleRegistryCancelEPersonAction());
347347
});
348348
});
349349

350350
describe('editEPerson', () => {
351351
it('should dispatch a EDIT_EPERSON action with the EPerson to start editing', () => {
352352
service.editEPerson(EPersonMock);
353-
expect(store.dispatch).toHaveBeenCalledWith(new EPeopleRegistryEditEPersonAction(EPersonMock));
353+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new EPeopleRegistryEditEPersonAction(EPersonMock));
354354
});
355355
});
356356

src/app/core/eperson/group-data.service.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,14 @@ describe('GroupDataService', () => {
270270
describe('editGroup', () => {
271271
it('should dispatch a EDIT_GROUP action with the group to start editing', () => {
272272
service.editGroup(GroupMock);
273-
expect(store.dispatch).toHaveBeenCalledWith(new GroupRegistryEditGroupAction(GroupMock));
273+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new GroupRegistryEditGroupAction(GroupMock));
274274
});
275275
});
276276

277277
describe('cancelEditGroup', () => {
278278
it('should dispatch a CANCEL_EDIT_GROUP action', () => {
279279
service.cancelEditGroup();
280-
expect(store.dispatch).toHaveBeenCalledWith(new GroupRegistryCancelGroupAction());
280+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new GroupRegistryCancelGroupAction());
281281
});
282282
});
283283
});

src/app/core/shared/search/search-filter.service.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('SearchFilterService', () => {
7070
});
7171

7272
it('SearchFilterInitializeAction should be dispatched to the store', () => {
73-
expect(store.dispatch).toHaveBeenCalledWith(new SearchFilterInitializeAction(mockFilterConfig));
73+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new SearchFilterInitializeAction(mockFilterConfig));
7474
});
7575
});
7676

@@ -80,7 +80,7 @@ describe('SearchFilterService', () => {
8080
});
8181

8282
it('SearchFilterCollapseAction should be dispatched to the store', () => {
83-
expect(store.dispatch).toHaveBeenCalledWith(new SearchFilterCollapseAction(mockFilterConfig.name));
83+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new SearchFilterCollapseAction(mockFilterConfig.name));
8484
});
8585

8686
});
@@ -91,7 +91,7 @@ describe('SearchFilterService', () => {
9191
});
9292

9393
it('SearchFilterInitialExpandAction should be dispatched to the store', () => {
94-
expect(store.dispatch).toHaveBeenCalledWith(new SearchFilterToggleAction(mockFilterConfig.name));
94+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new SearchFilterToggleAction(mockFilterConfig.name));
9595
});
9696
});
9797

@@ -101,7 +101,7 @@ describe('SearchFilterService', () => {
101101
});
102102

103103
it('SearchFilterDecrementPageAction should be dispatched to the store', () => {
104-
expect(store.dispatch).toHaveBeenCalledWith(new SearchFilterDecrementPageAction(mockFilterConfig.name));
104+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new SearchFilterDecrementPageAction(mockFilterConfig.name));
105105
});
106106

107107
});
@@ -112,7 +112,7 @@ describe('SearchFilterService', () => {
112112
});
113113

114114
it('SearchFilterCollapseAction should be dispatched to the store', () => {
115-
expect(store.dispatch).toHaveBeenCalledWith(new SearchFilterIncrementPageAction(mockFilterConfig.name));
115+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new SearchFilterIncrementPageAction(mockFilterConfig.name));
116116
});
117117

118118
});
@@ -123,7 +123,7 @@ describe('SearchFilterService', () => {
123123
});
124124

125125
it('SearchFilterDecrementPageAction should be dispatched to the store', () => {
126-
expect(store.dispatch).toHaveBeenCalledWith(new SearchFilterResetPageAction(mockFilterConfig.name));
126+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new SearchFilterResetPageAction(mockFilterConfig.name));
127127
});
128128

129129
});
@@ -134,7 +134,7 @@ describe('SearchFilterService', () => {
134134
});
135135

136136
it('SidebarExpandAction should be dispatched to the store', () => {
137-
expect(store.dispatch).toHaveBeenCalledWith(new SearchFilterExpandAction(mockFilterConfig.name));
137+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new SearchFilterExpandAction(mockFilterConfig.name));
138138
});
139139
});
140140

src/app/forgot-password/forgot-password-form/forgot-password-form.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('ForgotPasswordFormComponent', () => {
112112
comp.submit();
113113

114114
expect(ePersonDataService.patchPasswordWithToken).toHaveBeenCalledWith('test-uuid', 'test-token', 'password');
115-
expect(store.dispatch).toHaveBeenCalledWith(new AuthenticateAction('test@email.org', 'password'));
115+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new AuthenticateAction('test@email.org', 'password'));
116116
expect(router.navigate).toHaveBeenCalledWith(['/home']);
117117
expect(notificationsService.success).toHaveBeenCalled();
118118
});

0 commit comments

Comments
 (0)