11import { Observable , of as observableOf } from 'rxjs' ;
22import { CommonModule } from '@angular/common' ;
3- import { NO_ERRORS_SCHEMA } from '@angular/core' ;
3+ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' ;
44import { ComponentFixture , TestBed , waitForAsync } from '@angular/core/testing' ;
55import { UntypedFormControl , UntypedFormGroup , FormsModule , ReactiveFormsModule , Validators } from '@angular/forms' ;
66import { BrowserModule , By } from '@angular/platform-browser' ;
77import { NgbModule } from '@ng-bootstrap/ng-bootstrap' ;
8- import { TranslateLoader , TranslateModule } from '@ngx-translate/core' ;
8+ import { TranslateModule } from '@ngx-translate/core' ;
99import { buildPaginatedList , PaginatedList } from '../../../core/data/paginated-list.model' ;
1010import { RemoteData } from '../../../core/data/remote-data' ;
1111import { EPersonDataService } from '../../../core/eperson/eperson-data.service' ;
@@ -19,7 +19,6 @@ import { EPersonMock, EPersonMock2 } from '../../../shared/testing/eperson.mock'
1919import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils' ;
2020import { getMockFormBuilderService } from '../../../shared/mocks/form-builder-service.mock' ;
2121import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub' ;
22- import { TranslateLoaderMock } from '../../../shared/mocks/translate-loader.mock' ;
2322import { AuthService } from '../../../core/auth/auth.service' ;
2423import { AuthServiceStub } from '../../../shared/testing/auth-service.stub' ;
2524import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service' ;
@@ -31,6 +30,7 @@ import { PaginationServiceStub } from '../../../shared/testing/pagination-servic
3130import { FindListOptions } from '../../../core/data/find-list-options.model' ;
3231import { ValidateEmailNotTaken } from './validators/email-taken.validator' ;
3332import { EpersonRegistrationService } from '../../../core/data/eperson-registration.service' ;
33+ import { RouterTestingModule } from '@angular/router/testing' ;
3434
3535describe ( 'EPersonFormComponent' , ( ) => {
3636 let component : EPersonFormComponent ;
@@ -53,9 +53,6 @@ describe('EPersonFormComponent', () => {
5353 ePersonDataServiceStub = {
5454 activeEPerson : null ,
5555 allEpeople : mockEPeople ,
56- getEPeople ( ) : Observable < RemoteData < PaginatedList < EPerson > > > {
57- return createSuccessfulRemoteDataObject$ ( buildPaginatedList ( null , this . allEpeople ) ) ;
58- } ,
5956 getActiveEPerson ( ) : Observable < EPerson > {
6057 return observableOf ( this . activeEPerson ) ;
6158 } ,
@@ -184,12 +181,8 @@ describe('EPersonFormComponent', () => {
184181 paginationService = new PaginationServiceStub ( ) ;
185182 TestBed . configureTestingModule ( {
186183 imports : [ CommonModule , NgbModule , FormsModule , ReactiveFormsModule , BrowserModule ,
187- TranslateModule . forRoot ( {
188- loader : {
189- provide : TranslateLoader ,
190- useClass : TranslateLoaderMock
191- }
192- } ) ,
184+ RouterTestingModule ,
185+ TranslateModule . forRoot ( ) ,
193186 ] ,
194187 declarations : [ EPersonFormComponent ] ,
195188 providers : [
@@ -204,7 +197,7 @@ describe('EPersonFormComponent', () => {
204197 { provide : EpersonRegistrationService , useValue : epersonRegistrationService } ,
205198 EPeopleRegistryComponent
206199 ] ,
207- schemas : [ NO_ERRORS_SCHEMA ]
200+ schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
208201 } ) . compileComponents ( ) ;
209202 } ) ) ;
210203
@@ -223,37 +216,13 @@ describe('EPersonFormComponent', () => {
223216 } ) ;
224217
225218 describe ( 'check form validation' , ( ) => {
226- let firstName ;
227- let lastName ;
228- let email ;
229- let canLogIn ;
230- let requireCertificate ;
219+ let canLogIn : boolean ;
220+ let requireCertificate : boolean ;
231221
232- let expected ;
233222 beforeEach ( ( ) => {
234- firstName = 'testName' ;
235- lastName = 'testLastName' ;
236- email = 'testEmail@test.com' ;
237223 canLogIn = false ;
238224 requireCertificate = false ;
239225
240- expected = Object . assign ( new EPerson ( ) , {
241- metadata : {
242- 'eperson.firstname' : [
243- {
244- value : firstName
245- }
246- ] ,
247- 'eperson.lastname' : [
248- {
249- value : lastName
250- } ,
251- ] ,
252- } ,
253- email : email ,
254- canLogIn : canLogIn ,
255- requireCertificate : requireCertificate ,
256- } ) ;
257226 spyOn ( component . submitForm , 'emit' ) ;
258227 component . canLogIn . value = canLogIn ;
259228 component . requireCertificate . value = requireCertificate ;
@@ -343,15 +312,13 @@ describe('EPersonFormComponent', () => {
343312 } ) ;
344313 } ) ) ;
345314 } ) ;
346-
347-
348-
349315 } ) ;
316+
350317 describe ( 'when submitting the form' , ( ) => {
351318 let firstName ;
352319 let lastName ;
353320 let email ;
354- let canLogIn ;
321+ let canLogIn : boolean ;
355322 let requireCertificate ;
356323
357324 let expected ;
@@ -380,6 +347,7 @@ describe('EPersonFormComponent', () => {
380347 requireCertificate : requireCertificate ,
381348 } ) ;
382349 spyOn ( component . submitForm , 'emit' ) ;
350+ component . ngOnInit ( ) ;
383351 component . firstName . value = firstName ;
384352 component . lastName . value = lastName ;
385353 component . email . value = email ;
@@ -421,9 +389,17 @@ describe('EPersonFormComponent', () => {
421389 email : email ,
422390 canLogIn : canLogIn ,
423391 requireCertificate : requireCertificate ,
424- _links : undefined
392+ _links : {
393+ groups : {
394+ href : '' ,
395+ } ,
396+ self : {
397+ href : '' ,
398+ } ,
399+ } ,
425400 } ) ;
426401 spyOn ( ePersonDataServiceStub , 'getActiveEPerson' ) . and . returnValue ( observableOf ( expectedWithId ) ) ;
402+ component . ngOnInit ( ) ;
427403 component . onSubmit ( ) ;
428404 fixture . detectChanges ( ) ;
429405 } ) ;
@@ -473,22 +449,19 @@ describe('EPersonFormComponent', () => {
473449 } ) ;
474450
475451 describe ( 'delete' , ( ) => {
476-
477- let ePersonId ;
478452 let eperson : EPerson ;
479453 let modalService ;
480454
481455 beforeEach ( ( ) => {
482456 spyOn ( authService , 'impersonate' ) . and . callThrough ( ) ;
483- ePersonId = 'testEPersonId' ;
484457 eperson = EPersonMock ;
485458 component . epersonInitial = eperson ;
486459 component . canDelete$ = observableOf ( true ) ;
487460 spyOn ( component . epersonService , 'getActiveEPerson' ) . and . returnValue ( observableOf ( eperson ) ) ;
488461 modalService = ( component as any ) . modalService ;
489462 spyOn ( modalService , 'open' ) . and . returnValue ( Object . assign ( { componentInstance : Object . assign ( { response : observableOf ( true ) } ) } ) ) ;
463+ component . ngOnInit ( ) ;
490464 fixture . detectChanges ( ) ;
491-
492465 } ) ;
493466
494467 it ( 'the delete button should be active if the eperson can be deleted' , ( ) => {
0 commit comments