[CST-12109] fixed failing unit tests after merge

This commit is contained in:
Alisa Ismailati
2024-01-17 18:39:54 +01:00
parent 3ecc1ca68b
commit 805e98b837
9 changed files with 104 additions and 40 deletions

View File

@@ -82,20 +82,27 @@ describe('QualityAssuranceTopicDataService', () => {
spyOn((service as any).findAllData, 'findAll').and.callThrough(); spyOn((service as any).findAllData, 'findAll').and.callThrough();
spyOn((service as any), 'findById').and.callThrough(); spyOn((service as any), 'findById').and.callThrough();
spyOn((service as any).searchData, 'searchBy').and.callThrough();
}); });
describe('getTopics', () => { describe('searchTopicsByTarget', () => {
it('should call findListByHref', (done) => { it('should call searchData.searchBy with the correct parameters', () => {
service.getTopics().subscribe( const options = { elementsPerPage: 10 };
(res) => { const useCachedVersionIfAvailable = true;
expect((service as any).findAllData.findAll).toHaveBeenCalledWith({}, true, true); const reRequestOnStale = true;
}
service.searchTopicsByTarget(options, useCachedVersionIfAvailable, reRequestOnStale);
expect((service as any).searchData.searchBy).toHaveBeenCalledWith(
'byTarget',
options,
useCachedVersionIfAvailable,
reRequestOnStale
); );
done();
}); });
it('should return a RemoteData<PaginatedList<QualityAssuranceTopicObject>> for the object with the given URL', () => { it('should return a RemoteData<PaginatedList<QualityAssuranceTopicObject>> for the object with the given URL', () => {
const result = service.getTopics(); const result = service.searchTopicsByTarget();
const expected = cold('(a)', { const expected = cold('(a)', {
a: paginatedListRD a: paginatedListRD
}); });

View File

@@ -1,16 +1,44 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { QaEventNotificationComponent } from './qa-event-notification.component'; import { QaEventNotificationComponent } from './qa-event-notification.component';
import { createSuccessfulRemoteDataObject$ } from 'src/app/shared/remote-data.utils';
import { createPaginatedList } from 'src/app/shared/testing/utils.test';
import { QualityAssuranceSourceObject } from 'src/app/core/notifications/qa/models/quality-assurance-source.model';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { QualityAssuranceSourceDataService } from 'src/app/core/notifications/qa/source/quality-assurance-source-data.service';
import { RequestService } from 'src/app/core/data/request.service';
import { NotificationsService } from 'src/app/shared/notifications/notifications.service';
import { ObjectCacheService } from 'src/app/core/cache/object-cache.service';
import { RemoteDataBuildService } from 'src/app/core/cache/builders/remote-data-build.service';
import { provideMockStore } from '@ngrx/store/testing';
import { HALEndpointService } from 'src/app/core/shared/hal-endpoint.service';
import { HALEndpointServiceStub } from 'src/app/shared/testing/hal-endpoint-service.stub';
describe('QaEventNotificationComponent', () => { describe('QaEventNotificationComponent', () => {
let component: QaEventNotificationComponent; let component: QaEventNotificationComponent;
let fixture: ComponentFixture<QaEventNotificationComponent>; let fixture: ComponentFixture<QaEventNotificationComponent>;
let qualityAssuranceSourceDataServiceStub: any;
const obj = createSuccessfulRemoteDataObject$(createPaginatedList([new QualityAssuranceSourceObject()]));
const item = Object.assign({ uuid: '1234' });
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
declarations: [ QaEventNotificationComponent ] imports: [CommonModule, TranslateModule.forRoot()],
declarations: [ QaEventNotificationComponent ],
providers: [
{ provide: QualityAssuranceSourceDataService, useValue: qualityAssuranceSourceDataServiceStub },
{ provide: RequestService, useValue: {} },
{ provide: NotificationsService, useValue: {} },
{ provide: HALEndpointService, useValue: new HALEndpointServiceStub('test')},
ObjectCacheService,
RemoteDataBuildService,
provideMockStore({})
],
}) })
.compileComponents(); .compileComponents();
fixture = TestBed.createComponent(QaEventNotificationComponent); fixture = TestBed.createComponent(QaEventNotificationComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
component.item = item;
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should create', () => { it('should create', () => {

View File

@@ -271,8 +271,8 @@ describe('NotificationsStateService', () => {
it('Should call store.dispatch', () => { it('Should call store.dispatch', () => {
const elementsPerPage = 3; const elementsPerPage = 3;
const currentPage = 1; const currentPage = 1;
const action = new RetrieveAllTopicsAction(elementsPerPage, currentPage); const action = new RetrieveAllTopicsAction(elementsPerPage, currentPage, 'source', 'target');
service.dispatchRetrieveQualityAssuranceTopics(elementsPerPage, currentPage); service.dispatchRetrieveQualityAssuranceTopics(elementsPerPage, currentPage, 'source', 'target');
expect(serviceAsAny.store.dispatch).toHaveBeenCalledWith(action); expect(serviceAsAny.store.dispatch).toHaveBeenCalledWith(action);
}); });
}); });

View File

@@ -42,6 +42,8 @@ import { SortDirection, SortOptions } from '../../../core/cache/models/sort-opti
import { PaginationService } from '../../../core/pagination/pagination.service'; import { PaginationService } from '../../../core/pagination/pagination.service';
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub'; import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
import { FindListOptions } from '../../../core/data/find-list-options.model'; import { FindListOptions } from '../../../core/data/find-list-options.model';
import { ItemDataService } from 'src/app/core/data/item-data.service';
import { AuthorizationDataService } from 'src/app/core/data/feature-authorization/authorization-data.service';
describe('QualityAssuranceEventsComponent test suite', () => { describe('QualityAssuranceEventsComponent test suite', () => {
let fixture: ComponentFixture<QualityAssuranceEventsComponent>; let fixture: ComponentFixture<QualityAssuranceEventsComponent>;
@@ -118,6 +120,8 @@ describe('QualityAssuranceEventsComponent test suite', () => {
{ provide: NotificationsService, useValue: new NotificationsServiceStub() }, { provide: NotificationsService, useValue: new NotificationsServiceStub() },
{ provide: TranslateService, useValue: getMockTranslateService() }, { provide: TranslateService, useValue: getMockTranslateService() },
{ provide: PaginationService, useValue: paginationService }, { provide: PaginationService, useValue: paginationService },
{ provide: ItemDataService, useValue: {} },
{ provide: AuthorizationDataService, useValue: {} },
QualityAssuranceEventsComponent QualityAssuranceEventsComponent
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]

View File

@@ -16,7 +16,7 @@ import { NotificationsStateService } from '../../notifications-state.service';
import { cold } from 'jasmine-marbles'; import { cold } from 'jasmine-marbles';
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub'; import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
import { PaginationService } from '../../../core/pagination/pagination.service'; import { PaginationService } from '../../../core/pagination/pagination.service';
import { QualityAssuranceTopicsService } from './quality-assurance-topics.service'; import { ItemDataService } from 'src/app/core/data/item-data.service';
describe('QualityAssuranceTopicsComponent test suite', () => { describe('QualityAssuranceTopicsComponent test suite', () => {
let fixture: ComponentFixture<QualityAssuranceTopicsComponent>; let fixture: ComponentFixture<QualityAssuranceTopicsComponent>;
@@ -44,14 +44,14 @@ describe('QualityAssuranceTopicsComponent test suite', () => {
providers: [ providers: [
{ provide: NotificationsStateService, useValue: mockNotificationsStateService }, { provide: NotificationsStateService, useValue: mockNotificationsStateService },
{ provide: ActivatedRoute, useValue: { data: observableOf(activatedRouteParams), snapshot: { { provide: ActivatedRoute, useValue: { data: observableOf(activatedRouteParams), snapshot: {
paramMap: { params: {
get: () => 'openaire', sourceId: 'openaire',
targetId: null
}, },
}}}, }}},
{ provide: PaginationService, useValue: paginationService }, { provide: PaginationService, useValue: paginationService },
{ provide: ItemDataService, useValue: {} },
QualityAssuranceTopicsComponent, QualityAssuranceTopicsComponent,
// tslint:disable-next-line: no-empty
{ provide: QualityAssuranceTopicsService, useValue: { setSourceId: (sourceId: string) => { } }}
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}).compileComponents().then(() => { }).compileComponents().then(() => {

View File

@@ -29,7 +29,7 @@ describe('qualityAssuranceTopicsReducer test suite', () => {
const expectedState = qualityAssuranceTopicInitialState; const expectedState = qualityAssuranceTopicInitialState;
expectedState.processing = true; expectedState.processing = true;
const action = new RetrieveAllTopicsAction(elementPerPage, currentPage); const action = new RetrieveAllTopicsAction(elementPerPage, currentPage, 'ENRICH!MORE!ABSTRACT');
const newState = qualityAssuranceTopicsReducer(qualityAssuranceTopicInitialState, action); const newState = qualityAssuranceTopicsReducer(qualityAssuranceTopicInitialState, action);
expect(newState).toEqual(expectedState); expect(newState).toEqual(expectedState);

View File

@@ -42,30 +42,30 @@ describe('QualityAssuranceTopicsService', () => {
beforeEach(() => { beforeEach(() => {
restService = TestBed.inject(QualityAssuranceTopicDataService); restService = TestBed.inject(QualityAssuranceTopicDataService);
restServiceAsAny = restService; restServiceAsAny = restService;
restServiceAsAny.getTopics.and.returnValue(observableOf(paginatedListRD)); restServiceAsAny.searchTopicsBySource.and.returnValue(observableOf(paginatedListRD));
restServiceAsAny.searchTopicsByTarget.and.returnValue(observableOf(paginatedListRD));
service = new QualityAssuranceTopicsService(restService); service = new QualityAssuranceTopicsService(restService);
serviceAsAny = service; serviceAsAny = service;
}); });
describe('getTopics', () => { describe('getTopics', () => {
it('Should proxy the call to qualityAssuranceTopicRestService.getTopics', () => { it('should proxy the call to qualityAssuranceTopicRestService.searchTopicsBySource', () => {
const sortOptions = new SortOptions('name', SortDirection.ASC); const sortOptions = new SortOptions('name', SortDirection.ASC);
const findListOptions: FindListOptions = { const findListOptions: FindListOptions = {
elementsPerPage: elementsPerPage, elementsPerPage: elementsPerPage,
currentPage: currentPage, currentPage: currentPage,
sort: sortOptions, sort: sortOptions,
searchParams: [new RequestParam('source', 'ENRICH!MORE!ABSTRACT')] searchParams: [new RequestParam('source', 'openaire')]
}; };
service.setSourceId('ENRICH!MORE!ABSTRACT'); service.getTopics(elementsPerPage, currentPage, 'openaire');
const result = service.getTopics(elementsPerPage, currentPage); expect((service as any).qualityAssuranceTopicRestService.searchTopicsBySource).toHaveBeenCalledWith(findListOptions);
expect((service as any).qualityAssuranceTopicRestService.getTopics).toHaveBeenCalledWith(findListOptions);
}); });
it('Should return a paginated list of Quality Assurance topics', () => { it('should return a paginated list of Quality Assurance topics', () => {
const expected = cold('(a|)', { const expected = cold('(a|)', {
a: paginatedList a: paginatedList
}); });
const result = service.getTopics(elementsPerPage, currentPage); const result = service.getTopics(elementsPerPage, currentPage, 'openaire');
expect(result).toBeObservable(expected); expect(result).toBeObservable(expected);
}); });
}); });

View File

@@ -23,6 +23,10 @@ import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { Community } from '../../core/shared/community.model'; import { Community } from '../../core/shared/community.model';
import { Collection } from '../../core/shared/collection.model'; import { Collection } from '../../core/shared/collection.model';
import flatten from 'lodash/flatten'; 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';
describe('DSOEditMenuResolver', () => { describe('DSOEditMenuResolver', () => {
@@ -39,6 +43,8 @@ describe('DSOEditMenuResolver', () => {
let researcherProfileService; let researcherProfileService;
let notificationsService; let notificationsService;
let translate; let translate;
let dsoWithdrawnReinstateModalService;
let correctionsDataService;
const dsoRoute = (dso: DSpaceObject) => { const dsoRoute = (dso: DSpaceObject) => {
return { return {
@@ -141,6 +147,14 @@ describe('DSOEditMenuResolver', () => {
error: {}, error: {},
}); });
dsoWithdrawnReinstateModalService = jasmine.createSpyObj('dsoWithdrawnReinstateModalService', {
openCreateWithdrawnReinstateModal: {},
});
correctionsDataService = jasmine.createSpyObj('correctionsDataService', {
findByItem: observableOf([])
});
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), NoopAnimationsModule, RouterTestingModule], imports: [TranslateModule.forRoot(), NoopAnimationsModule, RouterTestingModule],
declarations: [AdminSidebarComponent], declarations: [AdminSidebarComponent],
@@ -152,6 +166,9 @@ describe('DSOEditMenuResolver', () => {
{provide: ResearcherProfileDataService, useValue: researcherProfileService}, {provide: ResearcherProfileDataService, useValue: researcherProfileService},
{provide: TranslateService, useValue: translate}, {provide: TranslateService, useValue: translate},
{provide: NotificationsService, useValue: notificationsService}, {provide: NotificationsService, useValue: notificationsService},
{provide: DsoWithdrawnReinstateModalService, useValue: dsoWithdrawnReinstateModalService},
{provide: AuthService, useValue: new AuthServiceMock()},
{provide: CorrectionTypeDataService, useValue: correctionsDataService},
{ {
provide: NgbModal, useValue: { provide: NgbModal, useValue: {
open: () => {/*comment*/ open: () => {/*comment*/
@@ -350,7 +367,7 @@ describe('DSOEditMenuResolver', () => {
route = dsoRoute(testItem); route = dsoRoute(testItem);
}); });
it('should return Item-specific entries', (done) => { it('should return Item-specific entries', () => {
const result = resolver.getDsoMenus(testObject, route, state); const result = resolver.getDsoMenus(testObject, route, state);
combineLatest(result).pipe(map(flatten)).subscribe((menu) => { combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
const orcidEntry = menu.find(entry => entry.id === 'orcid-dso'); const orcidEntry = menu.find(entry => entry.id === 'orcid-dso');
@@ -371,20 +388,18 @@ describe('DSOEditMenuResolver', () => {
expect(claimEntry.active).toBeFalse(); expect(claimEntry.active).toBeFalse();
expect(claimEntry.visible).toBeFalse(); expect(claimEntry.visible).toBeFalse();
expect(claimEntry.model.type).toEqual(MenuItemType.ONCLICK); expect(claimEntry.model.type).toEqual(MenuItemType.ONCLICK);
done();
}); });
}); });
it('should not return Community/Collection-specific entries', (done) => { it('should not return Community/Collection-specific entries', () => {
const result = resolver.getDsoMenus(testObject, route, state); const result = resolver.getDsoMenus(testObject, route, state);
combineLatest(result).pipe(map(flatten)).subscribe((menu) => { combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
const subscribeEntry = menu.find(entry => entry.id === 'subscribe'); const subscribeEntry = menu.find(entry => entry.id === 'subscribe');
expect(subscribeEntry).toBeFalsy(); expect(subscribeEntry).toBeFalsy();
done();
}); });
}); });
it('should return as third part the common list ', (done) => { it('should return as third part the common list ', () => {
const result = resolver.getDsoMenus(testObject, route, state); const result = resolver.getDsoMenus(testObject, route, state);
combineLatest(result).pipe(map(flatten)).subscribe((menu) => { combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
const editEntry = menu.find(entry => entry.id === 'edit-dso'); const editEntry = menu.find(entry => entry.id === 'edit-dso');
@@ -395,7 +410,6 @@ describe('DSOEditMenuResolver', () => {
expect((editEntry.model as LinkMenuItemModel).link).toEqual( expect((editEntry.model as LinkMenuItemModel).link).toEqual(
'/items/test-item-uuid/edit/metadata' '/items/test-item-uuid/edit/metadata'
); );
done();
}); });
}); });
}); });

View File

@@ -1482,7 +1482,8 @@ export const qualityAssuranceEventObjectMissingPid: QualityAssuranceEventObject
funder: null, funder: null,
fundingProgram: null, fundingProgram: null,
jurisdiction: null, jurisdiction: null,
title: null title: null,
reason: 'Missing PID'
}, },
_links: { _links: {
self: { self: {
@@ -1519,7 +1520,8 @@ export const qualityAssuranceEventObjectMissingPid2: QualityAssuranceEventObject
funder: null, funder: null,
fundingProgram: null, fundingProgram: null,
jurisdiction: null, jurisdiction: null,
title: null title: null,
reason: 'Missing PID'
}, },
_links: { _links: {
self: { self: {
@@ -1556,7 +1558,8 @@ export const qualityAssuranceEventObjectMissingPid3: QualityAssuranceEventObject
funder: null, funder: null,
fundingProgram: null, fundingProgram: null,
jurisdiction: null, jurisdiction: null,
title: null title: null,
reason: 'Missing PID'
}, },
_links: { _links: {
self: { self: {
@@ -1593,7 +1596,8 @@ export const qualityAssuranceEventObjectMissingPid4: QualityAssuranceEventObject
funder: null, funder: null,
fundingProgram: null, fundingProgram: null,
jurisdiction: null, jurisdiction: null,
title: null title: null,
reason: 'Missing DOI'
}, },
_links: { _links: {
self: { self: {
@@ -1630,7 +1634,8 @@ export const qualityAssuranceEventObjectMissingPid5: QualityAssuranceEventObject
funder: null, funder: null,
fundingProgram: null, fundingProgram: null,
jurisdiction: null, jurisdiction: null,
title: null title: null,
reason: 'Missing PID'
}, },
_links: { _links: {
self: { self: {
@@ -1667,7 +1672,8 @@ export const qualityAssuranceEventObjectMissingPid6: QualityAssuranceEventObject
funder: null, funder: null,
fundingProgram: null, fundingProgram: null,
jurisdiction: null, jurisdiction: null,
title: null title: null,
reason: 'Missing PID'
}, },
_links: { _links: {
self: { self: {
@@ -1704,7 +1710,8 @@ export const qualityAssuranceEventObjectMissingAbstract: QualityAssuranceEventOb
funder: null, funder: null,
fundingProgram: null, fundingProgram: null,
jurisdiction: null, jurisdiction: null,
title: null title: null,
reason: 'Missing abstract'
}, },
_links: { _links: {
self: { self: {
@@ -1741,6 +1748,7 @@ export const qualityAssuranceEventObjectMissingProjectFound: QualityAssuranceEve
funder: 'EC', funder: 'EC',
fundingProgram: 'H2020', fundingProgram: 'H2020',
jurisdiction: 'EU', jurisdiction: 'EU',
reason: 'Project found',
title: 'Tracking Papyrus and Parchment Paths: An Archaeological Atlas of Coptic Literature.\nLiterary Texts in their Geographical Context: Production, Copying, Usage, Dissemination and Storage' title: 'Tracking Papyrus and Parchment Paths: An Archaeological Atlas of Coptic Literature.\nLiterary Texts in their Geographical Context: Production, Copying, Usage, Dissemination and Storage'
}, },
_links: { _links: {
@@ -1778,7 +1786,8 @@ export const qualityAssuranceEventObjectMissingProjectNotFound: QualityAssurance
funder: 'EC', funder: 'EC',
fundingProgram: 'H2021', fundingProgram: 'H2021',
jurisdiction: 'EU', jurisdiction: 'EU',
title: 'Tracking Unknown Papyrus and Parchment Paths: An Archaeological Atlas of Coptic Literature.\nLiterary Texts in their Geographical Context: Production, Copying, Usage, Dissemination and Storage' title: 'Tracking Unknown Papyrus and Parchment Paths: An Archaeological Atlas of Coptic Literature.\nLiterary Texts in their Geographical Context: Production, Copying, Usage, Dissemination and Storage',
reason: 'Project not found'
}, },
_links: { _links: {
self: { self: {
@@ -1838,8 +1847,10 @@ export function getMockNotificationsStateService(): any {
*/ */
export function getMockQualityAssuranceTopicRestService(): QualityAssuranceTopicDataService { export function getMockQualityAssuranceTopicRestService(): QualityAssuranceTopicDataService {
return jasmine.createSpyObj('QualityAssuranceTopicDataService', { return jasmine.createSpyObj('QualityAssuranceTopicDataService', {
getTopics: jasmine.createSpy('getTopics'),
getTopic: jasmine.createSpy('getTopic'), getTopic: jasmine.createSpy('getTopic'),
searchTopicsByTarget: jasmine.createSpy('searchTopicsByTarget'),
searchTopicsBySource: jasmine.createSpy('searchTopicsBySource'),
clearFindAllTopicsRequests: jasmine.createSpy('clearFindAllTopicsRequests'),
}); });
} }