Skip to content
Permalink
Browse files
added unit test for center
  • Loading branch information
pembemiriam committed Oct 19, 2018
1 parent bcc1420 commit 3f5dd712917c392b6f95947e605969eee960b821
Showing 11 changed files with 122 additions and 66 deletions.
@@ -18,7 +18,7 @@
*/
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {Component, EventEmitter, ViewChild} from '@angular/core';
import {Employee} from '../../services/office/domain/employee.model';
import {Center} from '../../services/center/domain/center.model';
import {CenterFormComponent, EmployeeFormData, EmployeeSaveEvent} from './form.component';
import {User} from '../../services/identity/domain/user.model';
import {TranslateModule} from '@ngx-translate/core';
@@ -30,7 +30,7 @@ import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {FimsSharedModule} from '../../common/common.module';
import {MatIconModule, MatInputModule, MatOptionModule, MatSelectModule} from '@angular/material';

const employeeTemplate: Employee = {
const centerTemplate: Center = {
identifier: 'test',
givenName: 'test',
middleName: 'test',
@@ -41,6 +41,7 @@ const employeeTemplate: Employee = {
value: 'test@test.de',
preferenceLevel: 0
}],

assignedOffice: 'test'
};

@@ -49,7 +50,7 @@ const userTemplate: User = {
role: 'test'
};

describe('Test employee form component', () => {
describe('Test center form component', () => {

let fixture: ComponentFixture<TestComponent>;

@@ -89,16 +90,16 @@ describe('Test employee form component', () => {
fixture.detectChanges();

testComponent.saveEmitter.subscribe((saveEvent: EmployeeSaveEvent) => {
expect(employeeTemplate.identifier).toEqual(saveEvent.detailForm.identifier);
expect(employeeTemplate.givenName).toEqual(saveEvent.detailForm.firstName);
expect(employeeTemplate.middleName).toEqual(saveEvent.detailForm.middleName);
expect(employeeTemplate.surname).toEqual(saveEvent.detailForm.lastName);
expect(centerTemplate.identifier).toEqual(saveEvent.detailForm.identifier);
expect(centerTemplate.givenName).toEqual(saveEvent.detailForm.firstName);
expect(centerTemplate.middleName).toEqual(saveEvent.detailForm.middleName);
expect(centerTemplate.surname).toEqual(saveEvent.detailForm.lastName);
expect(saveEvent.detailForm.password).toEqual('');

expect(employeeTemplate.assignedOffice).toEqual(saveEvent.officeForm.assignedOffice);
expect(centerTemplate.assignedOffice).toEqual(saveEvent.officeForm.assignedOffice);

expect(employeeTemplate.contactDetails.length).toEqual(1);
expect(employeeTemplate.contactDetails[0].value).toEqual(saveEvent.contactForm.email);
expect(centerTemplate.contactDetails.length).toEqual(1);
expect(centerTemplate.contactDetails[0].value).toEqual(saveEvent.contactForm.email);

expect(userTemplate.role).toEqual(saveEvent.detailForm.role);
});
@@ -110,17 +111,17 @@ describe('Test employee form component', () => {

@Component({
template: `
<fims-employee-form-component #form (onSave)="onSave($event)" (onCancel)="onCancel($event)" [formData]="employeeFormData">
</fims-employee-form-component>`
<fims-center-form-component #form (onSave)="onSave($event)" (onCancel)="onCancel($event)" [formData]="employeeFormData">
</fims-center-form-component>`
})
class TestComponent {

saveEmitter = new EventEmitter<EmployeeSaveEvent>();

@ViewChild('form') formComponent: EmployeeFormComponent;
@ViewChild('form') formComponent: CenterFormComponent;

employeeFormData: EmployeeFormData = {
employee: employeeTemplate,
employee: centerTemplate,
user: userTemplate
};

@@ -62,6 +62,13 @@ export interface EmployeeSaveEvent {
})
export class CenterFormComponent implements OnInit {

staffs = [
{value: '', viewValue: ''},

];



offices: Observable<Office[]>;

roles: Observable<Role[]>;
@@ -77,7 +84,7 @@ export class CenterFormComponent implements OnInit {
@Input('formData') set formData(formData: EmployeeFormData) {
this.prepareDetailForm(formData.employee, formData.user);
this.prepareOfficeForm(formData.employee);
this.prepareContactForm(formData.employee.contactDetails);
// this.prepareContactForm(formData.employee.contactDetails);
}

@Output('onSave') onSave = new EventEmitter<EmployeeSaveEvent>();
@@ -107,7 +114,7 @@ export class CenterFormComponent implements OnInit {
this.detailForm = this.formBuilder.group({
identifier: [employee.identifier, [Validators.required, Validators.minLength(3), Validators.maxLength(32), FimsValidators.urlSafe]],
firstName: [employee.givenName, [Validators.required, Validators.maxLength(256)]],
middleName: [employee.middleName, Validators.maxLength(256)],
middleName: [employee.middleName, Validators.maxLength(256)],
lastName: [employee.surname, [Validators.required, Validators.maxLength(256)]],
password: ['', passwordValidators],
role: [user ? user.role : '', Validators.required]
@@ -159,6 +166,7 @@ export class CenterFormComponent implements OnInit {
});
}


cancel(): void {
this.onCancel.emit();
}
@@ -1,8 +1,5 @@
<fims-layout-card-over title="{{'Collection sheet' | translate}}">
<fims-layout-card-over-header-menu>
<td-search-box #searchBox placeholder="{{'Search' | translate}}" (search)="search($event)" [alwaysVisible]="false"></td-search-box>
</fims-layout-card-over-header-menu>

<fims-layout-card-over title="{{'Collection sheet'}}">

<mat-form-field>
<mat-select placeholder="Select office">
<mat-option *ngFor="let office of offices" [value]="office.value">
@@ -1,14 +1,36 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { CollectionComponent } from './collection.component';
import {FimsSharedModule} from '.././common/common.module';
import {MatIconModule, MatInputModule, MatOptionModule, MatSelectModule} from '@angular/material';
import {ReactiveFormsModule} from '@angular/forms';
import {CovalentStepsModule} from '@covalent/core';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {TranslateModule} from '@ngx-translate/core';

describe('CenterComponent', () => {


describe('CollectionComponent', () => {
let component: CollectionComponent;
let fixture: ComponentFixture<CollectionComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CollectionComponent ]
declarations: [ CollectionComponent ],

imports: [
TranslateModule.forRoot(),
FimsSharedModule,
ReactiveFormsModule,
MatSelectModule,
MatOptionModule,
MatIconModule,
MatInputModule,
CovalentStepsModule,
NoopAnimationsModule,


],
})
.compileComponents();
}));
@@ -1,12 +1,30 @@
import {Component, OnInit} from '@angular/core';
import {ActivatedRoute, Params, Router} from '@angular/router';
import {Employee} from '../services/office/domain/employee.model';
import {FetchRequest} from '../services/domain/paging/fetch-request.model';
import {TableData} from '../common/data-table/data-table.component';

import {Store} from '@ngrx/store';
import * as fromRoot from '../store';
import {Observable} from 'rxjs/Observable';
import {SEARCH} from '../store/employee/employee.actions';



export interface Office {
value: string;
viewValue: string;
}

export interface Staff {
value: string;
viewValue: string;
}

export interface Center {
value: string;
viewValue: string;
}

export interface Group {
value: string;
viewValue: string;
}



@@ -16,8 +34,31 @@ import {SEARCH} from '../store/employee/employee.actions';
styleUrls: ['./collection.component.scss']
})
export class CollectionComponent implements OnInit {

offices: Office[] = [
{value: '', viewValue: ''},

];

staffs: Staff[] = [
{value: '', viewValue: ''},

];

centers: Center[] = [
{value: '', viewValue: ''},

];

groups: Group[] = [
{value: '', viewValue: ''},

];




employeeData$: Observable<TableData>;


loading$: Observable<boolean>;

@@ -31,42 +72,22 @@ export class CollectionComponent implements OnInit {

searchTerm: string;

private lastFetchRequest: FetchRequest = {};


constructor(private router: Router, private route: ActivatedRoute, private store: Store<fromRoot.State>) {}
constructor( private store: Store<fromRoot.State>) {}

ngOnInit(): void {

this.employeeData$ = this.store.select(fromRoot.getEmployeeSearchResults)
.map(employeePage => ({
data: employeePage.employees,
totalElements: employeePage.totalElements,
totalPages: employeePage.totalPages
}));


this.loading$ = this.store.select(fromRoot.getEmployeeSearchLoading);

this.route.queryParams.subscribe((params: Params) => {
this.search(params['term']);
});

}

search(searchTerm: string): void {
this.searchTerm = searchTerm;
this.fetchEmployees();
}

rowSelect(row: Employee): void {
this.router.navigate(['detail', row.identifier], { relativeTo: this.route });

}

fetchEmployees(fetchRequest?: FetchRequest) {
if (fetchRequest) {
this.lastFetchRequest = fetchRequest;
}

this.lastFetchRequest.searchTerm = this.searchTerm;

this.store.dispatch({ type: SEARCH, payload: this.lastFetchRequest });
}

}
@@ -15,7 +15,8 @@ import {
MatListModule,
MatOptionModule,
MatSelectModule,
MatToolbarModule
MatToolbarModule,
MatFormFieldModule
} from '@angular/material';
import {CovalentSearchModule, CovalentStepsModule} from '@covalent/core';
import {TranslateModule} from '@ngx-translate/core';
@@ -38,6 +39,7 @@ import {ReactiveFormsModule} from '@angular/forms';
MatSelectModule,
CovalentSearchModule,
CovalentStepsModule,
MatFormFieldModule

],
declarations: [
@@ -50,7 +50,8 @@ import {
MatSelectModule,
MatSnackBarModule,
MatToolbarModule,
MatTooltipModule
MatTooltipModule,
MatFormFieldModule
} from '@angular/material';
import {EmployeeAutoCompleteComponent} from './employee-autocomplete/employee-auto-complete.component';
import {TextMaskModule} from 'angular2-text-mask';
@@ -85,6 +86,7 @@ import {DisplayFimsFinancialNumber} from './number/fims-financial-number.pipe';
MatSnackBarModule,
MatToolbarModule,
MatTooltipModule,
MatFormFieldModule,
ReactiveFormsModule,
TextMaskModule,
TranslateModule
@@ -37,6 +37,8 @@ export class LoginComponent implements OnInit, OnDestroy {

private loadingSubscription: Subscription;

hide: boolean;

currentLanguage: string;

languageOptions: any[] = [
Empty file.
@@ -0,0 +1,10 @@
import {ContactDetail} from '../../domain/contact/contact-detail.model';

export interface Center {
identifier: string;
givenName: string;
middleName?: string;
surname: string;
assignedOffice?: string;
contactDetails: ContactDetail[];
}
@@ -27,13 +27,4 @@ export interface Employee {
contactDetails: ContactDetail[];
}

export interface Center {
identifier: string;
givenName: string;
middleName?: string;
surname: string;
assignedOffice?: string;
contactDetails: ContactDetail[];
}


0 comments on commit 3f5dd71

Please sign in to comment.