70373: Fix existing texts

This commit is contained in:
Kristof De Langhe
2020-04-15 15:35:41 +02:00
parent c48bb2cbb0
commit 4cd11bcbca
8 changed files with 94 additions and 36 deletions

View File

@@ -31,6 +31,8 @@ import { NotificationsServiceStub } from '../../../../shared/testing/notificatio
import { createSuccessfulRemoteDataObject$ } from '../../../../shared/testing/utils'; import { createSuccessfulRemoteDataObject$ } from '../../../../shared/testing/utils';
import { EPeopleRegistryComponent } from '../epeople-registry.component'; import { EPeopleRegistryComponent } from '../epeople-registry.component';
import { EPersonFormComponent } from './eperson-form.component'; import { EPersonFormComponent } from './eperson-form.component';
import { AuthService } from '../../../../core/auth/auth.service';
import { AuthServiceStub } from '../../../../shared/testing/auth-service-stub';
describe('EPersonFormComponent', () => { describe('EPersonFormComponent', () => {
let component: EPersonFormComponent; let component: EPersonFormComponent;
@@ -125,6 +127,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() },
EPeopleRegistryComponent EPeopleRegistryComponent
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]

View File

@@ -161,7 +161,9 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
private authService: AuthService) { private authService: AuthService) {
this.subs.push(this.epersonService.getActiveEPerson().subscribe((eperson: EPerson) => { this.subs.push(this.epersonService.getActiveEPerson().subscribe((eperson: EPerson) => {
this.epersonInitial = eperson; this.epersonInitial = eperson;
this.isImpersonated = this.authService.isImpersonatingUser(eperson.id); if (hasValue(eperson)) {
this.isImpersonated = this.authService.isImpersonatingUser(eperson.id);
}
})); }));
} }

View File

@@ -234,7 +234,7 @@ describe('AuthEffects', () => {
} }
}); });
const expected = cold('--b-', { b: new RetrieveAuthenticatedEpersonSuccessAction(EPersonMock) }); const expected = cold('--b-', { b: new RetrieveAuthenticatedEpersonSuccessAction(EPersonMock.id) });
expect(authEffects.retrieveAuthenticatedEperson$).toBeObservable(expected); expect(authEffects.retrieveAuthenticatedEperson$).toBeObservable(expected);
}); });

View File

@@ -189,7 +189,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EPersonMock userId: EPersonMock.id
}; };
const action = new LogOutAction(); const action = new LogOutAction();
@@ -206,7 +206,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EPersonMock userId: EPersonMock.id
}; };
const action = new LogOutSuccessAction(); const action = new LogOutSuccessAction();
@@ -219,7 +219,7 @@ describe('authReducer', () => {
loading: false, loading: false,
info: undefined, info: undefined,
refreshing: false, refreshing: false,
user: undefined userId: undefined
}; };
expect(newState).toEqual(state); expect(newState).toEqual(state);
}); });
@@ -232,7 +232,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EPersonMock userId: EPersonMock.id
}; };
const action = new LogOutErrorAction(mockError); const action = new LogOutErrorAction(mockError);
@@ -244,7 +244,7 @@ describe('authReducer', () => {
error: 'Test error message', error: 'Test error message',
loading: false, loading: false,
info: undefined, info: undefined,
user: EPersonMock userId: EPersonMock.id
}; };
expect(newState).toEqual(state); expect(newState).toEqual(state);
}); });
@@ -258,7 +258,7 @@ describe('authReducer', () => {
loading: true, loading: true,
info: undefined info: undefined
}; };
const action = new RetrieveAuthenticatedEpersonSuccessAction(EPersonMock); const action = new RetrieveAuthenticatedEpersonSuccessAction(EPersonMock.id);
const newState = authReducer(initialState, action); const newState = authReducer(initialState, action);
state = { state = {
authenticated: true, authenticated: true,
@@ -267,7 +267,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EPersonMock userId: EPersonMock.id
}; };
expect(newState).toEqual(state); expect(newState).toEqual(state);
}); });
@@ -301,7 +301,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EPersonMock userId: EPersonMock.id
}; };
const newTokenInfo = new AuthTokenInfo('Refreshed token'); const newTokenInfo = new AuthTokenInfo('Refreshed token');
const action = new RefreshTokenAction(newTokenInfo); const action = new RefreshTokenAction(newTokenInfo);
@@ -313,7 +313,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EPersonMock, userId: EPersonMock.id,
refreshing: true refreshing: true
}; };
expect(newState).toEqual(state); expect(newState).toEqual(state);
@@ -327,7 +327,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EPersonMock, userId: EPersonMock.id,
refreshing: true refreshing: true
}; };
const newTokenInfo = new AuthTokenInfo('Refreshed token'); const newTokenInfo = new AuthTokenInfo('Refreshed token');
@@ -340,7 +340,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EPersonMock, userId: EPersonMock.id,
refreshing: false refreshing: false
}; };
expect(newState).toEqual(state); expect(newState).toEqual(state);
@@ -354,7 +354,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EPersonMock, userId: EPersonMock.id,
refreshing: true refreshing: true
}; };
const action = new RefreshTokenErrorAction(); const action = new RefreshTokenErrorAction();
@@ -367,7 +367,7 @@ describe('authReducer', () => {
loading: false, loading: false,
info: undefined, info: undefined,
refreshing: false, refreshing: false,
user: undefined userId: undefined
}; };
expect(newState).toEqual(state); expect(newState).toEqual(state);
}); });
@@ -380,7 +380,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EPersonMock userId: EPersonMock.id
}; };
state = { state = {
@@ -390,7 +390,7 @@ describe('authReducer', () => {
loading: false, loading: false,
error: undefined, error: undefined,
info: 'Message', info: 'Message',
user: undefined userId: undefined
}; };
}); });

View File

@@ -12,12 +12,15 @@ import { AuthTokenInfo } from '../core/auth/models/auth-token-info.model';
import { EPersonDataService } from '../core/eperson/eperson-data.service'; import { EPersonDataService } from '../core/eperson/eperson-data.service';
import { NotificationsService } from '../shared/notifications/notifications.service'; import { NotificationsService } from '../shared/notifications/notifications.service';
import { authReducer } from '../core/auth/auth.reducer'; import { authReducer } from '../core/auth/auth.reducer';
import { of } from 'rxjs/internal/observable/of';
import { AuthService } from '../core/auth/auth.service';
describe('ProfilePageComponent', () => { describe('ProfilePageComponent', () => {
let component: ProfilePageComponent; let component: ProfilePageComponent;
let fixture: ComponentFixture<ProfilePageComponent>; let fixture: ComponentFixture<ProfilePageComponent>;
const user = Object.assign(new EPerson(), { const user = Object.assign(new EPerson(), {
id: 'userId',
groups: createSuccessfulRemoteDataObject$(createPaginatedList([])) groups: createSuccessfulRemoteDataObject$(createPaginatedList([]))
}); });
const authState = { const authState = {
@@ -25,9 +28,12 @@ describe('ProfilePageComponent', () => {
loaded: true, loaded: true,
loading: false, loading: false,
authToken: new AuthTokenInfo('test_token'), authToken: new AuthTokenInfo('test_token'),
user: user userId: user.id
}; };
const authService = jasmine.createSpyObj('authService', {
getAuthenticatedUserFromStore: of(user)
});
const epersonService = jasmine.createSpyObj('epersonService', { const epersonService = jasmine.createSpyObj('epersonService', {
findById: createSuccessfulRemoteDataObject$(user) findById: createSuccessfulRemoteDataObject$(user)
}); });
@@ -43,7 +49,8 @@ describe('ProfilePageComponent', () => {
imports: [StoreModule.forRoot(authReducer), TranslateModule.forRoot(), RouterTestingModule.withRoutes([])], imports: [StoreModule.forRoot(authReducer), TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
providers: [ providers: [
{ provide: EPersonDataService, useValue: epersonService }, { provide: EPersonDataService, useValue: epersonService },
{ provide: NotificationsService, useValue: notificationsService } { provide: NotificationsService, useValue: notificationsService },
{ provide: AuthService, useValue: authService }
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}).compileComponents(); }).compileComponents();

View File

@@ -14,6 +14,7 @@ import { HostWindowService } from '../host-window.service';
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { AuthTokenInfo } from '../../core/auth/models/auth-token-info.model'; import { AuthTokenInfo } from '../../core/auth/models/auth-token-info.model';
import { AuthService } from '../../core/auth/auth.service'; import { AuthService } from '../../core/auth/auth.service';
import { of } from 'rxjs/internal/observable/of';
describe('AuthNavMenuComponent', () => { describe('AuthNavMenuComponent', () => {
@@ -25,9 +26,19 @@ describe('AuthNavMenuComponent', () => {
let notAuthState: AuthState; let notAuthState: AuthState;
let authState: AuthState; let authState: AuthState;
let authService: AuthService;
let routerState = { let routerState = {
url: '/home' url: '/home'
}; };
function serviceInit() {
authService = jasmine.createSpyObj('authService', {
getAuthenticatedUserFromStore: of(EPersonMock),
setRedirectUrl: {}
});
}
function init() { function init() {
notAuthState = { notAuthState = {
authenticated: false, authenticated: false,
@@ -39,13 +50,14 @@ describe('AuthNavMenuComponent', () => {
loaded: true, loaded: true,
loading: false, loading: false,
authToken: new AuthTokenInfo('test_token'), authToken: new AuthTokenInfo('test_token'),
user: EPersonMock userId: EPersonMock.id
}; };
} }
describe('when is a not mobile view', () => { describe('when is a not mobile view', () => {
beforeEach(async(() => { beforeEach(async(() => {
const window = new HostWindowServiceStub(800); const window = new HostWindowServiceStub(800);
serviceInit();
// refine the test module by declaring the test component // refine the test module by declaring the test component
TestBed.configureTestingModule({ TestBed.configureTestingModule({
@@ -59,12 +71,7 @@ describe('AuthNavMenuComponent', () => {
], ],
providers: [ providers: [
{ provide: HostWindowService, useValue: window }, { provide: HostWindowService, useValue: window },
{ { provide: AuthService, useValue: authService }
provide: AuthService, useValue: {
setRedirectUrl: () => { /*empty*/
}
}
}
], ],
schemas: [ schemas: [
CUSTOM_ELEMENTS_SCHEMA CUSTOM_ELEMENTS_SCHEMA
@@ -239,6 +246,7 @@ describe('AuthNavMenuComponent', () => {
describe('when is a mobile view', () => { describe('when is a mobile view', () => {
beforeEach(async(() => { beforeEach(async(() => {
const window = new HostWindowServiceStub(300); const window = new HostWindowServiceStub(300);
serviceInit();
// refine the test module by declaring the test component // refine the test module by declaring the test component
TestBed.configureTestingModule({ TestBed.configureTestingModule({
@@ -252,12 +260,7 @@ describe('AuthNavMenuComponent', () => {
], ],
providers: [ providers: [
{ provide: HostWindowService, useValue: window }, { provide: HostWindowService, useValue: window },
{ { provide: AuthService, useValue: authService }
provide: AuthService, useValue: {
setRedirectUrl: () => { /*empty*/
}
}
}
], ],
schemas: [ schemas: [
CUSTOM_ELEMENTS_SCHEMA CUSTOM_ELEMENTS_SCHEMA

View File

@@ -12,6 +12,8 @@ import { AppState } from '../../../app.reducer';
import { MockTranslateLoader } from '../../mocks/mock-translate-loader'; import { MockTranslateLoader } from '../../mocks/mock-translate-loader';
import { cold } from 'jasmine-marbles'; import { cold } from 'jasmine-marbles';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { AuthService } from '../../../core/auth/auth.service';
import { of } from 'rxjs';
describe('UserMenuComponent', () => { describe('UserMenuComponent', () => {
@@ -20,6 +22,13 @@ describe('UserMenuComponent', () => {
let deUserMenu: DebugElement; let deUserMenu: DebugElement;
let authState: AuthState; let authState: AuthState;
let authStateLoading: AuthState; let authStateLoading: AuthState;
let authService: AuthService;
function serviceInit() {
authService = jasmine.createSpyObj('authService', {
getAuthenticatedUserFromStore: of(EPersonMock)
});
}
function init() { function init() {
authState = { authState = {
@@ -27,18 +36,19 @@ describe('UserMenuComponent', () => {
loaded: true, loaded: true,
loading: false, loading: false,
authToken: new AuthTokenInfo('test_token'), authToken: new AuthTokenInfo('test_token'),
user: EPersonMock userId: EPersonMock.id
}; };
authStateLoading = { authStateLoading = {
authenticated: true, authenticated: true,
loaded: true, loaded: true,
loading: true, loading: true,
authToken: null, authToken: null,
user: EPersonMock userId: EPersonMock.id
}; };
} }
beforeEach(async(() => { beforeEach(async(() => {
serviceInit();
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [
StoreModule.forRoot(authReducer), StoreModule.forRoot(authReducer),
@@ -49,6 +59,9 @@ describe('UserMenuComponent', () => {
} }
}) })
], ],
providers: [
{ provide: AuthService, useValue: authService }
],
declarations: [ declarations: [
UserMenuComponent UserMenuComponent
], ],
@@ -93,7 +106,7 @@ describe('UserMenuComponent', () => {
b: true b: true
})); }));
expect(component.user$).toBeObservable(cold('c', { expect(component.user$).toBeObservable(cold('(c|)', {
c: EPersonMock c: EPersonMock
})); }));
@@ -132,7 +145,7 @@ describe('UserMenuComponent', () => {
b: false b: false
})); }));
expect(component.user$).toBeObservable(cold('c', { expect(component.user$).toBeObservable(cold('(c|)', {
c: EPersonMock c: EPersonMock
})); }));

View File

@@ -5,6 +5,7 @@ import { EPersonMock } from './eperson-mock';
import { EPerson } from '../../core/eperson/models/eperson.model'; import { EPerson } from '../../core/eperson/models/eperson.model';
import { createSuccessfulRemoteDataObject$ } from './utils'; import { createSuccessfulRemoteDataObject$ } from './utils';
import { AuthMethod } from '../../core/auth/models/auth.method'; import { AuthMethod } from '../../core/auth/models/auth.method';
import { hasValue } from '../empty.util';
export const authMethodsMock = [ export const authMethodsMock = [
new AuthMethod('password'), new AuthMethod('password'),
@@ -14,6 +15,7 @@ export const authMethodsMock = [
export class AuthServiceStub { export class AuthServiceStub {
token: AuthTokenInfo = new AuthTokenInfo('token_test'); token: AuthTokenInfo = new AuthTokenInfo('token_test');
impersonating: string;
private _tokenExpired = false; private _tokenExpired = false;
private redirectUrl; private redirectUrl;
@@ -47,6 +49,10 @@ export class AuthServiceStub {
return observableOf(EPersonMock); return observableOf(EPersonMock);
} }
public retrieveAuthenticatedUserById(id: string): Observable<EPerson> {
return observableOf(EPersonMock);
}
public buildAuthHeader(token?: AuthTokenInfo): string { public buildAuthHeader(token?: AuthTokenInfo): string {
return `Bearer ${token.accessToken}`; return `Bearer ${token.accessToken}`;
} }
@@ -120,4 +126,28 @@ export class AuthServiceStub {
retrieveAuthMethodsFromAuthStatus(status: AuthStatus) { retrieveAuthMethodsFromAuthStatus(status: AuthStatus) {
return observableOf(authMethodsMock); return observableOf(authMethodsMock);
} }
impersonate(id: string) {
this.impersonating = id;
}
isImpersonating() {
return hasValue(this.impersonating);
}
isImpersonatingUser(id: string) {
return this.impersonating === id;
}
stopImpersonating() {
this.impersonating = undefined;
}
stopImpersonatingAndRefresh() {
this.stopImpersonating();
}
getImpersonateID() {
return this.impersonating;
}
} }