@@ -5,8 +5,8 @@ import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
55import { ComponentFixture , fakeAsync , TestBed , tick , waitForAsync } from '@angular/core/testing' ;
66import { FormsModule , ReactiveFormsModule } from '@angular/forms' ;
77import { BrowserModule , By } from '@angular/platform-browser' ;
8- import { NgbModule } from '@ng-bootstrap/ng-bootstrap' ;
9- import { TranslateLoader , TranslateModule , TranslateService } from '@ngx-translate/core' ;
8+ import { NgbModule , NgbModal } from '@ng-bootstrap/ng-bootstrap' ;
9+ import { TranslateModule } from '@ngx-translate/core' ;
1010import { buildPaginatedList , PaginatedList } from '../../core/data/paginated-list.model' ;
1111import { RemoteData } from '../../core/data/remote-data' ;
1212import { EPersonDataService } from '../../core/eperson/eperson-data.service' ;
@@ -18,8 +18,6 @@ import { EPeopleRegistryComponent } from './epeople-registry.component';
1818import { EPersonMock , EPersonMock2 } from '../../shared/testing/eperson.mock' ;
1919import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils' ;
2020import { getMockFormBuilderService } from '../../shared/mocks/form-builder-service.mock' ;
21- import { getMockTranslateService } from '../../shared/mocks/translate.service.mock' ;
22- import { TranslateLoaderMock } from '../../shared/mocks/translate-loader.mock' ;
2321import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub' ;
2422import { RouterStub } from '../../shared/testing/router.stub' ;
2523import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service' ;
@@ -31,17 +29,15 @@ import { FindListOptions } from '../../core/data/find-list-options.model';
3129describe ( 'EPeopleRegistryComponent' , ( ) => {
3230 let component : EPeopleRegistryComponent ;
3331 let fixture : ComponentFixture < EPeopleRegistryComponent > ;
34- let translateService : TranslateService ;
3532 let builderService : FormBuilderService ;
3633
37- let mockEPeople ;
34+ let mockEPeople : EPerson [ ] ;
3835 let ePersonDataServiceStub : any ;
3936 let authorizationService : AuthorizationDataService ;
40- let modalService ;
37+ let modalService : NgbModal ;
38+ let paginationService : PaginationServiceStub ;
4139
42- let paginationService ;
43-
44- beforeEach ( waitForAsync ( ( ) => {
40+ beforeEach ( waitForAsync ( async ( ) => {
4541 jasmine . getEnv ( ) . allowRespy ( true ) ;
4642 mockEPeople = [ EPersonMock , EPersonMock2 ] ;
4743 ePersonDataServiceStub = {
@@ -99,7 +95,7 @@ describe('EPeopleRegistryComponent', () => {
9995 deleteEPerson ( ePerson : EPerson ) : Observable < boolean > {
10096 this . allEpeople = this . allEpeople . filter ( ( ePerson2 : EPerson ) => {
10197 return ( ePerson2 . uuid !== ePerson . uuid ) ;
102- } ) ;
98+ } ) ;
10399 return observableOf ( true ) ;
104100 } ,
105101 editEPerson ( ePerson : EPerson ) {
@@ -119,17 +115,11 @@ describe('EPeopleRegistryComponent', () => {
119115 isAuthorized : observableOf ( true )
120116 } ) ;
121117 builderService = getMockFormBuilderService ( ) ;
122- translateService = getMockTranslateService ( ) ;
123118
124119 paginationService = new PaginationServiceStub ( ) ;
125- TestBed . configureTestingModule ( {
120+ await TestBed . configureTestingModule ( {
126121 imports : [ CommonModule , NgbModule , FormsModule , ReactiveFormsModule , BrowserModule ,
127- TranslateModule . forRoot ( {
128- loader : {
129- provide : TranslateLoader ,
130- useClass : TranslateLoaderMock
131- }
132- } ) ,
122+ TranslateModule . forRoot ( ) ,
133123 ] ,
134124 declarations : [ EPeopleRegistryComponent ] ,
135125 providers : [
@@ -148,7 +138,7 @@ describe('EPeopleRegistryComponent', () => {
148138 beforeEach ( ( ) => {
149139 fixture = TestBed . createComponent ( EPeopleRegistryComponent ) ;
150140 component = fixture . componentInstance ;
151- modalService = ( component as any ) . modalService ;
141+ modalService = TestBed . inject ( NgbModal ) ;
152142 spyOn ( modalService , 'open' ) . and . returnValue ( Object . assign ( { componentInstance : Object . assign ( { response : observableOf ( true ) } ) } ) ) ;
153143 fixture . detectChanges ( ) ;
154144 } ) ;
@@ -158,18 +148,18 @@ describe('EPeopleRegistryComponent', () => {
158148 } ) ;
159149
160150 it ( 'should display list of ePeople' , ( ) => {
161- const ePeopleIdsFound = fixture . debugElement . queryAll ( By . css ( '#epeople tr td:first-child' ) ) ;
151+ const ePeopleIdsFound : DebugElement [ ] = fixture . debugElement . queryAll ( By . css ( '#epeople tr td:first-child' ) ) ;
162152 expect ( ePeopleIdsFound . length ) . toEqual ( 2 ) ;
163153 mockEPeople . map ( ( ePerson : EPerson ) => {
164- expect ( ePeopleIdsFound . find ( ( foundEl ) => {
154+ expect ( ePeopleIdsFound . find ( ( foundEl : DebugElement ) => {
165155 return ( foundEl . nativeElement . textContent . trim ( ) === ePerson . uuid ) ;
166156 } ) ) . toBeTruthy ( ) ;
167157 } ) ;
168158 } ) ;
169159
170160 describe ( 'search' , ( ) => {
171161 describe ( 'when searching with scope/query (scope metadata)' , ( ) => {
172- let ePeopleIdsFound ;
162+ let ePeopleIdsFound : DebugElement [ ] ;
173163 beforeEach ( fakeAsync ( ( ) => {
174164 component . search ( { scope : 'metadata' , query : EPersonMock2 . name } ) ;
175165 tick ( ) ;
@@ -179,14 +169,14 @@ describe('EPeopleRegistryComponent', () => {
179169
180170 it ( 'should display search result' , ( ) => {
181171 expect ( ePeopleIdsFound . length ) . toEqual ( 1 ) ;
182- expect ( ePeopleIdsFound . find ( ( foundEl ) => {
172+ expect ( ePeopleIdsFound . find ( ( foundEl : DebugElement ) => {
183173 return ( foundEl . nativeElement . textContent . trim ( ) === EPersonMock2 . uuid ) ;
184174 } ) ) . toBeTruthy ( ) ;
185175 } ) ;
186176 } ) ;
187177
188178 describe ( 'when searching with scope/query (scope email)' , ( ) => {
189- let ePeopleIdsFound ;
179+ let ePeopleIdsFound : DebugElement [ ] ;
190180 beforeEach ( fakeAsync ( ( ) => {
191181 component . search ( { scope : 'email' , query : EPersonMock . email } ) ;
192182 tick ( ) ;
@@ -196,7 +186,7 @@ describe('EPeopleRegistryComponent', () => {
196186
197187 it ( 'should display search result' , ( ) => {
198188 expect ( ePeopleIdsFound . length ) . toEqual ( 1 ) ;
199- expect ( ePeopleIdsFound . find ( ( foundEl ) => {
189+ expect ( ePeopleIdsFound . find ( ( foundEl : DebugElement ) => {
200190 return ( foundEl . nativeElement . textContent . trim ( ) === EPersonMock . uuid ) ;
201191 } ) ) . toBeTruthy ( ) ;
202192 } ) ;
@@ -228,19 +218,12 @@ describe('EPeopleRegistryComponent', () => {
228218 } ) ;
229219 } ) ;
230220
231- describe ( 'delete EPerson button when the isAuthorized returns false' , ( ) => {
232- let ePeopleDeleteButton ;
233- beforeEach ( ( ) => {
234- spyOn ( authorizationService , 'isAuthorized' ) . and . returnValue ( observableOf ( false ) ) ;
235- component . initialisePage ( ) ;
236- fixture . detectChanges ( ) ;
237- } ) ;
238221
239- it ( 'should be disabled ' , ( ) => {
240- ePeopleDeleteButton = fixture . debugElement . queryAll ( By . css ( '#epeople tr td div button.delete-button' ) ) ;
241- ePeopleDeleteButton . forEach ( ( deleteButton : DebugElement ) => {
242- expect ( deleteButton . nativeElement . disabled ) . toBe ( true ) ;
243- } ) ;
244- } ) ;
222+ it ( 'should hide delete EPerson button when the isAuthorized returns false ' , ( ) => {
223+ spyOn ( authorizationService , 'isAuthorized' ) . and . returnValue ( observableOf ( false ) ) ;
224+ component . initialisePage ( ) ;
225+ fixture . detectChanges ( ) ;
226+
227+ expect ( fixture . debugElement . query ( By . css ( '#epeople tr td div button.delete-button' ) ) ) . toBeNull ( ) ;
245228 } ) ;
246229} ) ;
0 commit comments