Skip to content
Permalink
Browse files
Merge pull request #10 from pembemiriam/master
Unit test for center
  • Loading branch information
awasum committed Oct 25, 2018
2 parents 6aa1b7d + 98b1e89 commit e048f09dce40e0dd50e7dbc4569d2d7458940cba
Showing 17 changed files with 104 additions and 210 deletions.
@@ -20,7 +20,7 @@ import {async, ComponentFixture, inject, TestBed} from '@angular/core/testing';
import {TranslateModule} from '@ngx-translate/core';
import {ReactiveFormsModule} from '@angular/forms';
import {CovalentStepsModule} from '@covalent/core';
import {CenterFormComponent, EmployeeSaveEvent} from '../form.component';
import {CenterFormComponent, CenterSaveEvent} from '../form.component';
import {ActivatedRoute, Router} from '@angular/router';
import {Observable} from 'rxjs/Observable';
import {CreateCenterFormComponent} from './create.form.component';
@@ -33,7 +33,7 @@ import {MatCardModule, MatInputModule, MatOptionModule, MatSelectModule} from '@
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
import {FimsSharedModule} from '../../../common/common.module';

const eventMock: EmployeeSaveEvent = {
const eventMock: CenterSaveEvent = {
detailForm: {
identifier: 'test',
firstName: 'test',
@@ -54,7 +54,7 @@ const eventMock: EmployeeSaveEvent = {

let router: Router;

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

let fixture: ComponentFixture<CreateCenterFormComponent>;

@@ -101,7 +101,7 @@ describe('Test employee form component', () => {
testComponent = fixture.componentInstance;
});

it('should test if employee is created', async(inject([EmployeesStore], (store: EmployeesStore) => {
it('should test if center is created', async(inject([EmployeesStore], (store: EmployeesStore) => {
fixture.detectChanges();

testComponent.onSave(eventMock);
@@ -118,12 +118,5 @@ describe('Test employee form component', () => {
});
})));

xit('should test if error is set on 409', async(() => {
fixture.detectChanges();

fixture.whenStable().then(() => {
expect(testComponent.formComponent.detailForm.get('identifier').errors).toBeDefined();
expect(testComponent.formComponent.detailForm.get('identifier').errors['unique']).toBeTruthy();
});
}));

});
@@ -18,7 +18,7 @@
*/
import {Component, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {CenterFormComponent, EmployeeFormData, EmployeeSaveEvent} from '../form.component';
import {CenterFormComponent, CenterFormData, CenterSaveEvent} from '../form.component';
import {mapEmployee, mapUser} from '../form.mapper';
import {Employee} from '../../../services/office/domain/employee.model';
import {UserWithPassword} from '../../../services/identity/domain/user-with-password.model';
@@ -37,7 +37,7 @@ export class CreateCenterFormComponent implements OnInit, OnDestroy {

@ViewChild('form') formComponent: CenterFormComponent;

employeeFormData: EmployeeFormData = {
employeeFormData: CenterFormData = {
user: { identifier: '', role: ''},
employee: { identifier: '', givenName: '', surname: '', contactDetails: [] }
};
@@ -62,7 +62,7 @@ export class CreateCenterFormComponent implements OnInit, OnDestroy {
this.store.dispatch({ type: RESET_FORM });
}

onSave(event: EmployeeSaveEvent): void {
onSave(event: CenterSaveEvent): void {
const employee: Employee = mapEmployee(event);
const user: UserWithPassword = mapUser(event);

@@ -63,7 +63,7 @@ const activatedRoute = {
};
let router: Router;

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

let fixture: ComponentFixture<EditCenterFormComponent>;

@@ -117,7 +117,7 @@ describe('Test employee form component', () => {
testComponent = fixture.componentInstance;
});

it('should test if employee is updated', async(inject([EmployeesStore], (store: EmployeesStore) => {
it('should test if center is updated', async(inject([EmployeesStore], (store: EmployeesStore) => {
fixture.detectChanges();

testComponent.formComponent.detailForm.get('password').setValue('newPassword');
@@ -18,7 +18,7 @@
*/
import {Component, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {CenterFormComponent, EmployeeFormData, EmployeeSaveEvent} from '../form.component';
import {CenterFormComponent, CenterFormData, CenterSaveEvent} from '../form.component';
import {mapContactDetails, mapEmployee} from '../form.mapper';
import {Employee} from '../../../services/office/domain/employee.model';
import {User} from '../../../services/identity/domain/user.model';
@@ -33,7 +33,7 @@ export class EditCenterFormComponent implements OnInit {

@ViewChild('form') formComponent: CenterFormComponent;

formData: Observable<EmployeeFormData>;
formData: Observable<CenterFormData>;

employee: Employee;

@@ -54,7 +54,7 @@ export class EditCenterFormComponent implements OnInit {
);
}

onSave(event: EmployeeSaveEvent) {
onSave(event: CenterSaveEvent) {
const employee: Employee = mapEmployee(event);

this.store.dispatch({ type: UPDATE, payload: {
@@ -18,8 +18,8 @@
*/
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {Component, EventEmitter, ViewChild} from '@angular/core';
import {Employee} from '../../services/office/domain/employee.model';
import {CenterFormComponent, EmployeeFormData, EmployeeSaveEvent} from './form.component';
import {Center} from '../../services/center/domain/center.model';
import {CenterFormComponent, CenterFormData, CenterSaveEvent} from './form.component';
import {User} from '../../services/identity/domain/user.model';
import {TranslateModule} from '@ngx-translate/core';
import {ReactiveFormsModule} from '@angular/forms';
@@ -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>;

@@ -88,17 +89,17 @@ describe('Test employee form component', () => {
it('should test if the form save the original values', () => {
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);
testComponent.saveEmitter.subscribe((saveEvent: CenterSaveEvent) => {
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,26 +111,26 @@ 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>();
saveEmitter = new EventEmitter<CenterSaveEvent>();

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

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

triggerSave(): void {
this.formComponent.save();
}

onSave(event: EmployeeSaveEvent): void {
onSave(event: CenterSaveEvent): void {
this.saveEmitter.emit(event);
}

}
}
@@ -33,12 +33,12 @@ import {SEARCH as SEARCH_OFFICE} from '../../store/office/office.actions';
import {SEARCH as SEARCH_ROLE} from '../../store/role/role.actions';
import { Staff } from '../../services/domain/center/staff';

export interface EmployeeFormData {
export interface CenterFormData {
user: User;
employee: Employee;
}

export interface EmployeeSaveEvent {
export interface CenterSaveEvent {
detailForm: {
identifier: string;
firstName: string;
@@ -63,6 +63,7 @@ export interface EmployeeSaveEvent {
})
export class CenterFormComponent implements OnInit {


offices: Observable<Office[]>;

roles: Observable<Role[]>;
@@ -77,13 +78,13 @@ export class CenterFormComponent implements OnInit {

@Input('editMode') editMode: boolean;

@Input('formData') set formData(formData: EmployeeFormData) {
@Input('formData') set formData(formData: CenterFormData) {
this.prepareDetailForm(formData.employee, formData.user);
this.prepareOfficeForm(formData.employee);
this.prepareContactForm(formData.employee.contactDetails);
}

@Output('onSave') onSave = new EventEmitter<EmployeeSaveEvent>();
@Output('onSave') onSave = new EventEmitter<CenterSaveEvent>();
@Output('onCancel') onCancel = new EventEmitter<void>();

constructor(private formBuilder: FormBuilder, private store: Store<fromRoot.State>) {}
@@ -110,7 +111,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]
@@ -162,6 +163,7 @@ export class CenterFormComponent implements OnInit {
});
}


cancel(): void {
this.onCancel.emit();
}
@@ -17,7 +17,7 @@
* under the License.
*/

import {EmployeeSaveEvent} from './form.component';
import {CenterSaveEvent} from './form.component';
import {ContactDetail, ContactDetailType} from '../../services/domain/contact/contact-detail.model';
import {Employee} from '../../services/office/domain/employee.model';
import {UserWithPassword} from '../../services/identity/domain/user-with-password.model';
@@ -49,7 +49,7 @@ export function mapContactDetails(contactForm: any): ContactDetail[] {
return contactDetails;
}

export function mapEmployee(event: EmployeeSaveEvent): Employee {
export function mapEmployee(event: CenterSaveEvent): Employee {
const assignedOffice = event.officeForm.assignedOffice;

const contactDetails: ContactDetail[] = mapContactDetails(event.contactForm);
@@ -66,7 +66,7 @@ export function mapEmployee(event: EmployeeSaveEvent): Employee {
return employee;
}

export function mapUser(event: EmployeeSaveEvent): UserWithPassword {
export function mapUser(event: CenterSaveEvent): UserWithPassword {
const userWithPassword: UserWithPassword = {
identifier: event.detailForm.identifier,
password: event.detailForm.password,
@@ -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,45 @@
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';
import {Store} from '@ngrx/store';
import {Observable} from 'rxjs/Observable';

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,


],
providers: [
{
provide: Store, useClass: class {
dispatch = jasmine.createSpy('dispatch');
select = jasmine.createSpy('select').and.returnValue(Observable.empty());
}}
]
})
.compileComponents();
}));

0 comments on commit e048f09

Please sign in to comment.