66} from '@angular/core' ;
77import {
88 ComponentFixture ,
9+ fakeAsync ,
910 inject ,
1011 TestBed ,
1112 waitForAsync ,
@@ -15,19 +16,15 @@ import { TranslateModule } from '@ngx-translate/core';
1516import { cold } from 'jasmine-marbles' ;
1617import uniqueId from 'lodash/uniqueId' ;
1718import { of as observableOf } from 'rxjs' ;
18- import { DSONameService } from 'src/app/core/breadcrumbs/dso-name.service' ;
19- import {
20- dataService ,
21- getDataServiceFor ,
22- } from 'src/app/core/data/base/data-service.decorator' ;
23- import { EPERSON } from 'src/app/core/eperson/models/eperson.resource-type' ;
24- import { GROUP } from 'src/app/core/eperson/models/group.resource-type' ;
25- import { ResourceType } from 'src/app/core/shared/resource-type' ;
2619
20+ import { APP_DATA_SERVICES_MAP } from '../../../config/app-config.interface' ;
21+ import { DSONameService } from '../../core/breadcrumbs/dso-name.service' ;
2722import { buildPaginatedList } from '../../core/data/paginated-list.model' ;
2823import { RequestService } from '../../core/data/request.service' ;
2924import { EPersonDataService } from '../../core/eperson/eperson-data.service' ;
3025import { GroupDataService } from '../../core/eperson/group-data.service' ;
26+ import { EPERSON } from '../../core/eperson/models/eperson.resource-type' ;
27+ import { GROUP } from '../../core/eperson/models/group.resource-type' ;
3128import { PaginationService } from '../../core/pagination/pagination.service' ;
3229import { PageInfo } from '../../core/shared/page-info.model' ;
3330import { DSONameServiceMock } from '../mocks/dso-name.service.mock' ;
@@ -44,6 +41,11 @@ import { SearchEvent } from './eperson-group-list-event-type';
4441import { EpersonSearchBoxComponent } from './eperson-search-box/eperson-search-box.component' ;
4542import { GroupSearchBoxComponent } from './group-search-box/group-search-box.component' ;
4643
44+ const mockDataServiceMap : any = {
45+ [ EPERSON . value ] : ( ) => import ( '../../core/eperson/eperson-data.service' ) . then ( m => m . EPersonDataService ) ,
46+ [ GROUP . value ] : ( ) => import ( '../../core/eperson/group-data.service' ) . then ( m => m . GroupDataService ) ,
47+ } ;
48+
4749describe ( 'EpersonGroupListComponent test suite' , ( ) => {
4850 let comp : EpersonGroupListComponent ;
4951 let compAsAny : any ;
@@ -59,7 +61,6 @@ describe('EpersonGroupListComponent test suite', () => {
5961
6062 const mockEpersonService = jasmine . createSpyObj ( 'epersonService' ,
6163 {
62- getDataServiceFor : jasmine . createSpy ( 'getDataServiceFor' ) ,
6364 findByHref : jasmine . createSpy ( 'findByHref' ) ,
6465 findAll : jasmine . createSpy ( 'findAll' ) ,
6566 searchByScope : jasmine . createSpy ( 'searchByScope' ) ,
@@ -71,7 +72,6 @@ describe('EpersonGroupListComponent test suite', () => {
7172
7273 const mockGroupService = jasmine . createSpyObj ( 'groupService' ,
7374 {
74- getDataServiceFor : jasmine . createSpy ( 'getDataServiceFor' ) ,
7575 findByHref : jasmine . createSpy ( 'findByHref' ) ,
7676 findAll : jasmine . createSpy ( 'findAll' ) ,
7777 searchGroups : jasmine . createSpy ( 'searchGroups' ) ,
@@ -106,6 +106,7 @@ describe('EpersonGroupListComponent test suite', () => {
106106 { provide : GroupDataService , useValue : mockGroupService } ,
107107 { provide : RequestService , useValue : getMockRequestService ( ) } ,
108108 { provide : PaginationService , useValue : paginationService } ,
109+ { provide : APP_DATA_SERVICES_MAP , useValue : mockDataServiceMap } ,
109110 EpersonGroupListComponent ,
110111 ChangeDetectorRef ,
111112 Injector ,
@@ -151,19 +152,14 @@ describe('EpersonGroupListComponent test suite', () => {
151152
152153 describe ( 'when is list of eperson' , ( ) => {
153154
154- beforeEach ( ( ) => {
155+ beforeEach ( waitForAsync ( ( ) => {
155156 // initTestScheduler();
156157 fixture = TestBed . createComponent ( EpersonGroupListComponent ) ;
157158 epersonService = TestBed . inject ( EPersonDataService ) ;
158159 comp = fixture . componentInstance ;
159160 compAsAny = fixture . componentInstance ;
160161 comp . isListOfEPerson = true ;
161- const resourceType : ResourceType = ( comp . isListOfEPerson ) ? EPERSON : GROUP ;
162- const mockDataService = dataService ( resourceType ) ;
163- if ( ! getDataServiceFor ( resourceType ) ) {
164- mockDataService ( EPersonDataService ) ;
165- }
166- } ) ;
162+ } ) ) ;
167163
168164 afterEach ( ( ) => {
169165 comp = null ;
@@ -172,33 +168,40 @@ describe('EpersonGroupListComponent test suite', () => {
172168 fixture . destroy ( ) ;
173169 } ) ;
174170
175- it ( 'should inject EPersonDataService' , ( ) => {
171+ it ( 'should inject EPersonDataService' , fakeAsync ( ( ) => {
176172 spyOn ( comp , 'updateList' ) ;
177173 fixture . detectChanges ( ) ;
178174
179- expect ( compAsAny . dataService ) . toBeDefined ( ) ;
180- expect ( comp . updateList ) . toHaveBeenCalled ( ) ;
181- } ) ;
175+ fixture . whenStable ( ) . then ( ( ) => {
176+ expect ( compAsAny . dataService ) . toBeDefined ( ) ;
177+ expect ( comp . updateList ) . toHaveBeenCalled ( ) ;
178+ } ) ;
179+ } ) ) ;
182180
183- it ( 'should init entrySelectedId' , ( ) => {
181+ it ( 'should init entrySelectedId' , fakeAsync ( ( ) => {
184182 spyOn ( comp , 'updateList' ) ;
185183 comp . initSelected = EPersonMock . id ;
186184
187185 fixture . detectChanges ( ) ;
188186
189- expect ( compAsAny . entrySelectedId . value ) . toBe ( EPersonMock . id ) ;
190- } ) ;
187+ fixture . whenStable ( ) . then ( ( ) => {
188+ expect ( compAsAny . entrySelectedId . value ) . toBe ( EPersonMock . id ) ;
189+ } ) ;
191190
192- it ( 'should init the list of eperson' , ( ) => {
191+ } ) ) ;
192+
193+ it ( 'should init the list of eperson' , fakeAsync ( ( ) => {
193194 epersonService . searchByScope . and . returnValue ( observableOf ( epersonPaginatedListRD ) ) ;
194195
195196 fixture . detectChanges ( ) ;
196197
197- expect ( compAsAny . list$ . value ) . toEqual ( epersonPaginatedListRD ) ;
198- expect ( comp . getList ( ) ) . toBeObservable ( cold ( 'a' , {
199- a : epersonPaginatedListRD ,
200- } ) ) ;
201- } ) ;
198+ fixture . whenStable ( ) . then ( ( ) => {
199+ expect ( compAsAny . list$ . value ) . toEqual ( epersonPaginatedListRD ) ;
200+ expect ( comp . getList ( ) ) . toBeObservable ( cold ( 'a' , {
201+ a : epersonPaginatedListRD ,
202+ } ) ) ;
203+ } ) ;
204+ } ) ) ;
202205
203206 it ( 'should emit select event' , ( ) => {
204207 spyOn ( comp . select , 'emit' ) ;
@@ -234,11 +237,6 @@ describe('EpersonGroupListComponent test suite', () => {
234237 comp = fixture . componentInstance ;
235238 compAsAny = fixture . componentInstance ;
236239 comp . isListOfEPerson = false ;
237- const resourceType : ResourceType = ( comp . isListOfEPerson ) ? EPERSON : GROUP ;
238- const mockDataService = dataService ( resourceType ) ;
239- if ( ! getDataServiceFor ( resourceType ) ) {
240- mockDataService ( GroupDataService ) ;
241- }
242240 } ) ;
243241
244242 afterEach ( ( ) => {
@@ -248,32 +246,39 @@ describe('EpersonGroupListComponent test suite', () => {
248246 fixture . destroy ( ) ;
249247 } ) ;
250248
251- it ( 'should inject GroupDataService' , ( ) => {
249+ it ( 'should inject GroupDataService' , fakeAsync ( ( ) => {
252250 spyOn ( comp , 'updateList' ) ;
253251 fixture . detectChanges ( ) ;
254252
255- expect ( compAsAny . dataService ) . toBeDefined ( ) ;
256- expect ( comp . updateList ) . toHaveBeenCalled ( ) ;
257- } ) ;
253+ fixture . whenStable ( ) . then ( ( ) => {
254+ expect ( compAsAny . dataService ) . toBeDefined ( ) ;
255+ expect ( comp . updateList ) . toHaveBeenCalled ( ) ;
256+ } ) ;
258257
259- it ( 'should init entrySelectedId' , ( ) => {
258+ } ) ) ;
259+
260+ it ( 'should init entrySelectedId' , fakeAsync ( ( ) => {
260261 spyOn ( comp , 'updateList' ) ;
261262 comp . initSelected = GroupMock . id ;
262263
263264 fixture . detectChanges ( ) ;
264265
265- expect ( compAsAny . entrySelectedId . value ) . toBe ( GroupMock . id ) ;
266- } ) ;
266+ fixture . whenStable ( ) . then ( ( ) => {
267+ expect ( compAsAny . entrySelectedId . value ) . toBe ( GroupMock . id ) ;
268+ } ) ;
269+ } ) ) ;
267270
268- it ( 'should init the list of group' , ( ) => {
271+ it ( 'should init the list of group' , fakeAsync ( ( ) => {
269272 groupService . searchGroups . and . returnValue ( observableOf ( groupPaginatedListRD ) ) ;
270273 fixture . detectChanges ( ) ;
271274
272- expect ( compAsAny . list$ . value ) . toEqual ( groupPaginatedListRD ) ;
273- expect ( comp . getList ( ) ) . toBeObservable ( cold ( 'a' , {
274- a : groupPaginatedListRD ,
275- } ) ) ;
276- } ) ;
275+ fixture . whenStable ( ) . then ( ( ) => {
276+ expect ( compAsAny . list$ . value ) . toEqual ( groupPaginatedListRD ) ;
277+ expect ( comp . getList ( ) ) . toBeObservable ( cold ( 'a' , {
278+ a : groupPaginatedListRD ,
279+ } ) ) ;
280+ } ) ;
281+ } ) ) ;
277282
278283 it ( 'should emit select event' , ( ) => {
279284 spyOn ( comp . select , 'emit' ) ;
0 commit comments