mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
70373: EPerson impersonate tests
This commit is contained in:
@@ -42,6 +42,7 @@ describe('EPersonFormComponent', () => {
|
|||||||
|
|
||||||
let mockEPeople;
|
let mockEPeople;
|
||||||
let ePersonDataServiceStub: any;
|
let ePersonDataServiceStub: any;
|
||||||
|
let authService: AuthServiceStub;
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
mockEPeople = [EPersonMock, EPersonMock2];
|
mockEPeople = [EPersonMock, EPersonMock2];
|
||||||
@@ -106,6 +107,7 @@ describe('EPersonFormComponent', () => {
|
|||||||
};
|
};
|
||||||
builderService = getMockFormBuilderService();
|
builderService = getMockFormBuilderService();
|
||||||
translateService = getMockTranslateService();
|
translateService = getMockTranslateService();
|
||||||
|
authService = new AuthServiceStub();
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [CommonModule, NgbModule, FormsModule, ReactiveFormsModule, BrowserModule,
|
imports: [CommonModule, NgbModule, FormsModule, ReactiveFormsModule, BrowserModule,
|
||||||
TranslateModule.forRoot({
|
TranslateModule.forRoot({
|
||||||
@@ -127,7 +129,7 @@ describe('EPersonFormComponent', () => {
|
|||||||
{ provide: Store, useValue: {} },
|
{ provide: Store, useValue: {} },
|
||||||
{ provide: RemoteDataBuildService, useValue: {} },
|
{ provide: RemoteDataBuildService, useValue: {} },
|
||||||
{ provide: HALEndpointService, useValue: {} },
|
{ provide: HALEndpointService, useValue: {} },
|
||||||
{ provide: AuthService, useValue: new AuthServiceStub() },
|
{ provide: AuthService, useValue: authService },
|
||||||
EPeopleRegistryComponent
|
EPeopleRegistryComponent
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
@@ -231,4 +233,40 @@ describe('EPersonFormComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('impersonate', () => {
|
||||||
|
let ePersonId;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(authService, 'impersonate').and.callThrough();
|
||||||
|
ePersonId = 'testEPersonId';
|
||||||
|
component.epersonInitial = Object.assign(new EPerson(), {
|
||||||
|
id: ePersonId
|
||||||
|
});
|
||||||
|
component.impersonate();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call authService.impersonate', () => {
|
||||||
|
expect(authService.impersonate).toHaveBeenCalledWith(ePersonId);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set isImpersonated to true', () => {
|
||||||
|
expect(component.isImpersonated).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('stopImpersonating', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(authService, 'stopImpersonatingAndRefresh').and.callThrough();
|
||||||
|
component.stopImpersonating();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call authService.stopImpersonatingAndRefresh', () => {
|
||||||
|
expect(authService.stopImpersonatingAndRefresh).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set isImpersonated to false', () => {
|
||||||
|
expect(component.isImpersonated).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -0,0 +1,80 @@
|
|||||||
|
import { ImpersonateNavbarComponent } from './impersonate-navbar.component';
|
||||||
|
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
|
||||||
|
import { VarDirective } from '../utils/var.directive';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
import { AuthService } from '../../core/auth/auth.service';
|
||||||
|
import { Store, StoreModule } from '@ngrx/store';
|
||||||
|
import { authReducer, AuthState } from '../../core/auth/auth.reducer';
|
||||||
|
import { AuthTokenInfo } from '../../core/auth/models/auth-token-info.model';
|
||||||
|
import { EPersonMock } from '../testing/eperson-mock';
|
||||||
|
import { AppState } from '../../app.reducer';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
|
||||||
|
describe('ImpersonateNavbarComponent', () => {
|
||||||
|
let component: ImpersonateNavbarComponent;
|
||||||
|
let fixture: ComponentFixture<ImpersonateNavbarComponent>;
|
||||||
|
let authService: AuthService;
|
||||||
|
let authState: AuthState;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
authService = jasmine.createSpyObj('authService', {
|
||||||
|
isImpersonating: false,
|
||||||
|
stopImpersonatingAndRefresh: {}
|
||||||
|
});
|
||||||
|
authState = {
|
||||||
|
authenticated: true,
|
||||||
|
loaded: true,
|
||||||
|
loading: false,
|
||||||
|
authToken: new AuthTokenInfo('test_token'),
|
||||||
|
userId: EPersonMock.id
|
||||||
|
};
|
||||||
|
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ImpersonateNavbarComponent, VarDirective],
|
||||||
|
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), StoreModule.forRoot(authReducer)],
|
||||||
|
providers: [
|
||||||
|
{ provide: AuthService, useValue: authService }
|
||||||
|
],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(inject([Store], (store: Store<AppState>) => {
|
||||||
|
store
|
||||||
|
.subscribe((state) => {
|
||||||
|
(state as any).core = Object.create({});
|
||||||
|
(state as any).core.auth = authState;
|
||||||
|
});
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(ImpersonateNavbarComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('when the user is impersonating another user', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
component.isImpersonating = true;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should display a button', () => {
|
||||||
|
const button = fixture.debugElement.query(By.css('button'));
|
||||||
|
expect(button).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call authService\'s stopImpersonatingAndRefresh upon clicking the button', () => {
|
||||||
|
const button = fixture.debugElement.query(By.css('button')).nativeElement;
|
||||||
|
button.click();
|
||||||
|
expect(authService.stopImpersonatingAndRefresh).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the user is not impersonating another user', () => {
|
||||||
|
it('should not display a button', () => {
|
||||||
|
const button = fixture.debugElement.query(By.css('button'));
|
||||||
|
expect(button).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Reference in New Issue
Block a user