Skip to content

Commit

Permalink
Fixed tests without expectations from DSpace#2759 & DSpace#2681
Browse files Browse the repository at this point in the history
Added the necessary done() calls back & fixed tests
  • Loading branch information
alexandrevryghem committed Feb 29, 2024
1 parent 87788e7 commit 371e766
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
14 changes: 7 additions & 7 deletions src/app/core/coar-notify/notify-info/notify-info.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { TestBed } from '@angular/core/testing';

import { NotifyInfoService } from './notify-info.service';
import { ConfigurationDataService } from '../../data/configuration-data.service';
import { of } from 'rxjs';
import { AuthorizationDataService } from '../../data/feature-authorization/authorization-data.service';
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';

describe('NotifyInfoService', () => {
let service: NotifyInfoService;
Expand Down Expand Up @@ -32,21 +32,21 @@ describe('NotifyInfoService', () => {
expect(service).toBeTruthy();
});

it('should retrieve and map coar configuration', () => {
const mockResponse = { payload: { values: ['true'] } };
(configurationDataService.findByPropertyName as jasmine.Spy).and.returnValue(of(mockResponse));
it('should retrieve and map coar configuration', (done: DoneFn) => {
(configurationDataService.findByPropertyName as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$({ values: ['true'] }));

service.isCoarConfigEnabled().subscribe((result) => {
expect(result).toBe(true);
done();
});
});

it('should retrieve and map LDN local inbox URLs', () => {
const mockResponse = { values: ['inbox1', 'inbox2'] };
(configurationDataService.findByPropertyName as jasmine.Spy).and.returnValue(of(mockResponse));
it('should retrieve and map LDN local inbox URLs', (done: DoneFn) => {
(configurationDataService.findByPropertyName as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$({ values: ['inbox1', 'inbox2'] }));

service.getCoarLdnLocalInboxUrls().subscribe((result) => {
expect(result).toEqual(['inbox1', 'inbox2']);
done();
});
});

Expand Down
15 changes: 8 additions & 7 deletions src/app/shared/dso-page/dso-edit-menu.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import { Community } from '../../core/shared/community.model';
import { Collection } from '../../core/shared/collection.model';
import flatten from 'lodash/flatten';
import { DsoWithdrawnReinstateModalService } from './dso-withdrawn-reinstate-service/dso-withdrawn-reinstate-modal.service';
import { AuthService } from 'src/app/core/auth/auth.service';
import { AuthServiceMock } from '../mocks/auth.service.mock';
import { CorrectionTypeDataService } from 'src/app/core/submission/correctiontype-data.service';
import { createPaginatedList } from '../testing/utils.test';

describe('DSOEditMenuResolver', () => {

Expand Down Expand Up @@ -152,7 +151,7 @@ describe('DSOEditMenuResolver', () => {
});

correctionsDataService = jasmine.createSpyObj('correctionsDataService', {
findByItem: observableOf([])
findByItem: createSuccessfulRemoteDataObject$(createPaginatedList([])),
});

TestBed.configureTestingModule({
Expand All @@ -167,7 +166,6 @@ describe('DSOEditMenuResolver', () => {
{provide: TranslateService, useValue: translate},
{provide: NotificationsService, useValue: notificationsService},
{provide: DsoWithdrawnReinstateModalService, useValue: dsoWithdrawnReinstateModalService},
{provide: AuthService, useValue: new AuthServiceMock()},
{provide: CorrectionTypeDataService, useValue: correctionsDataService},
{
provide: NgbModal, useValue: {
Expand Down Expand Up @@ -367,7 +365,7 @@ describe('DSOEditMenuResolver', () => {
route = dsoRoute(testItem);
});

it('should return Item-specific entries', () => {
it('should return Item-specific entries', (done: DoneFn) => {
const result = resolver.getDsoMenus(testObject, route, state);
combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
const orcidEntry = menu.find(entry => entry.id === 'orcid-dso');
Expand All @@ -388,18 +386,20 @@ describe('DSOEditMenuResolver', () => {
expect(claimEntry.active).toBeFalse();
expect(claimEntry.visible).toBeFalse();
expect(claimEntry.model.type).toEqual(MenuItemType.ONCLICK);
done();
});
});

it('should not return Community/Collection-specific entries', () => {
it('should not return Community/Collection-specific entries', (done: DoneFn) => {
const result = resolver.getDsoMenus(testObject, route, state);
combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
const subscribeEntry = menu.find(entry => entry.id === 'subscribe');
expect(subscribeEntry).toBeFalsy();
done();
});
});

it('should return as third part the common list ', () => {
it('should return as third part the common list ', (done: DoneFn) => {
const result = resolver.getDsoMenus(testObject, route, state);
combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
const editEntry = menu.find(entry => entry.id === 'edit-dso');
Expand All @@ -410,6 +410,7 @@ describe('DSOEditMenuResolver', () => {
expect((editEntry.model as LinkMenuItemModel).link).toEqual(
'/items/test-item-uuid/edit/metadata'
);
done();
});
});
});
Expand Down
7 changes: 0 additions & 7 deletions src/app/shared/dso-page/dso-edit-menu.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ import { ResearcherProfileDataService } from '../../core/profile/researcher-prof
import { NotificationsService } from '../notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core';
import { DsoWithdrawnReinstateModalService, REQUEST_REINSTATE, REQUEST_WITHDRAWN } from './dso-withdrawn-reinstate-service/dso-withdrawn-reinstate-modal.service';
import { AuthService } from '../../core/auth/auth.service';
import { FindListOptions } from '../../core/data/find-list-options.model';
import { RequestParam } from '../../core/cache/models/request-param.model';
import { CorrectionTypeDataService } from '../../core/submission/correctiontype-data.service';
import { SubscriptionModalComponent } from '../subscriptions/subscription-modal/subscription-modal.component';
import { Community } from '../../core/shared/community.model';
Expand All @@ -50,7 +47,6 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
protected notificationsService: NotificationsService,
protected translate: TranslateService,
protected dsoWithdrawnReinstateModalService: DsoWithdrawnReinstateModalService,
private auth: AuthService,
private correctionTypeDataService: CorrectionTypeDataService
) {
}
Expand Down Expand Up @@ -133,9 +129,6 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
*/
protected getItemMenu(dso): Observable<MenuSection[]> {
if (dso instanceof Item) {
const findListTopicOptions: FindListOptions = {
searchParams: [new RequestParam('target', dso.uuid)]
};
return combineLatest([
this.authorizationService.isAuthorized(FeatureID.CanCreateVersion, dso.self),
this.dsoVersioningModalService.isNewVersionButtonDisabled(dso),
Expand Down

0 comments on commit 371e766

Please sign in to comment.