From 0fbaf7faf006c2b228d6132aaeef489a00a3e2f0 Mon Sep 17 00:00:00 2001 From: Vito Albano Date: Sat, 20 Aug 2016 20:26:50 +0100 Subject: [PATCH] Added some more test for new functionality --- .../activiti-form.component.spec.ts | 23 ++++++++++++-- .../container/container.widget.spec.ts | 15 +++++++++ .../widgets/widget.component.spec.ts | 31 +++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/ng2-components/ng2-activiti-form/src/components/activiti-form.component.spec.ts b/ng2-components/ng2-activiti-form/src/components/activiti-form.component.spec.ts index fed7fecd72..f6125d605f 100644 --- a/ng2-components/ng2-activiti-form/src/components/activiti-form.component.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/activiti-form.component.spec.ts @@ -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: '' }); 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); + }); + }); diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/container/container.widget.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/container/container.widget.spec.ts index 54b43944fa..eb721dfc9f 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/container/container.widget.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/container/container.widget.spec.ts @@ -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); + }); + }); diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/widget.component.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/widget.component.spec.ts index d57b2e54f9..849e84a255 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/widget.component.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/widget.component.spec.ts @@ -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); + }); });