Skip to content

Commit d181c03

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
1 parent a5d0d3d commit d181c03

File tree

17 files changed

+64
-88
lines changed

17 files changed

+64
-88
lines changed

src/app/access-control/epeople-registry/epeople-registry.service.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('EpeopleRegistryService', () => {
5151
it('should dispatch EPeopleRegistryCancelEPersonAction', () => {
5252
const dispatchSpy = spyOn(store, 'dispatch');
5353
service.cancelEditEPerson();
54-
expect(dispatchSpy).toHaveBeenCalledWith(new EPeopleRegistryCancelEPersonAction());
54+
expect(dispatchSpy as jasmine.Spy).toHaveBeenCalledWith(new EPeopleRegistryCancelEPersonAction());
5555
});
5656
});
5757

@@ -60,7 +60,7 @@ describe('EpeopleRegistryService', () => {
6060
const dispatchSpy = spyOn(store, 'dispatch');
6161
const mockEPerson: EPerson = { id: '456', name: 'Another User' } as EPerson;
6262
service.editEPerson(mockEPerson);
63-
expect(dispatchSpy).toHaveBeenCalledWith(new EPeopleRegistryEditEPersonAction(mockEPerson));
63+
expect(dispatchSpy as jasmine.Spy).toHaveBeenCalledWith(new EPeopleRegistryEditEPersonAction(mockEPerson));
6464
});
6565
});
6666
});

src/app/access-control/group-registry/group-registry.service.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
editGroupSelector,
1515
GroupRegistryService,
1616
} from './group-registry.service';
17+
import Jasmine = jasmine.Jasmine;
1718

1819
describe('GroupRegistryService', () => {
1920
let service: GroupRegistryService;
@@ -52,13 +53,13 @@ describe('GroupRegistryService', () => {
5253
it('should dispatch cancel edit group action', () => {
5354
const dispatchSpy = spyOn(store, 'dispatch');
5455
service.cancelEditGroup();
55-
expect(dispatchSpy).toHaveBeenCalledWith(new GroupRegistryCancelGroupAction());
56+
expect(dispatchSpy as jasmine.Spy).toHaveBeenCalledWith(new GroupRegistryCancelGroupAction());
5657
});
5758

5859
it('should dispatch edit group action with group', () => {
5960
const dispatchSpy = spyOn(store, 'dispatch');
6061
const group: Group = { id: '123', name: 'New Group' } as Group;
6162
service.editGroup(group);
62-
expect(dispatchSpy).toHaveBeenCalledWith(new GroupRegistryEditGroupAction(group));
63+
expect(dispatchSpy as jasmine.Spy).toHaveBeenCalledWith(new GroupRegistryEditGroupAction(group));
6364
});
6465
});

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
@@ -266,15 +266,15 @@ describe('AuthService test', () => {
266266
it('store should dispatch SetUserAsIdleAction', () => {
267267
spyOn(mockStore, 'dispatch');
268268
authService.setIdle(true);
269-
expect(mockStore.dispatch).toHaveBeenCalledWith(new SetUserAsIdleAction());
269+
expect(mockStore.dispatch as jasmine.Spy).toHaveBeenCalledWith(new SetUserAsIdleAction());
270270
});
271271
});
272272

273273
describe('setIdle false', () => {
274274
it('store should dispatch UnsetUserAsIdleAction', () => {
275275
spyOn(mockStore, 'dispatch');
276276
authService.setIdle(false);
277-
expect(mockStore.dispatch).toHaveBeenCalledWith(new UnsetUserAsIdleAction());
277+
expect(mockStore.dispatch as jasmine.Spy).toHaveBeenCalledWith(new UnsetUserAsIdleAction());
278278
});
279279
});
280280
});

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ describe('ObjectCacheService', () => {
151151
describe('add', () => {
152152
it('should dispatch an ADD action with the object to add, the time to live, and the current timestamp', () => {
153153
service.add(objectToCache, msToLive, requestUUID, alternativeLink);
154-
expect(store.dispatch).toHaveBeenCalledWith(new AddToObjectCacheAction(objectToCache, timestamp, msToLive, requestUUID, alternativeLink));
154+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new AddToObjectCacheAction(objectToCache, timestamp, msToLive, requestUUID, alternativeLink));
155155
expect(linkServiceStub.removeResolvedLinks).toHaveBeenCalledWith(objectToCache);
156156
});
157157
});
@@ -163,20 +163,20 @@ describe('ObjectCacheService', () => {
163163

164164
it('should dispatch a REMOVE action with the self link of the object to remove', () => {
165165
service.remove(selfLink);
166-
expect(store.dispatch).toHaveBeenCalledWith(new RemoveFromObjectCacheAction(selfLink));
166+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new RemoveFromObjectCacheAction(selfLink));
167167
});
168168

169169
it('should dispatch a REMOVE_BY_SUBSTRING action on the index state for each alternativeLink in the object', () => {
170170
service.remove(selfLink);
171171
cacheEntry.alternativeLinks.forEach(
172-
(link: string) => expect(store.dispatch).toHaveBeenCalledWith(new RemoveFromIndexBySubstringAction(IndexName.ALTERNATIVE_OBJECT_LINK, link)));
172+
(link: string) => expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new RemoveFromIndexBySubstringAction(IndexName.ALTERNATIVE_OBJECT_LINK, link)));
173173
});
174174

175175
it('should dispatch a REMOVE_BY_SUBSTRING action on the index state for each _links in the object, except the self link', () => {
176176
service.remove(selfLink);
177177
Object.entries(objectToCache._links).forEach(([key, value]: [string, HALLink]) => {
178178
if (key !== 'self') {
179-
expect(store.dispatch).toHaveBeenCalledWith(new RemoveFromIndexBySubstringAction(IndexName.ALTERNATIVE_OBJECT_LINK, value.href));
179+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new RemoveFromIndexBySubstringAction(IndexName.ALTERNATIVE_OBJECT_LINK, value.href));
180180
}
181181
});
182182
});
@@ -345,8 +345,8 @@ describe('ObjectCacheService', () => {
345345
describe('patch methods', () => {
346346
it('should dispatch the correct actions when addPatch is called', () => {
347347
service.addPatch(selfLink, operations);
348-
expect(store.dispatch).toHaveBeenCalledWith(new AddPatchObjectCacheAction(selfLink, operations));
349-
expect(store.dispatch).toHaveBeenCalledWith(new AddToSSBAction(selfLink, RestRequestMethod.PATCH));
348+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new AddPatchObjectCacheAction(selfLink, operations));
349+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new AddToSSBAction(selfLink, RestRequestMethod.PATCH));
350350
});
351351

352352
it('isDirty should return true when the patches list in the cache entry is not empty', () => {
@@ -366,7 +366,7 @@ describe('ObjectCacheService', () => {
366366
});
367367
it('should dispatch the correct actions when applyPatchesToCachedObject is called', () => {
368368
(service as any).applyPatchesToCachedObject(selfLink);
369-
expect(store.dispatch).toHaveBeenCalledWith(new ApplyPatchObjectCacheAction(selfLink));
369+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new ApplyPatchObjectCacheAction(selfLink));
370370
});
371371
});
372372

@@ -398,12 +398,12 @@ describe('ObjectCacheService', () => {
398398
describe('addDependency', () => {
399399
it('should dispatch an ADD_DEPENDENTS action', () => {
400400
service.addDependency(selfLink, 'objectWithoutDependents');
401-
expect(store.dispatch).toHaveBeenCalledOnceWith(new AddDependentsObjectCacheAction('objectWithoutDependents', [requestUUID]));
401+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledOnceWith(new AddDependentsObjectCacheAction('objectWithoutDependents', [requestUUID]));
402402
});
403403

404404
it('should resolve alt links', () => {
405405
service.addDependency(anotherLink, 'objectWithoutDependentsAlt');
406-
expect(store.dispatch).toHaveBeenCalledOnceWith(new AddDependentsObjectCacheAction('objectWithoutDependents', [requestUUID]));
406+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledOnceWith(new AddDependentsObjectCacheAction('objectWithoutDependents', [requestUUID]));
407407
});
408408

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

428428
it('should work with observable hrefs', () => {
429429
service.addDependency(of(selfLink), of('objectWithoutDependents'));
430-
expect(store.dispatch).toHaveBeenCalledOnceWith(new AddDependentsObjectCacheAction('objectWithoutDependents', [requestUUID]));
430+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledOnceWith(new AddDependentsObjectCacheAction('objectWithoutDependents', [requestUUID]));
431431
});
432432

433433
it('should only dispatch once for the first value of either observable href', () => {
@@ -448,7 +448,7 @@ describe('ObjectCacheService', () => {
448448
service.addDependency(href$, dependsOnHref$);
449449
flush();
450450

451-
expect(store.dispatch).toHaveBeenCalledOnceWith(new AddDependentsObjectCacheAction('objectWithoutDependents', [requestUUID]));
451+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledOnceWith(new AddDependentsObjectCacheAction('objectWithoutDependents', [requestUUID]));
452452
});
453453
});
454454

@@ -473,12 +473,12 @@ describe('ObjectCacheService', () => {
473473
describe('removeDependents', () => {
474474
it('should dispatch a REMOVE_DEPENDENTS action', () => {
475475
service.removeDependents('objectWithDependents');
476-
expect(store.dispatch).toHaveBeenCalledOnceWith(new RemoveDependentsObjectCacheAction('objectWithDependents'));
476+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledOnceWith(new RemoveDependentsObjectCacheAction('objectWithDependents'));
477477
});
478478

479479
it('should resolve alt links', () => {
480480
service.removeDependents('objectWithDependentsAlt');
481-
expect(store.dispatch).toHaveBeenCalledOnceWith(new RemoveDependentsObjectCacheAction('objectWithDependents'));
481+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledOnceWith(new RemoveDependentsObjectCacheAction('objectWithDependents'));
482482
});
483483

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

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
@@ -704,7 +704,7 @@ describe('RequestService', () => {
704704
service.setStaleByHref(href).subscribe(() => {
705705
const requestStaleAction = new RequestStaleAction(uuid);
706706
requestStaleAction.lastUpdated = jasmine.any(Number) as any;
707-
expect(store.dispatch).toHaveBeenCalledWith(requestStaleAction);
707+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(requestStaleAction);
708708
done();
709709
});
710710
});

src/app/core/notification-system/notifications.service.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,36 +62,36 @@ describe('NotificationsService test', () => {
6262
it('Success method should dispatch NewNotificationAction with proper parameter', () => {
6363
const notification = service.success('Title', of('Content'));
6464
expect(notification.type).toBe(NotificationType.Success);
65-
expect(store.dispatch).toHaveBeenCalledWith(new NewNotificationAction(notification));
65+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new NewNotificationAction(notification));
6666
});
6767

6868
it('Warning method should dispatch NewNotificationAction with proper parameter', () => {
6969
const notification = service.warning('Title', of('Content'));
7070
expect(notification.type).toBe(NotificationType.Warning);
71-
expect(store.dispatch).toHaveBeenCalledWith(new NewNotificationAction(notification));
71+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new NewNotificationAction(notification));
7272
});
7373

7474
it('Info method should dispatch NewNotificationAction with proper parameter', () => {
7575
const notification = service.info('Title', of('Content'));
7676
expect(notification.type).toBe(NotificationType.Info);
77-
expect(store.dispatch).toHaveBeenCalledWith(new NewNotificationAction(notification));
77+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new NewNotificationAction(notification));
7878
});
7979

8080
it('Error method should dispatch NewNotificationAction with proper parameter', () => {
8181
const notification = service.error('Title', of('Content'));
8282
expect(notification.type).toBe(NotificationType.Error);
83-
expect(store.dispatch).toHaveBeenCalledWith(new NewNotificationAction(notification));
83+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new NewNotificationAction(notification));
8484
});
8585

8686
it('Remove method should dispatch RemoveNotificationAction with proper id', () => {
8787
const notification = new Notification('1234', NotificationType.Info, 'title...', 'description');
8888
service.remove(notification);
89-
expect(store.dispatch).toHaveBeenCalledWith(new RemoveNotificationAction(notification.id));
89+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new RemoveNotificationAction(notification.id));
9090
});
9191

9292
it('RemoveAll method should dispatch RemoveAllNotificationsAction', () => {
9393
service.removeAll();
94-
expect(store.dispatch).toHaveBeenCalledWith(new RemoveAllNotificationsAction());
94+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new RemoveAllNotificationsAction());
9595
});
9696

9797
});

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('[email protected]', 'password'));
115+
expect(store.dispatch as jasmine.Spy).toHaveBeenCalledWith(new AuthenticateAction('[email protected]', 'password'));
116116
expect(router.navigate).toHaveBeenCalledWith(['/home']);
117117
expect(notificationsService.success).toHaveBeenCalled();
118118
});

src/app/init.service.spec.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { CommonModule } from '@angular/common';
2-
import {
3-
APP_INITIALIZER,
4-
Injectable,
5-
} from '@angular/core';
2+
import { Injectable } from '@angular/core';
63
import {
74
inject,
85
TestBed,
@@ -98,12 +95,6 @@ describe('InitService', () => {
9895
expect(providers).toContain(objectContaining({
9996
provide: APP_CONFIG,
10097
}));
101-
102-
expect(providers).toContain(objectContaining({
103-
provide: APP_INITIALIZER,
104-
deps: [ InitService ],
105-
multi: true,
106-
}));
10798
});
10899

109100
it('should call resolveAppConfig() in APP_CONFIG factory', () => {
@@ -117,22 +108,6 @@ describe('InitService', () => {
117108
expect(spy.resolveAppConfig).toHaveBeenCalled();
118109
expect(spy.init).not.toHaveBeenCalled();
119110
});
120-
121-
it('should defer to init() in APP_INITIALIZER factory', () => {
122-
const factory = (
123-
ConcreteInitServiceMock.providers()
124-
.find((p: any) => p.provide === APP_INITIALIZER) as any
125-
).useFactory;
126-
127-
// we don't care about the dependencies here
128-
// @ts-ignore
129-
const instance = new ConcreteInitServiceMock(null, null, null);
130-
131-
// provider ensures that the right concrete instance is passed to the factory
132-
factory(instance);
133-
expect(spy.resolveAppConfig).not.toHaveBeenCalled();
134-
expect(spy.init).toHaveBeenCalled();
135-
});
136111
});
137112

138113
describe('common initialization steps', () => {

0 commit comments

Comments
 (0)