Skip to content

Commit 230adc1

Browse files
Fixed failing EPeopleRegistryComponent test
Buttons to which you don't have access are now hidden by default instead of disabled
1 parent aa42a7e commit 230adc1

1 file changed

Lines changed: 22 additions & 39 deletions

File tree

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

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
55
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
66
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
77
import { 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';
1010
import { buildPaginatedList, PaginatedList } from '../../core/data/paginated-list.model';
1111
import { RemoteData } from '../../core/data/remote-data';
1212
import { EPersonDataService } from '../../core/eperson/eperson-data.service';
@@ -18,8 +18,6 @@ import { EPeopleRegistryComponent } from './epeople-registry.component';
1818
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';
21-
import { getMockTranslateService } from '../../shared/mocks/translate.service.mock';
22-
import { TranslateLoaderMock } from '../../shared/mocks/translate-loader.mock';
2321
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
2422
import { RouterStub } from '../../shared/testing/router.stub';
2523
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
@@ -31,17 +29,15 @@ import { FindListOptions } from '../../core/data/find-list-options.model';
3129
describe('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

Comments
 (0)