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 e9bcf64082..dbc9901062 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 @@ -16,29 +16,34 @@ */ 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 { FormService } from './../services/form.service'; describe('ActivitiForm', () => { let componentHandler: any; + let formService: FormService; + let formComponent: ActivitiForm; beforeEach(() => { componentHandler = jasmine.createSpyObj('componentHandler', [ 'upgradeAllRegistered' ]); - window['componentHandler'] = componentHandler; + + formService = new FormService(null, null, null); + formComponent = new ActivitiForm(formService); }); it('should upgrade MDL content on view checked', () => { - let formComponent = new ActivitiForm(null); formComponent.ngAfterViewChecked(); expect(componentHandler.upgradeAllRegistered).toHaveBeenCalled(); }); it('should setup MDL content only if component handler available', () => { - let formComponent = new ActivitiForm(null); expect(formComponent.setupMaterialComponents()).toBeTruthy(); window['componentHandler'] = null; @@ -46,21 +51,18 @@ describe('ActivitiForm', () => { }); it('should start loading form on init', () => { - let formComponent = new ActivitiForm(null); spyOn(formComponent, 'loadForm').and.stub(); formComponent.ngOnInit(); expect(formComponent.loadForm).toHaveBeenCalled(); }); it('should check form', () => { - let formComponent = new ActivitiForm(null); expect(formComponent.hasForm()).toBeFalsy(); formComponent.form = new FormModel(); expect(formComponent.hasForm()).toBeTruthy(); }); it('should allow title if task name available', () => { - let formComponent = new ActivitiForm(null); let formModel = new FormModel(); formComponent.form = formModel; @@ -80,7 +82,6 @@ describe('ActivitiForm', () => { }); it('should not allow title', () => { - let formComponent = new ActivitiForm(null); let formModel = new FormModel(); formComponent.form = formModel; @@ -91,12 +92,10 @@ describe('ActivitiForm', () => { }); it('should not enable outcome button when model missing', () => { - let formComponent = new ActivitiForm(null); expect(formComponent.isOutcomeButtonEnabled(null)).toBeFalsy(); }); it('should enable custom outcome buttons', () => { - let formComponent = new ActivitiForm(null); let formModel = new FormModel(); let outcome = new FormOutcomeModel(formModel, { id: 'action1', name: 'Action 1' }); expect(formComponent.isOutcomeButtonEnabled(outcome)).toBeTruthy(); @@ -104,8 +103,6 @@ describe('ActivitiForm', () => { it('should allow controlling [complete] button visibility', () => { - let formComponent = new ActivitiForm(null); - let formModel = new FormModel(); let outcome = new FormOutcomeModel(formModel, { id: '$save', name: FormOutcomeModel.SAVE_ACTION }); @@ -117,8 +114,6 @@ describe('ActivitiForm', () => { }); it('should allow controlling [save] button visibility', () => { - let formComponent = new ActivitiForm(null); - let formModel = new FormModel(); let outcome = new FormOutcomeModel(formModel, { id: '$save', name: FormOutcomeModel.COMPLETE_ACTION }); @@ -129,4 +124,443 @@ describe('ActivitiForm', () => { expect(formComponent.isOutcomeButtonEnabled(outcome)).toBeFalsy(); }); + it('should load form on refresh', () => { + spyOn(formComponent, 'loadForm').and.stub(); + + formComponent.onRefreshClicked(); + expect(formComponent.loadForm).toHaveBeenCalled(); + }); + + it('should get form by task id on load', () => { + spyOn(formComponent, 'getFormByTaskId').and.stub(); + const taskId = '123'; + + formComponent.taskId = taskId; + formComponent.loadForm(); + + expect(formComponent.getFormByTaskId).toHaveBeenCalledWith(taskId); + }); + + it('should get form definition by form id on load', () => { + spyOn(formComponent, 'getFormDefinitionByFormId').and.stub(); + const formId = '123'; + + formComponent.formId = formId; + formComponent.loadForm(); + + expect(formComponent.getFormDefinitionByFormId).toHaveBeenCalledWith(formId); + }); + + it('should get form definition by form name on load', () => { + spyOn(formComponent, 'getFormDefinitionByFormName').and.stub(); + const formName = '