Commit d14453c8 authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

WIP: Add tests

parent c92189a6
......@@ -45,7 +45,7 @@
</li>
<li class="divider dropdown-divider"></li>
<li role="menuitem">
<a class="dropdown-item text-danger pointer" (click)="logout.emit()">
<a class="dropdown-item text-danger pointer" (click)="emitLogout()">
<span class="fas fa-sign-out-alt fa-fw"></span> Sign Out
</a>
</li>
......
......@@ -2,7 +2,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NavComponent } from './nav.component';
describe('Component: NavComponent', () => {
describe('[Core] Component: NavComponent', () => {
let component: NavComponent;
let fixture: ComponentFixture<NavComponent>;
......@@ -45,4 +45,9 @@ describe('Component: NavComponent', () => {
const template = fixture.nativeElement;
expect(template.querySelector('#button-sign-in')).toBeFalsy();
});
it('raises the logout event when clicked', () => {
component.logout.subscribe((event) => expect(event).toBe(undefined));
component.emitLogout();
});
});
......@@ -11,6 +11,10 @@ import { LoginToken } from '../../login/store/model';
export class NavComponent {
@Input() isAuthenticated: boolean;
@Input() loginToken: LoginToken;
@Output() logout: EventEmitter<{}> = new EventEmitter();
@Output() logout: EventEmitter<any> = new EventEmitter();
isCollapsed = true;
emitLogout() {
this.logout.emit();
}
}
......@@ -2,7 +2,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NotFoundPageComponent } from './not-found-page.component';
describe('Component: NotFoundPageComponent', () => {
describe('[Core] Component: NotFoundPageComponent', () => {
let component: NotFoundPageComponent;
let fixture: ComponentFixture<NotFoundPageComponent>;
......
......@@ -2,7 +2,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ObjectDisplayComponent } from './object-display.component';
describe('Component: ObjectDisplayComponent', () => {
describe('[Detail] Component: ObjectDisplayComponent', () => {
it('#getAttributesVisible() should filter and sort #attributeList', () => {
const component = new ObjectDisplayComponent();
component.attributeList = [
......
......@@ -2,7 +2,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AccountBenefitsComponent } from './account-benefits.component';
describe('Component: AccountBenefitsComponent', () => {
describe('[Login] Component: AccountBenefitsComponent', () => {
let component: AccountBenefitsComponent;
let fixture: ComponentFixture<AccountBenefitsComponent>;
......
<form name="form" (ngSubmit)="f.form.valid && submitted.emit(f.form.value)" #f="ngForm" novalidate>
<form name="form" (ngSubmit)="f.form.valid && emitSubmit(f.form.value)" #f="ngForm" novalidate>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" id="email" class="form-control" name="email" [(ngModel)]="email" placeholder="Enter email"
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormForgotPasswordComponent } from './form-forgot-password.component';
import { FormsModule } from '@angular/forms';
describe('[Login] Component: FormForgotPasswordComponent', () => {
let component: FormForgotPasswordComponent;
let fixture: ComponentFixture<FormForgotPasswordComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [FormForgotPasswordComponent],
imports: [FormsModule]
});
fixture = TestBed.createComponent(FormForgotPasswordComponent);
component = fixture.componentInstance;
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('raises the submit form event when clicked', () => {
const email = 'test@email.com';
component.submitted.subscribe((event: string) => expect(event).toEqual(email));
component.emitSubmit(email);
});
});
......@@ -7,4 +7,8 @@ import { Component, Output, EventEmitter } from '@angular/core';
export class FormForgotPasswordComponent {
email = '';
@Output() submitted: EventEmitter<string> = new EventEmitter();
emitSubmit(email: string) {
this.submitted.emit(email);
}
}
<form name="form" (ngSubmit)="f.form.valid && submitted.emit(f.form.value)" #f="ngForm" novalidate>
<form name="form" (ngSubmit)="f.form.valid && emitSubmit(f.form.value)" #f="ngForm" novalidate>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" id="email" class="form-control" name="email" [(ngModel)]="model.email"
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { FormLoginComponent } from './form-login.component';
import { Login } from '../store/model';
describe('[Login] Component: FormLoginComponent', () => {
let component: FormLoginComponent;
let fixture: ComponentFixture<FormLoginComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [FormLoginComponent],
imports: [FormsModule]
});
fixture = TestBed.createComponent(FormLoginComponent);
component = fixture.componentInstance;
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('raises the submit form event when clicked', () => {
const login: Login = { email: 'test@email.com', password: 'password'};
component.submitted.subscribe((event: Login) => expect(event).toEqual(login));
component.emitSubmit(login);
});
});
import { Component, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { Component, Output, EventEmitter } from '@angular/core';
import { Login } from '../store/model';
......@@ -9,4 +9,8 @@ import { Login } from '../store/model';
export class FormLoginComponent {
model: Login = new Login();
@Output() submitted: EventEmitter<Login> = new EventEmitter();
emitSubmit(login: Login) {
this.submitted.emit(login);
}
}
<form (ngSubmit)="f.form.valid && submitted.emit(f.form.value)" #f="ngForm" novalidate>
<form (ngSubmit)="f.form.valid && emitSubmit(f.form.value)" #f="ngForm" novalidate>
<div class="form-group">
<label for="register_email">Email address</label>
<input type="email" id="register_email" class="form-control" name="email" [(ngModel)]="model.email"
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { FormRegisterComponent } from './form-register.component';
import { Login } from '../store/model';
describe('[Login] Component: FormRegisterComponent', () => {
let component: FormRegisterComponent;
let fixture: ComponentFixture<FormRegisterComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [FormRegisterComponent],
imports: [FormsModule]
});
fixture = TestBed.createComponent(FormRegisterComponent);
component = fixture.componentInstance;
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('raises the submit form event when clicked', () => {
const login: Login = { email: 'test@email.com', password: 'password'};
component.submitted.subscribe((event: Login) => expect(event).toEqual(login));
component.emitSubmit(login);
});
});
......@@ -9,4 +9,8 @@ import { Login } from '../store/model';
export class FormRegisterComponent {
model: Login = new Login();
@Output() submitted: EventEmitter<Login> = new EventEmitter();
emitSubmit(login: Login) {
this.submitted.emit(login);
}
}
......@@ -8,12 +8,12 @@ import * as fromLogin from '../store/login.reducer';
@Component({
selector: 'app-change-password',
templateUrl: 'change-password.component.html',
styleUrls: [ 'login.component.css']
styleUrls: ['login.component.css']
})
export class ChangePasswordComponent {
model = {password: '', newPassword: '', confirmPassword: ''};
model = { password: '', newPassword: '', confirmPassword: '' };
constructor(private store: Store<{login: fromLogin.State}>) { }
constructor(private store: Store<{ login: fromLogin.State }>) { }
submitted() {
this.store.dispatch(new loginActions.ChangePasswordAction({
......
......@@ -93,7 +93,7 @@
[label]="attribute.form_label"
[criterion]="getCriterion(attribute.id)"
(add)="add($event)"
(delete)="delete($event)">
(deleteCriterion)="delete($event)">
</app-between-date>
</div>
<div *ngSwitchCase="'time'">
......
......@@ -15,7 +15,7 @@
(click)="addCriterion()">
<span class="fas fa-plus fa-fw"></span>
</button>
<button class="btn btn-outline-danger" *ngIf="field.disabled" (click)="deleteCriterion()">
<button class="btn btn-outline-danger" *ngIf="field.disabled" (click)="emitDelete()">
<span class="fa fa-times fa-fw"></span>
</button>
</div>
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { BsDatepickerModule } from 'ngx-bootstrap';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BetweenDateComponent } from './between-date.component';
import { Criterion, BetweenCriterion } from '../../../store/model';
describe('[Search][Criteria][SearchType] Component: BetweenDateComponent', () => {
let component: BetweenDateComponent;
let fixture: ComponentFixture<BetweenDateComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [BetweenDateComponent],
imports: [BsDatepickerModule.forRoot(), FormsModule, ReactiveFormsModule]
});
fixture = TestBed.createComponent(BetweenDateComponent);
component = fixture.componentInstance;
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('#getDateString() should format a datetime object into a string', () => {
const dateObject = new Date('February 08, 2019 15:47:00');
const expectedDateString = '2019-02-08';
const formatedDate = component.getDateString(dateObject);
expect(formatedDate).toEqual(expectedDateString);
});
it('#getDefault() should not fill and enable form if criterion not defined', () => {
const expectedFieldValue = '';
component.getDefault(undefined);
expect(component.field.value).toEqual(expectedFieldValue);
expect(component.field.enabled).toBeTruthy();
});
it('#getDefault() should fill and disable form if criterion is defined', () => {
const criterion = new BetweenCriterion(1, '2019-02-08', '2019-02-17');
const expectedFieldValue = [new Date(criterion.min), new Date(criterion.max)];
component.getDefault(criterion);
expect(component.field.value).toEqual(expectedFieldValue);
expect(component.field.disabled).toBeTruthy();
});
// it('raises the add criterion event when clicked', () => {
// component.id = 123;
// component.deleteCriterion.subscribe((event: number) => expect(event).toEqual(component.id));
// component.emitDelete();
// });
// it('raises the delete criterion event when clicked', () => {
// component.id = 123;
// component.deleteCriterion.subscribe((event: number) => expect(event).toEqual(component.id));
// component.emitDelete();
// });
});
......@@ -17,19 +17,20 @@ export class BetweenDateComponent {
this.getDefault(criterion);
}
@Output() add: EventEmitter<BetweenCriterion> = new EventEmitter();
@Output() delete: EventEmitter<number> = new EventEmitter();
@Output() deleteCriterion: EventEmitter<number> = new EventEmitter();
field = new FormControl('');
addCriterion(): void {
console.log(this.field.value);
const dateMin = this.getDateString(this.field.value[0]);
const dateMax = this.getDateString(this.field.value[1]);
const fd = new BetweenCriterion(this.id, dateMin, dateMax);
this.add.emit(fd);
}
deleteCriterion() {
this.delete.emit(this.id);
emitDelete() {
this.deleteCriterion.emit(this.id);
}
getDefault(criterion: Criterion): void {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment