-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3721 from alexandrevryghem/w2p-117573_remove-obse…
…rvable-function-calls-from-template_contribute-7_x [Port dspace-7_x] Removed observable function calls from template (part 1)
- Loading branch information
Showing
29 changed files
with
878 additions
and
900 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { Observable, of as observableOf } from 'rxjs'; | ||
import { CommonModule } from '@angular/common'; | ||
import { NO_ERRORS_SCHEMA } from '@angular/core'; | ||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; | ||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | ||
import { UntypedFormControl, UntypedFormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms'; | ||
import { BrowserModule, By } from '@angular/platform-browser'; | ||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; | ||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { buildPaginatedList, PaginatedList } from '../../../core/data/paginated-list.model'; | ||
import { RemoteData } from '../../../core/data/remote-data'; | ||
import { EPersonDataService } from '../../../core/eperson/eperson-data.service'; | ||
|
@@ -19,7 +19,6 @@ import { EPersonMock, EPersonMock2 } from '../../../shared/testing/eperson.mock' | |
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils'; | ||
import { getMockFormBuilderService } from '../../../shared/mocks/form-builder-service.mock'; | ||
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub'; | ||
import { TranslateLoaderMock } from '../../../shared/mocks/translate-loader.mock'; | ||
import { AuthService } from '../../../core/auth/auth.service'; | ||
import { AuthServiceStub } from '../../../shared/testing/auth-service.stub'; | ||
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service'; | ||
|
@@ -35,6 +34,7 @@ import { FollowLinkConfig } from '../../../shared/utils/follow-link-config.model | |
import { ActivatedRoute, Router } from '@angular/router'; | ||
import { RouterStub } from '../../../shared/testing/router.stub'; | ||
import { ActivatedRouteStub } from '../../../shared/testing/active-router.stub'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
|
||
describe('EPersonFormComponent', () => { | ||
let component: EPersonFormComponent; | ||
|
@@ -59,9 +59,6 @@ describe('EPersonFormComponent', () => { | |
ePersonDataServiceStub = { | ||
activeEPerson: null, | ||
allEpeople: mockEPeople, | ||
getEPeople(): Observable<RemoteData<PaginatedList<EPerson>>> { | ||
return createSuccessfulRemoteDataObject$(buildPaginatedList(null, this.allEpeople)); | ||
}, | ||
getActiveEPerson(): Observable<EPerson> { | ||
return observableOf(this.activeEPerson); | ||
}, | ||
|
@@ -195,12 +192,8 @@ describe('EPersonFormComponent', () => { | |
router = new RouterStub(); | ||
TestBed.configureTestingModule({ | ||
imports: [CommonModule, NgbModule, FormsModule, ReactiveFormsModule, BrowserModule, | ||
TranslateModule.forRoot({ | ||
loader: { | ||
provide: TranslateLoader, | ||
useClass: TranslateLoaderMock | ||
} | ||
}), | ||
RouterTestingModule, | ||
TranslateModule.forRoot(), | ||
], | ||
declarations: [EPersonFormComponent], | ||
providers: [ | ||
|
@@ -217,7 +210,7 @@ describe('EPersonFormComponent', () => { | |
{ provide: Router, useValue: router }, | ||
EPeopleRegistryComponent | ||
], | ||
schemas: [NO_ERRORS_SCHEMA] | ||
schemas: [CUSTOM_ELEMENTS_SCHEMA], | ||
}).compileComponents(); | ||
})); | ||
|
||
|
@@ -236,37 +229,13 @@ describe('EPersonFormComponent', () => { | |
}); | ||
|
||
describe('check form validation', () => { | ||
let firstName; | ||
let lastName; | ||
let email; | ||
let canLogIn; | ||
let requireCertificate; | ||
let canLogIn: boolean; | ||
let requireCertificate: boolean; | ||
|
||
let expected; | ||
beforeEach(() => { | ||
firstName = 'testName'; | ||
lastName = 'testLastName'; | ||
email = '[email protected]'; | ||
canLogIn = false; | ||
requireCertificate = false; | ||
|
||
expected = Object.assign(new EPerson(), { | ||
metadata: { | ||
'eperson.firstname': [ | ||
{ | ||
value: firstName | ||
} | ||
], | ||
'eperson.lastname': [ | ||
{ | ||
value: lastName | ||
}, | ||
], | ||
}, | ||
email: email, | ||
canLogIn: canLogIn, | ||
requireCertificate: requireCertificate, | ||
}); | ||
spyOn(component.submitForm, 'emit'); | ||
component.canLogIn.value = canLogIn; | ||
component.requireCertificate.value = requireCertificate; | ||
|
@@ -340,15 +309,13 @@ describe('EPersonFormComponent', () => { | |
expect(component.formGroup.controls.email.errors.emailTaken).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
|
||
|
||
}); | ||
|
||
describe('when submitting the form', () => { | ||
let firstName; | ||
let lastName; | ||
let email; | ||
let canLogIn; | ||
let canLogIn: boolean; | ||
let requireCertificate; | ||
|
||
let expected; | ||
|
@@ -377,6 +344,7 @@ describe('EPersonFormComponent', () => { | |
requireCertificate: requireCertificate, | ||
}); | ||
spyOn(component.submitForm, 'emit'); | ||
component.ngOnInit(); | ||
component.firstName.value = firstName; | ||
component.lastName.value = lastName; | ||
component.email.value = email; | ||
|
@@ -416,9 +384,17 @@ describe('EPersonFormComponent', () => { | |
email: email, | ||
canLogIn: canLogIn, | ||
requireCertificate: requireCertificate, | ||
_links: undefined | ||
_links: { | ||
groups: { | ||
href: '', | ||
}, | ||
self: { | ||
href: '', | ||
}, | ||
}, | ||
}); | ||
spyOn(ePersonDataServiceStub, 'getActiveEPerson').and.returnValue(observableOf(expectedWithId)); | ||
component.ngOnInit(); | ||
component.onSubmit(); | ||
fixture.detectChanges(); | ||
}); | ||
|
@@ -466,22 +442,19 @@ describe('EPersonFormComponent', () => { | |
}); | ||
|
||
describe('delete', () => { | ||
|
||
let ePersonId; | ||
let eperson: EPerson; | ||
let modalService; | ||
|
||
beforeEach(() => { | ||
spyOn(authService, 'impersonate').and.callThrough(); | ||
ePersonId = 'testEPersonId'; | ||
eperson = EPersonMock; | ||
component.epersonInitial = eperson; | ||
component.canDelete$ = observableOf(true); | ||
spyOn(component.epersonService, 'getActiveEPerson').and.returnValue(observableOf(eperson)); | ||
modalService = (component as any).modalService; | ||
spyOn(modalService, 'open').and.returnValue(Object.assign({ componentInstance: Object.assign({ response: observableOf(true) }) })); | ||
component.ngOnInit(); | ||
fixture.detectChanges(); | ||
|
||
}); | ||
|
||
it('the delete button should be visible if the ePerson can be deleted', () => { | ||
|
Oops, something went wrong.