Refactored components' name and added missing tests

This commit is contained in:
Giuseppe Digilio
2020-01-02 18:21:47 +01:00
parent 972f0dfd60
commit fdd05d2fec
29 changed files with 637 additions and 285 deletions

View File

@@ -1,7 +0,0 @@
export enum AuthMethodType {
Password = 'password',
Shibboleth = 'shibboleth',
Ldap = 'ldap',
Ip = 'ip',
X509 = 'x509'
}

View File

@@ -1,4 +1,4 @@
import { AuthMethodType } from './authMethods-type';
import { AuthMethodType } from '../../../core/auth/models/auth.method-type';
const authMethodsMap = new Map();

View File

@@ -4,16 +4,17 @@ import { FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { By } from '@angular/platform-browser';
import { Store, StoreModule } from '@ngrx/store';
import { TranslateModule } from '@ngx-translate/core';
import { LogInPasswordComponent } from './log-in-password.component';
import { EPerson } from '../../../../core/eperson/models/eperson.model';
import { EPersonMock } from '../../../testing/eperson-mock';
import { authReducer } from '../../../../core/auth/auth.reducer';
import { TranslateModule } from '@ngx-translate/core';
import { AuthService } from '../../../../core/auth/auth.service';
import { AuthServiceStub } from '../../../testing/auth-service-stub';
import { AppState } from '../../../../app.reducer';
import { AuthMethodModel } from '../../../../core/auth/models/auth-method.model';
import { AuthMethodType } from '../authMethods-type';
import { AuthMethod } from '../../../../core/auth/models/auth.method';
import { AuthMethodType } from '../../../../core/auth/models/auth.method-type';
describe('LogInPasswordComponent', () => {
@@ -46,7 +47,7 @@ describe('LogInPasswordComponent', () => {
],
providers: [
{ provide: AuthService, useClass: AuthServiceStub },
{ provide: 'authMethodModelProvider', useValue: new AuthMethodModel(AuthMethodType.Password) }
{ provide: 'authMethodProvider', useValue: new AuthMethod(AuthMethodType.Password) }
],
schemas: [
CUSTOM_ELEMENTS_SCHEMA

View File

@@ -1,5 +1,5 @@
import { map } from 'rxjs/operators';
import { Component, Inject, Input, OnInit } from '@angular/core';
import { Component, Inject, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { select, Store } from '@ngrx/store';
@@ -8,12 +8,11 @@ import { AuthenticateAction, ResetAuthenticationMessagesAction } from '../../../
import { getAuthenticationError, getAuthenticationInfo, } from '../../../../core/auth/selectors';
import { CoreState } from '../../../../core/core.reducers';
import { isNotEmpty } from '../../../empty.util';
import { fadeOut } from '../../../animations/fade';
import { AuthMethodType } from '../authMethods-type';
import { renderAuthMethodFor } from '../authMethods-decorator';
import { AuthMethodModel } from '../../../../core/auth/models/auth-method.model';
import { AuthMethodType } from '../../../../core/auth/models/auth.method-type';
import { renderAuthMethodFor } from '../log-in.methods-decorator';
import { AuthMethod } from '../../../../core/auth/models/auth.method';
/**
* /users/sign-in
@@ -28,6 +27,12 @@ import { AuthMethodModel } from '../../../../core/auth/models/auth-method.model'
@renderAuthMethodFor(AuthMethodType.Password)
export class LogInPasswordComponent implements OnInit {
/**
* The authentication method data.
* @type {AuthMethod}
*/
public authMethod: AuthMethod;
/**
* The error if authentication fails.
* @type {Observable<string>}
@@ -58,21 +63,18 @@ export class LogInPasswordComponent implements OnInit {
*/
public form: FormGroup;
@Input() authMethodModel: AuthMethodModel;
/**
* @constructor
* @param {AuthMethodModel} injectedAuthMethodModel
* @param {AuthMethod} injectedAuthMethodModel
* @param {FormBuilder} formBuilder
* @param {Store<State>} store
*/
constructor(
@Inject('authMethodModelProvider') public injectedAuthMethodModel: AuthMethodModel,
/* private authService: AuthService,*/
@Inject('authMethodProvider') public injectedAuthMethodModel: AuthMethod,
private formBuilder: FormBuilder,
private store: Store<CoreState>
) {
this.authMethodModel = injectedAuthMethodModel;
this.authMethod = injectedAuthMethodModel;
}
/**
@@ -118,15 +120,6 @@ export class LogInPasswordComponent implements OnInit {
}
}
/**
* To the registration page.
* @method register
*/
public register() {
// TODO enable after registration process is done
// this.router.navigate(['/register']);
}
/**
* Submit the authentication form.
* @method submit

View File

@@ -0,0 +1,105 @@
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Store, StoreModule } from '@ngrx/store';
import { TranslateModule } from '@ngx-translate/core';
import { EPerson } from '../../../../core/eperson/models/eperson.model';
import { EPersonMock } from '../../../testing/eperson-mock';
import { authReducer } from '../../../../core/auth/auth.reducer';
import { AuthService } from '../../../../core/auth/auth.service';
import { AuthServiceStub } from '../../../testing/auth-service-stub';
import { AppState } from '../../../../app.reducer';
import { AuthMethod } from '../../../../core/auth/models/auth.method';
import { AuthMethodType } from '../../../../core/auth/models/auth.method-type';
import { LogInShibbolethComponent } from './log-in-shibboleth.component';
describe('LogInShibbolethComponent', () => {
let component: LogInShibbolethComponent;
let fixture: ComponentFixture<LogInShibbolethComponent>;
let page: Page;
let user: EPerson;
const authState = {
authenticated: false,
loaded: false,
loading: false,
};
beforeEach(() => {
user = EPersonMock;
});
beforeEach(async(() => {
// refine the test module by declaring the test component
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot(authReducer),
TranslateModule.forRoot()
],
declarations: [
LogInShibbolethComponent
],
providers: [
{ provide: AuthService, useClass: AuthServiceStub },
{ provide: 'authMethodProvider',
useValue: new AuthMethod(AuthMethodType.Shibboleth, 'dspace.test/shibboleth')
}
],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
]
})
.compileComponents();
}));
beforeEach(inject([Store], (store: Store<AppState>) => {
store
.subscribe((state) => {
(state as any).core = Object.create({});
(state as any).core.auth = authState;
});
// create component and test fixture
fixture = TestBed.createComponent(LogInShibbolethComponent);
// get test component from the fixture
component = fixture.componentInstance;
// create page
page = new Page(component, fixture);
}));
it('should display a link with properly href', () => {
fixture.detectChanges();
const link = fixture.debugElement.query(By.css('a'));
expect(link.nativeElement.getAttribute('href')).toBe('dspace.test/shibboleth');
});
});
/**
* I represent the DOM elements and attach spies.
*
* @class Page
*/
class Page {
public emailInput: HTMLInputElement;
public navigateSpy: jasmine.Spy;
public passwordInput: HTMLInputElement;
constructor(private component: LogInShibbolethComponent, private fixture: ComponentFixture<LogInShibbolethComponent>) {
// use injector to get services
const injector = fixture.debugElement.injector;
const store = injector.get(Store);
// add spies
this.navigateSpy = spyOn(store, 'dispatch');
}
}

View File

@@ -1,11 +1,11 @@
import { Component, Inject, Input, OnInit, } from '@angular/core';
import { Component, Inject, OnInit, } from '@angular/core';
import { Observable } from 'rxjs';
import { select, Store } from '@ngrx/store';
import { renderAuthMethodFor } from '../authMethods-decorator';
import { AuthMethodType } from '../authMethods-type';
import { AuthMethodModel } from '../../../../core/auth/models/auth-method.model';
import { renderAuthMethodFor } from '../log-in.methods-decorator';
import { AuthMethodType } from '../../../../core/auth/models/auth.method-type';
import { AuthMethod } from '../../../../core/auth/models/auth.method';
import { CoreState } from '../../../../core/core.reducers';
import { isAuthenticated, isAuthenticationLoading } from '../../../../core/auth/selectors';
@@ -19,7 +19,11 @@ import { isAuthenticated, isAuthenticationLoading } from '../../../../core/auth/
@renderAuthMethodFor(AuthMethodType.Shibboleth)
export class LogInShibbolethComponent implements OnInit {
@Input() authMethodModel: AuthMethodModel;
/**
* The authentication method data.
* @type {AuthMethod}
*/
public authMethod: AuthMethod;
/**
* True if the authentication is loading.
@@ -41,12 +45,14 @@ export class LogInShibbolethComponent implements OnInit {
/**
* @constructor
* @param {AuthMethod} injectedAuthMethodModel
* @param {Store<State>} store
*/
constructor(
@Inject('authMethodModelProvider') public injectedAuthMethodModel: AuthMethodModel,
@Inject('authMethodProvider') public injectedAuthMethodModel: AuthMethod,
private store: Store<CoreState>
) {
this.authMethodModel = injectedAuthMethodModel;
this.authMethod = injectedAuthMethodModel;
}
ngOnInit(): void {