Skip to content

Commit 70f0af6

Browse files
117287: Removed method calls returning observables from the EPerson form
1 parent d09f529 commit 70f0af6

5 files changed

Lines changed: 140 additions & 187 deletions

File tree

src/app/access-control/epeople-registry/epeople-registry.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h3 id="search" class="border-bottom pb-2">{{labelPrefix + 'search.head' | trans
6666
</thead>
6767
<tbody>
6868
<tr *ngFor="let epersonDto of (ePeopleDto$ | async)?.page"
69-
[ngClass]="{'table-primary' : isActive(epersonDto.eperson) | async}">
69+
[ngClass]="{'table-primary' : (activeEPerson$ | async) === epersonDto.eperson}">
7070
<td>{{epersonDto.eperson.id}}</td>
7171
<td>{{ dsoNameService.getName(epersonDto.eperson) }}</td>
7272
<td>{{epersonDto.eperson.email}}</td>

src/app/access-control/epeople-registry/epeople-registry.component.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy {
4545
*/
4646
ePeopleDto$: BehaviorSubject<PaginatedList<EpersonDtoModel>> = new BehaviorSubject<PaginatedList<EpersonDtoModel>>({} as any);
4747

48+
activeEPerson$: Observable<EPerson>;
49+
4850
/**
4951
* An observable for the pageInfo, needed to pass to the pagination component
5052
*/
@@ -121,6 +123,7 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy {
121123
this.isEPersonFormShown = true;
122124
}
123125
}));
126+
this.activeEPerson$ = this.epersonService.getActiveEPerson();
124127
this.subs.push(this.ePeople$.pipe(
125128
switchMap((epeople: PaginatedList<EPerson>) => {
126129
if (epeople.pageInfo.totalElements > 0) {
@@ -188,29 +191,12 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy {
188191
);
189192
}
190193

191-
/**
192-
* Checks whether the given EPerson is active (being edited)
193-
* @param eperson
194-
*/
195-
isActive(eperson: EPerson): Observable<boolean> {
196-
return this.getActiveEPerson().pipe(
197-
map((activeEPerson) => eperson === activeEPerson)
198-
);
199-
}
200-
201-
/**
202-
* Gets the active eperson (being edited)
203-
*/
204-
getActiveEPerson(): Observable<EPerson> {
205-
return this.epersonService.getActiveEPerson();
206-
}
207-
208194
/**
209195
* Start editing the selected EPerson
210196
* @param ePerson
211197
*/
212198
toggleEditEPerson(ePerson: EPerson) {
213-
this.getActiveEPerson().pipe(take(1)).subscribe((activeEPerson: EPerson) => {
199+
this.activeEPerson$.pipe(take(1)).subscribe((activeEPerson: EPerson) => {
214200
if (ePerson === activeEPerson) {
215201
this.epersonService.cancelEditEPerson();
216202
this.isEPersonFormShown = false;

src/app/access-control/epeople-registry/eperson-form/eperson-form.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div *ngIf="epersonService.getActiveEPerson() | async; then editheader; else createHeader"></div>
1+
<div *ngIf="activeEPerson$ | async; then editheader; else createHeader"></div>
22

33
<ng-template #createHeader>
44
<h4>{{messagePrefix + '.create' | translate}}</h4>
@@ -39,7 +39,7 @@ <h4>{{messagePrefix + '.edit' | translate}}</h4>
3939

4040
<ds-themed-loading [showMessage]="false" *ngIf="!formGroup"></ds-themed-loading>
4141

42-
<div *ngIf="epersonService.getActiveEPerson() | async">
42+
<div *ngIf="activeEPerson$ | async">
4343
<h5>{{messagePrefix + '.groupsEPersonIsMemberOf' | translate}}</h5>
4444

4545
<ds-themed-loading [showMessage]="false" *ngIf="!(groups | async)"></ds-themed-loading>

src/app/access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts

Lines changed: 21 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Observable, of as observableOf } from 'rxjs';
22
import { CommonModule } from '@angular/common';
3-
import { NO_ERRORS_SCHEMA } from '@angular/core';
3+
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
44
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
55
import { UntypedFormControl, UntypedFormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
66
import { BrowserModule, By } from '@angular/platform-browser';
77
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
8-
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
8+
import { TranslateModule } from '@ngx-translate/core';
99
import { buildPaginatedList, PaginatedList } from '../../../core/data/paginated-list.model';
1010
import { RemoteData } from '../../../core/data/remote-data';
1111
import { EPersonDataService } from '../../../core/eperson/eperson-data.service';
@@ -19,7 +19,6 @@ import { EPersonMock, EPersonMock2 } from '../../../shared/testing/eperson.mock'
1919
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
2020
import { getMockFormBuilderService } from '../../../shared/mocks/form-builder-service.mock';
2121
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
22-
import { TranslateLoaderMock } from '../../../shared/mocks/translate-loader.mock';
2322
import { AuthService } from '../../../core/auth/auth.service';
2423
import { AuthServiceStub } from '../../../shared/testing/auth-service.stub';
2524
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
@@ -31,6 +30,7 @@ import { PaginationServiceStub } from '../../../shared/testing/pagination-servic
3130
import { FindListOptions } from '../../../core/data/find-list-options.model';
3231
import { ValidateEmailNotTaken } from './validators/email-taken.validator';
3332
import { EpersonRegistrationService } from '../../../core/data/eperson-registration.service';
33+
import { RouterTestingModule } from '@angular/router/testing';
3434

3535
describe('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

Comments
 (0)