Login Validation
This commit is contained in:
parent
056cd60d0d
commit
a5262894ed
@ -1,6 +1,6 @@
|
|||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { FormsModule } from '@angular/forms';
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||||
|
|
||||||
import { IonicModule } from '@ionic/angular';
|
import { IonicModule } from '@ionic/angular';
|
||||||
|
|
||||||
@ -13,7 +13,8 @@ import { LoginPage } from './login.page';
|
|||||||
CommonModule,
|
CommonModule,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
IonicModule,
|
IonicModule,
|
||||||
LoginPageRoutingModule
|
LoginPageRoutingModule,
|
||||||
|
ReactiveFormsModule
|
||||||
],
|
],
|
||||||
declarations: [LoginPage]
|
declarations: [LoginPage]
|
||||||
})
|
})
|
||||||
|
44
ui/src/app/pages/login/login.page.form.spec.ts
Normal file
44
ui/src/app/pages/login/login.page.form.spec.ts
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import { FormBuilder, FormGroup } from "@angular/forms";
|
||||||
|
import { LoginPageForm } from "./login.page.form";
|
||||||
|
|
||||||
|
describe(`LoginPageForm`, () => {
|
||||||
|
|
||||||
|
let loginPageForm : LoginPageForm;
|
||||||
|
let form: FormGroup
|
||||||
|
|
||||||
|
beforeEach(() =>{
|
||||||
|
loginPageForm = new LoginPageForm(new FormBuilder());
|
||||||
|
form = loginPageForm.createForm();
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should create login form empty', () => {
|
||||||
|
const loginPageForm = new LoginPageForm(new FormBuilder());
|
||||||
|
const form = loginPageForm.createForm();
|
||||||
|
expect(form).not.toBeNull();
|
||||||
|
expect(form.get('email')).not.toBeNull();
|
||||||
|
expect(form.get('email').value).toEqual("");
|
||||||
|
expect(form.get('email').valid).toBeFalsy();
|
||||||
|
expect(form.get('password')).not.toBeNull();
|
||||||
|
expect(form.get('password').value).toEqual("");
|
||||||
|
expect(form.get('password').valid).toBeFalsy();
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should have email invalid if email is not valid', () => {
|
||||||
|
form.get('email').setValue('invalid email');
|
||||||
|
|
||||||
|
expect(form.get('email').valid).toBeFalsy();
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should have email valid if email is valid', () => {
|
||||||
|
form.get('email').setValue('valid@email.test');
|
||||||
|
|
||||||
|
expect(form.get('email').valid).toBeTruthy();
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should have a valid from', () => {
|
||||||
|
form.get('email').setValue('valid@email.test');
|
||||||
|
form.get('password').setValue('12345678');
|
||||||
|
|
||||||
|
expect(form.valid).toBeTruthy();
|
||||||
|
})
|
||||||
|
})
|
14
ui/src/app/pages/login/login.page.form.ts
Normal file
14
ui/src/app/pages/login/login.page.form.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
|
||||||
|
|
||||||
|
export class LoginPageForm {
|
||||||
|
private formBuilder: FormBuilder
|
||||||
|
constructor(formBuilder: FormBuilder){
|
||||||
|
this.formBuilder = formBuilder;
|
||||||
|
}
|
||||||
|
createForm() : FormGroup {
|
||||||
|
return this.formBuilder.group({
|
||||||
|
email: ['', [Validators.required, Validators.email]],
|
||||||
|
password: ['', [Validators.required]]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -1,35 +1,37 @@
|
|||||||
<ion-content>
|
<ion-content>
|
||||||
<div class="flex-center">
|
<div class="flex-center">
|
||||||
<ion-card>
|
<form [formGroup]="form">
|
||||||
<ion-card-header>
|
<ion-card>
|
||||||
<ion-card-title color="primary">Login</ion-card-title>
|
<ion-card-header>
|
||||||
<ion-card-subtitle color="secondary">Please sign in with your credentials</ion-card-subtitle>
|
<ion-card-title color="primary">Login</ion-card-title>
|
||||||
</ion-card-header>
|
<ion-card-subtitle color="secondary">Please sign in with your credentials</ion-card-subtitle>
|
||||||
<ion-card-content>
|
</ion-card-header>
|
||||||
<ion-item fill="solid">
|
<ion-card-content>
|
||||||
<ion-label position="floating">Email</ion-label>
|
<ion-item fill="solid">
|
||||||
<ion-input type="email" ngModel email></ion-input>
|
<ion-label position="floating">Email</ion-label>
|
||||||
<ion-note slot="helper">Enter a valid email</ion-note>
|
<ion-input type="email" formControlName="email"></ion-input>
|
||||||
<ion-note slot="error">Invalid email</ion-note>
|
<ion-note slot="helper">Enter a valid email</ion-note>
|
||||||
<ion-note slot="success">Valid email</ion-note>
|
<ion-note slot="error">Invalid email</ion-note>
|
||||||
</ion-item>
|
<ion-note slot="success">Valid email</ion-note>
|
||||||
<ion-item fill="solid">
|
</ion-item>
|
||||||
<ion-label position="floating">Password</ion-label>
|
<ion-item fill="solid">
|
||||||
<ion-input type="Password" ngModel password></ion-input>
|
<ion-label position="floating">Password</ion-label>
|
||||||
<ion-note slot="helper">Choose a secure password</ion-note>
|
<ion-input type="Password" formControlName="password"></ion-input>
|
||||||
</ion-item>
|
<ion-note slot="helper">Choose a secure password</ion-note>
|
||||||
<ion-button fill="clear" >
|
</ion-item>
|
||||||
Forgot Email/Password
|
<ion-button fill="clear" [disabled]="!form.get('email').valid" >
|
||||||
</ion-button>
|
Forgot Password
|
||||||
<ion-button size="full">
|
</ion-button>
|
||||||
Login
|
<ion-button size="full" [disabled]="!form.valid">
|
||||||
<ion-icon slot="end" name="log-in-outline"></ion-icon>
|
Login
|
||||||
</ion-button>
|
<ion-icon slot="end" name="log-in-outline"></ion-icon>
|
||||||
<ion-button fill="clear" color="secondary" size="full">
|
</ion-button>
|
||||||
|
<ion-button fill="clear" color="secondary" size="full">
|
||||||
Register
|
Register
|
||||||
<ion-icon slot="end" name="create-outline"></ion-icon>
|
<ion-icon slot="end" name="create-outline"></ion-icon>
|
||||||
</ion-button>
|
</ion-button>
|
||||||
</ion-card-content>
|
</ion-card-content>
|
||||||
</ion-card>
|
</ion-card>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||||
|
import { ReactiveFormsModule } from '@angular/forms';
|
||||||
import { IonicModule } from '@ionic/angular';
|
import { IonicModule } from '@ionic/angular';
|
||||||
|
import { AppRoutingModule } from 'src/app/app-routing.module';
|
||||||
|
|
||||||
import { LoginPage } from './login.page';
|
import { LoginPage } from './login.page';
|
||||||
|
|
||||||
@ -10,7 +12,11 @@ describe('LoginPage', () => {
|
|||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [ LoginPage ],
|
declarations: [ LoginPage ],
|
||||||
imports: [IonicModule.forRoot()]
|
imports: [
|
||||||
|
IonicModule.forRoot(),
|
||||||
|
AppRoutingModule,
|
||||||
|
ReactiveFormsModule
|
||||||
|
]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
|
|
||||||
fixture = TestBed.createComponent(LoginPage);
|
fixture = TestBed.createComponent(LoginPage);
|
||||||
@ -18,7 +24,9 @@ describe('LoginPage', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should create', () => {
|
it('should create form on init', () => {
|
||||||
expect(component).toBeTruthy();
|
component.ngOnInit();
|
||||||
|
|
||||||
|
expect(component.form).not.toBeUndefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { LoginPageForm } from './login.page.form';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-login',
|
selector: 'app-login',
|
||||||
@ -7,9 +10,12 @@ import { Component, OnInit } from '@angular/core';
|
|||||||
})
|
})
|
||||||
export class LoginPage implements OnInit {
|
export class LoginPage implements OnInit {
|
||||||
|
|
||||||
constructor() { }
|
form: FormGroup;
|
||||||
|
|
||||||
|
constructor(private router: Router, private formBuilder: FormBuilder) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
this.form = new LoginPageForm(this.formBuilder).createForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user