hello
for a study project i do unit test on this code but i dont understand how unit test work.
I found example of code but nothing who explain the methodology,
please give me a way.
(sorry for the mistake i am french)
indent preformatted text by 4 spaces
import {Component} from ‘@angular/core’;
import { UserServices } from ‘./…/…/providers/user-services’;
import { SignInForm } from ‘…/signin-form/signin-form’;
import {FormGroup, FormBuilder, Validators, AbstractControl} from “@angular/forms”;
import {PasswordValidator} from “./password”;
import { NavController, AlertController} from ‘ionic-angular’;
import { MenuController } from ‘ionic-angular/index’;
@Component({
selector: 'signup-form',
templateUrl: 'signup-form.html'
})
export class SignUpForm {
myForm: FormGroup;
userInfo: {
firstname: string,
lastname: string,
birthday: string,
email: string
username: string,
password: string,
confirmPassword: string
} = {firstname: '', lastname: '', birthday: '', email: '', username: '', password: '', confirmPassword: ''};
password: AbstractControl;
confirmPassword: AbstractControl;
constructor(private builder: FormBuilder, private userService: UserServices, public navCtrl: NavController,
public alertCtrl: AlertController, private menu: MenuController) {
this.myForm = builder.group({
'firstname': ['', Validators.compose([Validators.required, Validators.minLength(2), Validators.maxLength(20),
Validators.pattern('[a-zA-Z àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ-]*')])],
'lastname': ['', Validators.compose([Validators.required, Validators.minLength(2), Validators.maxLength(20),
Validators.pattern('[a-zA-Z àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ-]*')])],
'birthday': ['', Validators.required],
'email': ['', Validators.compose([Validators.required,
Validators.pattern('[a-zA-Z0-9!#$%&*+/=?^_{|}~-]+(?:\.[a-zA-Z0-9!#$%&*+/=?^_{|}~-]+)*@(?:[a-zA-Z0-9](?:' +
'[a-z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?')])],
'username': ['', Validators.compose([Validators.minLength(2), Validators.maxLength(20),
Validators.pattern('[A-Za-z0-9]*')])],//
'password': ['', Validators.compose([Validators.minLength(8), Validators.maxLength(20),
Validators.pattern("[A-Za-z0-9,?;.:/!*-+$()&]*")])],
'confirmPassword': ['', Validators.compose([Validators.minLength(8), Validators.maxLength(20),
Validators.pattern("[A-Za-z0-9,?;.:/!*-+$()&]*")])]
}, { 'validator': PasswordValidator.isMatching })
this.password = this.myForm.controls['password'];
this.confirmPassword = this.myForm.controls['confirmPassword'];
}
/**
* Disable the side menu after view loaded
*/
ionViewDidEnter() {
this.menu.swipeEnable(false, 'sideMenu');
}
addUser(formData){
this.userService.addUser(formData.value).subscribe(
data => {
console.log(data);
this.showAlert();
this.navCtrl.push(SignInForm);
},
err => console.error(err),
() => console.log('done')
);
}
showAlert() {
let alert = this.alertCtrl.create({
title: 'Inscription réussie!',
subTitle: 'Un email de confirmation vient de vous être envoyé.<br/> Activez votre compte pour pouvoir l\'utiliser.',
buttons: ['OK']
});
alert.present();
}
}
indent preformatted text by 4 spaces