Added some more test for new functionality

This commit is contained in:
Vito Albano
2016-08-20 20:26:50 +01:00
parent 5241435164
commit 0fbaf7faf0
3 changed files with 67 additions and 2 deletions

View File

@@ -19,23 +19,29 @@ import { it, describe, expect } from '@angular/core/testing';
import { Observable } from 'rxjs/Rx';
import { SimpleChange } from '@angular/core';
import { ActivitiForm } from './activiti-form.component';
import { FormModel, FormOutcomeModel } from './widgets/index';
import { FormModel, FormOutcomeModel, FormFieldModel } from './widgets/index';
import { FormService } from './../services/form.service';
import { WidgetVisibilityService } from './../services/widget-visibility.service';
import { ContainerWidget } from './widgets/container/container.widget';
describe('ActivitiForm', () => {
let componentHandler: any;
let formService: FormService;
let formComponent: ActivitiForm;
let visibilityService: WidgetVisibilityService;
beforeEach(() => {
componentHandler = jasmine.createSpyObj('componentHandler', [
'upgradeAllRegistered'
]);
visibilityService = jasmine.createSpyObj('WidgetVisibilityService', [
'updateVisibilityForForm', 'getTaskProcessVariableModelsForTask'
]);
window['componentHandler'] = componentHandler;
formService = new FormService(null, null, null);
formComponent = new ActivitiForm(formService, null);
formComponent = new ActivitiForm(formService, visibilityService);
});
it('should upgrade MDL content on view checked', () => {
@@ -139,6 +145,7 @@ describe('ActivitiForm', () => {
formComponent.loadForm();
expect(formComponent.getFormByTaskId).toHaveBeenCalledWith(taskId);
expect(visibilityService.getTaskProcessVariableModelsForTask).toHaveBeenCalledWith(taskId);
});
it('should get form definition by form id on load', () => {
@@ -563,4 +570,16 @@ describe('ActivitiForm', () => {
let form = formComponent.parseForm({ id: '<id>' });
expect(formComponent.getFormDefinitionOutcomes).toHaveBeenCalledWith(form);
});
it('should update the visibility when the container raise the change event', (done) => {
spyOn(formComponent, 'checkVisibility').and.callThrough();
let widget = new ContainerWidget();
let fakeForm = new FormModel();
let fakeField = new FormFieldModel(fakeForm, {id: 'fakeField', value: 'fakeValue'});
widget.formValueChanged.subscribe(field => { console.log('called'); done(); });
widget.fieldChanged(fakeField);
expect(formComponent.checkVisibility).toHaveBeenCalledWith(fakeField);
});
});

View File

@@ -20,6 +20,7 @@ import { ContainerWidget } from './container.widget';
import { FormModel } from './../core/form.model';
import { ContainerModel } from './../core/container.model';
import { FormFieldTypes } from './../core/form-field-types';
import { FormFieldModel } from './../core/form-field.model';
describe('ContainerWidget', () => {
@@ -94,4 +95,18 @@ describe('ContainerWidget', () => {
expect(container.isExpanded).toBeTruthy();
});
it('should send an event when a value is changed in the form', (done) => {
let widget = new ContainerWidget();
let fakeForm = new FormModel();
let fakeField = new FormFieldModel(fakeForm, {id: 'fakeField', value: 'fakeValue'});
widget.formValueChanged.subscribe(field => {
expect(field).not.toBe(null);
expect(field.id).toBe('fakeField');
expect(field.value).toBe('fakeValue');
done();
});
widget.fieldChanged(fakeField);
});
});

View File

@@ -18,6 +18,7 @@
import { it, describe, expect, beforeEach } from '@angular/core/testing';
import { WidgetComponent } from './widget.component';
import { FormFieldModel } from './core/form-field.model';
import { FormModel } from './core/form.model';
describe('WidgetComponent', () => {
@@ -52,4 +53,34 @@ describe('WidgetComponent', () => {
component.field = new FormFieldModel(null);
expect(component.hasField()).toBeTruthy();
});
it('should send an event after view init', (done) => {
let component = new WidgetComponent();
let fakeForm = new FormModel();
let fakeField = new FormFieldModel(fakeForm, {id: 'fakeField', value: 'fakeValue'});
component.field = fakeField;
component.fieldChanged.subscribe(field => {
expect(field).not.toBe(null);
expect(field.id).toBe('fakeField');
expect(field.value).toBe('fakeValue');
done();
});
component.ngAfterViewInit();
});
it('should send an event when a field is changed', (done) => {
let component = new WidgetComponent();
let fakeForm = new FormModel();
let fakeField = new FormFieldModel(fakeForm, {id: 'fakeField', value: 'fakeValue'});
component.fieldChanged.subscribe(field => {
expect(field).not.toBe(null);
expect(field.id).toBe('fakeField');
expect(field.value).toBe('fakeValue');
done();
});
component.checkVisibility(fakeField);
});
});