[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), 'findById').and.callThrough();
spyOn((service as any).searchData, 'searchBy').and.callThrough();
});
describe('getTopics', () => {
it('should call findListByHref', (done) => {
service.getTopics().subscribe(
(res) => {
expect((service as any).findAllData.findAll).toHaveBeenCalledWith({}, true, true);
}
describe('searchTopicsByTarget', () => {
it('should call searchData.searchBy with the correct parameters', () => {
const options = { elementsPerPage: 10 };
const useCachedVersionIfAvailable = 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', () => {
const result = service.getTopics();
const result = service.searchTopicsByTarget();
const expected = cold('(a)', {
a: paginatedListRD
});

View File

@@ -1,16 +1,44 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
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', () => {
let component: QaEventNotificationComponent;
let fixture: ComponentFixture<QaEventNotificationComponent>;
let qualityAssuranceSourceDataServiceStub: any;
const obj = createSuccessfulRemoteDataObject$(createPaginatedList([new QualityAssuranceSourceObject()]));
const item = Object.assign({ uuid: '1234' });
beforeEach(async () => {
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();
fixture = TestBed.createComponent(QaEventNotificationComponent);
component = fixture.componentInstance;
component.item = item;
fixture.detectChanges();
});
it('should create', () => {

View File

@@ -271,8 +271,8 @@ describe('NotificationsStateService', () => {
it('Should call store.dispatch', () => {
const elementsPerPage = 3;
const currentPage = 1;
const action = new RetrieveAllTopicsAction(elementsPerPage, currentPage);
service.dispatchRetrieveQualityAssuranceTopics(elementsPerPage, currentPage);
const action = new RetrieveAllTopicsAction(elementsPerPage, currentPage, 'source', 'target');
service.dispatchRetrieveQualityAssuranceTopics(elementsPerPage, currentPage, 'source', 'target');
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 { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
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', () => {
let fixture: ComponentFixture<QualityAssuranceEventsComponent>;
@@ -118,6 +120,8 @@ describe('QualityAssuranceEventsComponent test suite', () => {
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
{ provide: TranslateService, useValue: getMockTranslateService() },
{ provide: PaginationService, useValue: paginationService },
{ provide: ItemDataService, useValue: {} },
{ provide: AuthorizationDataService, useValue: {} },
QualityAssuranceEventsComponent
],
schemas: [NO_ERRORS_SCHEMA]

View File

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

View File

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

View File

@@ -42,30 +42,30 @@ describe('QualityAssuranceTopicsService', () => {
beforeEach(() => {
restService = TestBed.inject(QualityAssuranceTopicDataService);
restServiceAsAny = restService;
restServiceAsAny.getTopics.and.returnValue(observableOf(paginatedListRD));
restServiceAsAny.searchTopicsBySource.and.returnValue(observableOf(paginatedListRD));
restServiceAsAny.searchTopicsByTarget.and.returnValue(observableOf(paginatedListRD));
service = new QualityAssuranceTopicsService(restService);
serviceAsAny = service;
});
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 findListOptions: FindListOptions = {
elementsPerPage: elementsPerPage,
currentPage: currentPage,
sort: sortOptions,
searchParams: [new RequestParam('source', 'ENRICH!MORE!ABSTRACT')]
searchParams: [new RequestParam('source', 'openaire')]
};
service.setSourceId('ENRICH!MORE!ABSTRACT');
const result = service.getTopics(elementsPerPage, currentPage);
expect((service as any).qualityAssuranceTopicRestService.getTopics).toHaveBeenCalledWith(findListOptions);
service.getTopics(elementsPerPage, currentPage, 'openaire');
expect((service as any).qualityAssuranceTopicRestService.searchTopicsBySource).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|)', {
a: paginatedList
});
const result = service.getTopics(elementsPerPage, currentPage);
const result = service.getTopics(elementsPerPage, currentPage, 'openaire');
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 { 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';
describe('DSOEditMenuResolver', () => {
@@ -39,6 +43,8 @@ describe('DSOEditMenuResolver', () => {
let researcherProfileService;
let notificationsService;
let translate;
let dsoWithdrawnReinstateModalService;
let correctionsDataService;
const dsoRoute = (dso: DSpaceObject) => {
return {
@@ -141,6 +147,14 @@ describe('DSOEditMenuResolver', () => {
error: {},
});
dsoWithdrawnReinstateModalService = jasmine.createSpyObj('dsoWithdrawnReinstateModalService', {
openCreateWithdrawnReinstateModal: {},
});
correctionsDataService = jasmine.createSpyObj('correctionsDataService', {
findByItem: observableOf([])
});
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), NoopAnimationsModule, RouterTestingModule],
declarations: [AdminSidebarComponent],
@@ -152,6 +166,9 @@ describe('DSOEditMenuResolver', () => {
{provide: ResearcherProfileDataService, useValue: researcherProfileService},
{provide: TranslateService, useValue: translate},
{provide: NotificationsService, useValue: notificationsService},
{provide: DsoWithdrawnReinstateModalService, useValue: dsoWithdrawnReinstateModalService},
{provide: AuthService, useValue: new AuthServiceMock()},
{provide: CorrectionTypeDataService, useValue: correctionsDataService},
{
provide: NgbModal, useValue: {
open: () => {/*comment*/
@@ -350,7 +367,7 @@ describe('DSOEditMenuResolver', () => {
route = dsoRoute(testItem);
});
it('should return Item-specific entries', (done) => {
it('should return Item-specific entries', () => {
const result = resolver.getDsoMenus(testObject, route, state);
combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
const orcidEntry = menu.find(entry => entry.id === 'orcid-dso');
@@ -371,20 +388,18 @@ 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', (done) => {
it('should not return Community/Collection-specific entries', () => {
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 ', (done) => {
it('should return as third part the common list ', () => {
const result = resolver.getDsoMenus(testObject, route, state);
combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
const editEntry = menu.find(entry => entry.id === 'edit-dso');
@@ -395,7 +410,6 @@ describe('DSOEditMenuResolver', () => {
expect((editEntry.model as LinkMenuItemModel).link).toEqual(
'/items/test-item-uuid/edit/metadata'
);
done();
});
});
});

View File

@@ -1482,7 +1482,8 @@ export const qualityAssuranceEventObjectMissingPid: QualityAssuranceEventObject
funder: null,
fundingProgram: null,
jurisdiction: null,
title: null
title: null,
reason: 'Missing PID'
},
_links: {
self: {
@@ -1519,7 +1520,8 @@ export const qualityAssuranceEventObjectMissingPid2: QualityAssuranceEventObject
funder: null,
fundingProgram: null,
jurisdiction: null,
title: null
title: null,
reason: 'Missing PID'
},
_links: {
self: {
@@ -1556,7 +1558,8 @@ export const qualityAssuranceEventObjectMissingPid3: QualityAssuranceEventObject
funder: null,
fundingProgram: null,
jurisdiction: null,
title: null
title: null,
reason: 'Missing PID'
},
_links: {
self: {
@@ -1593,7 +1596,8 @@ export const qualityAssuranceEventObjectMissingPid4: QualityAssuranceEventObject
funder: null,
fundingProgram: null,
jurisdiction: null,
title: null
title: null,
reason: 'Missing DOI'
},
_links: {
self: {
@@ -1630,7 +1634,8 @@ export const qualityAssuranceEventObjectMissingPid5: QualityAssuranceEventObject
funder: null,
fundingProgram: null,
jurisdiction: null,
title: null
title: null,
reason: 'Missing PID'
},
_links: {
self: {
@@ -1667,7 +1672,8 @@ export const qualityAssuranceEventObjectMissingPid6: QualityAssuranceEventObject
funder: null,
fundingProgram: null,
jurisdiction: null,
title: null
title: null,
reason: 'Missing PID'
},
_links: {
self: {
@@ -1704,7 +1710,8 @@ export const qualityAssuranceEventObjectMissingAbstract: QualityAssuranceEventOb
funder: null,
fundingProgram: null,
jurisdiction: null,
title: null
title: null,
reason: 'Missing abstract'
},
_links: {
self: {
@@ -1741,6 +1748,7 @@ export const qualityAssuranceEventObjectMissingProjectFound: QualityAssuranceEve
funder: 'EC',
fundingProgram: 'H2020',
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'
},
_links: {
@@ -1778,7 +1786,8 @@ export const qualityAssuranceEventObjectMissingProjectNotFound: QualityAssurance
funder: 'EC',
fundingProgram: 'H2021',
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: {
self: {
@@ -1838,8 +1847,10 @@ export function getMockNotificationsStateService(): any {
*/
export function getMockQualityAssuranceTopicRestService(): QualityAssuranceTopicDataService {
return jasmine.createSpyObj('QualityAssuranceTopicDataService', {
getTopics: jasmine.createSpy('getTopics'),
getTopic: jasmine.createSpy('getTopic'),
searchTopicsByTarget: jasmine.createSpy('searchTopicsByTarget'),
searchTopicsBySource: jasmine.createSpy('searchTopicsBySource'),
clearFindAllTopicsRequests: jasmine.createSpy('clearFindAllTopicsRequests'),
});
}