mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 04:53:06 +00:00
[DURACOM-191] Fix eperson-group-list.component which still used getDataServiceFor decorator
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
|||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import {
|
import {
|
||||||
ComponentFixture,
|
ComponentFixture,
|
||||||
|
fakeAsync,
|
||||||
inject,
|
inject,
|
||||||
TestBed,
|
TestBed,
|
||||||
waitForAsync,
|
waitForAsync,
|
||||||
@@ -15,19 +16,15 @@ import { TranslateModule } from '@ngx-translate/core';
|
|||||||
import { cold } from 'jasmine-marbles';
|
import { cold } from 'jasmine-marbles';
|
||||||
import uniqueId from 'lodash/uniqueId';
|
import uniqueId from 'lodash/uniqueId';
|
||||||
import { of as observableOf } from 'rxjs';
|
import { of as observableOf } from 'rxjs';
|
||||||
import { DSONameService } from 'src/app/core/breadcrumbs/dso-name.service';
|
|
||||||
import {
|
|
||||||
dataService,
|
|
||||||
getDataServiceFor,
|
|
||||||
} from 'src/app/core/data/base/data-service.decorator';
|
|
||||||
import { EPERSON } from 'src/app/core/eperson/models/eperson.resource-type';
|
|
||||||
import { GROUP } from 'src/app/core/eperson/models/group.resource-type';
|
|
||||||
import { ResourceType } from 'src/app/core/shared/resource-type';
|
|
||||||
|
|
||||||
|
import { APP_DATA_SERVICES_MAP } from '../../../config/app-config.interface';
|
||||||
|
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
|
||||||
import { buildPaginatedList } from '../../core/data/paginated-list.model';
|
import { buildPaginatedList } from '../../core/data/paginated-list.model';
|
||||||
import { RequestService } from '../../core/data/request.service';
|
import { RequestService } from '../../core/data/request.service';
|
||||||
import { EPersonDataService } from '../../core/eperson/eperson-data.service';
|
import { EPersonDataService } from '../../core/eperson/eperson-data.service';
|
||||||
import { GroupDataService } from '../../core/eperson/group-data.service';
|
import { GroupDataService } from '../../core/eperson/group-data.service';
|
||||||
|
import { EPERSON } from '../../core/eperson/models/eperson.resource-type';
|
||||||
|
import { GROUP } from '../../core/eperson/models/group.resource-type';
|
||||||
import { PaginationService } from '../../core/pagination/pagination.service';
|
import { PaginationService } from '../../core/pagination/pagination.service';
|
||||||
import { PageInfo } from '../../core/shared/page-info.model';
|
import { PageInfo } from '../../core/shared/page-info.model';
|
||||||
import { DSONameServiceMock } from '../mocks/dso-name.service.mock';
|
import { DSONameServiceMock } from '../mocks/dso-name.service.mock';
|
||||||
@@ -44,6 +41,11 @@ import { SearchEvent } from './eperson-group-list-event-type';
|
|||||||
import { EpersonSearchBoxComponent } from './eperson-search-box/eperson-search-box.component';
|
import { EpersonSearchBoxComponent } from './eperson-search-box/eperson-search-box.component';
|
||||||
import { GroupSearchBoxComponent } from './group-search-box/group-search-box.component';
|
import { GroupSearchBoxComponent } from './group-search-box/group-search-box.component';
|
||||||
|
|
||||||
|
const mockDataServiceMap: any = {
|
||||||
|
[EPERSON.value]: () => import('../../core/eperson/eperson-data.service').then(m => m.EPersonDataService),
|
||||||
|
[GROUP.value]: () => import('../../core/eperson/group-data.service').then(m => m.GroupDataService),
|
||||||
|
};
|
||||||
|
|
||||||
describe('EpersonGroupListComponent test suite', () => {
|
describe('EpersonGroupListComponent test suite', () => {
|
||||||
let comp: EpersonGroupListComponent;
|
let comp: EpersonGroupListComponent;
|
||||||
let compAsAny: any;
|
let compAsAny: any;
|
||||||
@@ -59,7 +61,6 @@ describe('EpersonGroupListComponent test suite', () => {
|
|||||||
|
|
||||||
const mockEpersonService = jasmine.createSpyObj('epersonService',
|
const mockEpersonService = jasmine.createSpyObj('epersonService',
|
||||||
{
|
{
|
||||||
getDataServiceFor: jasmine.createSpy('getDataServiceFor'),
|
|
||||||
findByHref: jasmine.createSpy('findByHref'),
|
findByHref: jasmine.createSpy('findByHref'),
|
||||||
findAll: jasmine.createSpy('findAll'),
|
findAll: jasmine.createSpy('findAll'),
|
||||||
searchByScope: jasmine.createSpy('searchByScope'),
|
searchByScope: jasmine.createSpy('searchByScope'),
|
||||||
@@ -71,7 +72,6 @@ describe('EpersonGroupListComponent test suite', () => {
|
|||||||
|
|
||||||
const mockGroupService = jasmine.createSpyObj('groupService',
|
const mockGroupService = jasmine.createSpyObj('groupService',
|
||||||
{
|
{
|
||||||
getDataServiceFor: jasmine.createSpy('getDataServiceFor'),
|
|
||||||
findByHref: jasmine.createSpy('findByHref'),
|
findByHref: jasmine.createSpy('findByHref'),
|
||||||
findAll: jasmine.createSpy('findAll'),
|
findAll: jasmine.createSpy('findAll'),
|
||||||
searchGroups: jasmine.createSpy('searchGroups'),
|
searchGroups: jasmine.createSpy('searchGroups'),
|
||||||
@@ -106,6 +106,7 @@ describe('EpersonGroupListComponent test suite', () => {
|
|||||||
{ provide: GroupDataService, useValue: mockGroupService },
|
{ provide: GroupDataService, useValue: mockGroupService },
|
||||||
{ provide: RequestService, useValue: getMockRequestService() },
|
{ provide: RequestService, useValue: getMockRequestService() },
|
||||||
{ provide: PaginationService, useValue: paginationService },
|
{ provide: PaginationService, useValue: paginationService },
|
||||||
|
{ provide: APP_DATA_SERVICES_MAP, useValue: mockDataServiceMap },
|
||||||
EpersonGroupListComponent,
|
EpersonGroupListComponent,
|
||||||
ChangeDetectorRef,
|
ChangeDetectorRef,
|
||||||
Injector,
|
Injector,
|
||||||
@@ -151,19 +152,14 @@ describe('EpersonGroupListComponent test suite', () => {
|
|||||||
|
|
||||||
describe('when is list of eperson', () => {
|
describe('when is list of eperson', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
// initTestScheduler();
|
// initTestScheduler();
|
||||||
fixture = TestBed.createComponent(EpersonGroupListComponent);
|
fixture = TestBed.createComponent(EpersonGroupListComponent);
|
||||||
epersonService = TestBed.inject(EPersonDataService);
|
epersonService = TestBed.inject(EPersonDataService);
|
||||||
comp = fixture.componentInstance;
|
comp = fixture.componentInstance;
|
||||||
compAsAny = fixture.componentInstance;
|
compAsAny = fixture.componentInstance;
|
||||||
comp.isListOfEPerson = true;
|
comp.isListOfEPerson = true;
|
||||||
const resourceType: ResourceType = (comp.isListOfEPerson) ? EPERSON : GROUP;
|
}));
|
||||||
const mockDataService = dataService(resourceType);
|
|
||||||
if (!getDataServiceFor(resourceType)) {
|
|
||||||
mockDataService(EPersonDataService);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
comp = null;
|
comp = null;
|
||||||
@@ -172,33 +168,40 @@ describe('EpersonGroupListComponent test suite', () => {
|
|||||||
fixture.destroy();
|
fixture.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should inject EPersonDataService', () => {
|
it('should inject EPersonDataService', fakeAsync(() => {
|
||||||
spyOn(comp, 'updateList');
|
spyOn(comp, 'updateList');
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
expect(compAsAny.dataService).toBeDefined();
|
expect(compAsAny.dataService).toBeDefined();
|
||||||
expect(comp.updateList).toHaveBeenCalled();
|
expect(comp.updateList).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
it('should init entrySelectedId', () => {
|
it('should init entrySelectedId', fakeAsync(() => {
|
||||||
spyOn(comp, 'updateList');
|
spyOn(comp, 'updateList');
|
||||||
comp.initSelected = EPersonMock.id;
|
comp.initSelected = EPersonMock.id;
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
expect(compAsAny.entrySelectedId.value).toBe(EPersonMock.id);
|
expect(compAsAny.entrySelectedId.value).toBe(EPersonMock.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should init the list of eperson', () => {
|
}));
|
||||||
|
|
||||||
|
it('should init the list of eperson', fakeAsync(() => {
|
||||||
epersonService.searchByScope.and.returnValue(observableOf(epersonPaginatedListRD));
|
epersonService.searchByScope.and.returnValue(observableOf(epersonPaginatedListRD));
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
expect(compAsAny.list$.value).toEqual(epersonPaginatedListRD);
|
expect(compAsAny.list$.value).toEqual(epersonPaginatedListRD);
|
||||||
expect(comp.getList()).toBeObservable(cold('a', {
|
expect(comp.getList()).toBeObservable(cold('a', {
|
||||||
a: epersonPaginatedListRD,
|
a: epersonPaginatedListRD,
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
it('should emit select event', () => {
|
it('should emit select event', () => {
|
||||||
spyOn(comp.select, 'emit');
|
spyOn(comp.select, 'emit');
|
||||||
@@ -234,11 +237,6 @@ describe('EpersonGroupListComponent test suite', () => {
|
|||||||
comp = fixture.componentInstance;
|
comp = fixture.componentInstance;
|
||||||
compAsAny = fixture.componentInstance;
|
compAsAny = fixture.componentInstance;
|
||||||
comp.isListOfEPerson = false;
|
comp.isListOfEPerson = false;
|
||||||
const resourceType: ResourceType = (comp.isListOfEPerson) ? EPERSON : GROUP;
|
|
||||||
const mockDataService = dataService(resourceType);
|
|
||||||
if (!getDataServiceFor(resourceType)) {
|
|
||||||
mockDataService(GroupDataService);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -248,32 +246,39 @@ describe('EpersonGroupListComponent test suite', () => {
|
|||||||
fixture.destroy();
|
fixture.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should inject GroupDataService', () => {
|
it('should inject GroupDataService', fakeAsync(() => {
|
||||||
spyOn(comp, 'updateList');
|
spyOn(comp, 'updateList');
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
expect(compAsAny.dataService).toBeDefined();
|
expect(compAsAny.dataService).toBeDefined();
|
||||||
expect(comp.updateList).toHaveBeenCalled();
|
expect(comp.updateList).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should init entrySelectedId', () => {
|
}));
|
||||||
|
|
||||||
|
it('should init entrySelectedId', fakeAsync(() => {
|
||||||
spyOn(comp, 'updateList');
|
spyOn(comp, 'updateList');
|
||||||
comp.initSelected = GroupMock.id;
|
comp.initSelected = GroupMock.id;
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
expect(compAsAny.entrySelectedId.value).toBe(GroupMock.id);
|
expect(compAsAny.entrySelectedId.value).toBe(GroupMock.id);
|
||||||
});
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
it('should init the list of group', () => {
|
it('should init the list of group', fakeAsync(() => {
|
||||||
groupService.searchGroups.and.returnValue(observableOf(groupPaginatedListRD));
|
groupService.searchGroups.and.returnValue(observableOf(groupPaginatedListRD));
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
expect(compAsAny.list$.value).toEqual(groupPaginatedListRD);
|
expect(compAsAny.list$.value).toEqual(groupPaginatedListRD);
|
||||||
expect(comp.getList()).toBeObservable(cold('a', {
|
expect(comp.getList()).toBeObservable(cold('a', {
|
||||||
a: groupPaginatedListRD,
|
a: groupPaginatedListRD,
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
it('should emit select event', () => {
|
it('should emit select event', () => {
|
||||||
spyOn(comp.select, 'emit');
|
spyOn(comp.select, 'emit');
|
||||||
|
@@ -6,6 +6,8 @@ import {
|
|||||||
import {
|
import {
|
||||||
Component,
|
Component,
|
||||||
EventEmitter,
|
EventEmitter,
|
||||||
|
Inject,
|
||||||
|
InjectionToken,
|
||||||
Injector,
|
Injector,
|
||||||
Input,
|
Input,
|
||||||
OnDestroy,
|
OnDestroy,
|
||||||
@@ -21,8 +23,11 @@ import {
|
|||||||
} from 'rxjs';
|
} from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
|
import {
|
||||||
|
APP_DATA_SERVICES_MAP,
|
||||||
|
LazyDataServicesMap,
|
||||||
|
} from '../../../config/app-config.interface';
|
||||||
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
|
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
|
||||||
import { getDataServiceFor } from '../../core/data/base/data-service.decorator';
|
|
||||||
import { FindListOptions } from '../../core/data/find-list-options.model';
|
import { FindListOptions } from '../../core/data/find-list-options.model';
|
||||||
import { PaginatedList } from '../../core/data/paginated-list.model';
|
import { PaginatedList } from '../../core/data/paginated-list.model';
|
||||||
import { RemoteData } from '../../core/data/remote-data';
|
import { RemoteData } from '../../core/data/remote-data';
|
||||||
@@ -30,6 +35,7 @@ import { EPersonDataService } from '../../core/eperson/eperson-data.service';
|
|||||||
import { GroupDataService } from '../../core/eperson/group-data.service';
|
import { GroupDataService } from '../../core/eperson/group-data.service';
|
||||||
import { EPERSON } from '../../core/eperson/models/eperson.resource-type';
|
import { EPERSON } from '../../core/eperson/models/eperson.resource-type';
|
||||||
import { GROUP } from '../../core/eperson/models/group.resource-type';
|
import { GROUP } from '../../core/eperson/models/group.resource-type';
|
||||||
|
import { lazyService } from '../../core/lazy-service';
|
||||||
import { PaginationService } from '../../core/pagination/pagination.service';
|
import { PaginationService } from '../../core/pagination/pagination.service';
|
||||||
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
||||||
import { getFirstCompletedRemoteData } from '../../core/shared/operators';
|
import { getFirstCompletedRemoteData } from '../../core/shared/operators';
|
||||||
@@ -121,9 +127,13 @@ export class EpersonGroupListComponent implements OnInit, OnDestroy {
|
|||||||
*
|
*
|
||||||
* @param {DSONameService} dsoNameService
|
* @param {DSONameService} dsoNameService
|
||||||
* @param {Injector} parentInjector
|
* @param {Injector} parentInjector
|
||||||
|
* @param {PaginationService} paginationService
|
||||||
|
* @param {APP_DATA_SERVICES_MAP} dataServiceMap
|
||||||
*/
|
*/
|
||||||
constructor(public dsoNameService: DSONameService, private parentInjector: Injector,
|
constructor(public dsoNameService: DSONameService,
|
||||||
private paginationService: PaginationService) {
|
private parentInjector: Injector,
|
||||||
|
private paginationService: PaginationService,
|
||||||
|
@Inject(APP_DATA_SERVICES_MAP) private dataServiceMap: InjectionToken<LazyDataServicesMap>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -131,11 +141,10 @@ export class EpersonGroupListComponent implements OnInit, OnDestroy {
|
|||||||
*/
|
*/
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
const resourceType: ResourceType = (this.isListOfEPerson) ? EPERSON : GROUP;
|
const resourceType: ResourceType = (this.isListOfEPerson) ? EPERSON : GROUP;
|
||||||
const provider = getDataServiceFor(resourceType);
|
const lazyProvider$: Observable<EPersonDataService | GroupDataService> = lazyService(this.dataServiceMap[resourceType.value], this.parentInjector);
|
||||||
this.dataService = Injector.create({
|
lazyProvider$.subscribe((dataService: EPersonDataService | GroupDataService) => {
|
||||||
providers: [],
|
this.dataService = dataService;
|
||||||
parent: this.parentInjector,
|
console.log(dataService);
|
||||||
}).get(provider);
|
|
||||||
this.paginationOptions.id = uniqueId('egl');
|
this.paginationOptions.id = uniqueId('egl');
|
||||||
this.paginationOptions.pageSize = 5;
|
this.paginationOptions.pageSize = 5;
|
||||||
|
|
||||||
@@ -144,6 +153,7 @@ export class EpersonGroupListComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.updateList(this.currentSearchScope, this.currentSearchQuery);
|
this.updateList(this.currentSearchScope, this.currentSearchQuery);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user