Skip to content
Permalink
Browse files
updated unit test for center
  • Loading branch information
pembemiriam committed Oct 20, 2018
1 parent 3f5dd71 commit 3aec1102196bb02b1f05761ebbe2621dfba5e335
Showing 7 changed files with 31 additions and 22 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',
@@ -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);

@@ -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: {
@@ -19,7 +19,7 @@
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {Component, EventEmitter, ViewChild} from '@angular/core';
import {Center} from '../../services/center/domain/center.model';
import {CenterFormComponent, EmployeeFormData, EmployeeSaveEvent} from './form.component';
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';
@@ -89,7 +89,7 @@ describe('Test center form component', () => {
it('should test if the form save the original values', () => {
fixture.detectChanges();

testComponent.saveEmitter.subscribe((saveEvent: EmployeeSaveEvent) => {
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);
@@ -116,11 +116,11 @@ describe('Test center form component', () => {
})
class TestComponent {

saveEmitter = new EventEmitter<EmployeeSaveEvent>();
saveEmitter = new EventEmitter<CenterSaveEvent>();

@ViewChild('form') formComponent: CenterFormComponent;

employeeFormData: EmployeeFormData = {
employeeFormData: CenterFormData = {
employee: centerTemplate,
user: userTemplate
};
@@ -129,8 +129,8 @@ class TestComponent {
this.formComponent.save();
}

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

}
}
@@ -32,12 +32,12 @@ import * as fromRoot from '../../store';
import {SEARCH as SEARCH_OFFICE} from '../../store/office/office.actions';
import {SEARCH as SEARCH_ROLE} from '../../store/role/role.actions';

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

export interface EmployeeSaveEvent {
export interface CenterSaveEvent {
detailForm: {
identifier: string;
firstName: string;
@@ -81,13 +81,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);
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>) {}
@@ -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,
@@ -7,6 +7,8 @@ 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';



@@ -31,6 +33,13 @@ describe('CollectionComponent', () => {


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

0 comments on commit 3aec110

Please sign in to comment.