mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Added some more test for new functionality
This commit is contained in:
@@ -19,23 +19,29 @@ import { it, describe, expect } from '@angular/core/testing';
|
|||||||
import { Observable } from 'rxjs/Rx';
|
import { Observable } from 'rxjs/Rx';
|
||||||
import { SimpleChange } from '@angular/core';
|
import { SimpleChange } from '@angular/core';
|
||||||
import { ActivitiForm } from './activiti-form.component';
|
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 { FormService } from './../services/form.service';
|
||||||
|
import { WidgetVisibilityService } from './../services/widget-visibility.service';
|
||||||
|
import { ContainerWidget } from './widgets/container/container.widget';
|
||||||
|
|
||||||
describe('ActivitiForm', () => {
|
describe('ActivitiForm', () => {
|
||||||
|
|
||||||
let componentHandler: any;
|
let componentHandler: any;
|
||||||
let formService: FormService;
|
let formService: FormService;
|
||||||
let formComponent: ActivitiForm;
|
let formComponent: ActivitiForm;
|
||||||
|
let visibilityService: WidgetVisibilityService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
componentHandler = jasmine.createSpyObj('componentHandler', [
|
componentHandler = jasmine.createSpyObj('componentHandler', [
|
||||||
'upgradeAllRegistered'
|
'upgradeAllRegistered'
|
||||||
]);
|
]);
|
||||||
|
visibilityService = jasmine.createSpyObj('WidgetVisibilityService', [
|
||||||
|
'updateVisibilityForForm', 'getTaskProcessVariableModelsForTask'
|
||||||
|
]);
|
||||||
window['componentHandler'] = componentHandler;
|
window['componentHandler'] = componentHandler;
|
||||||
|
|
||||||
formService = new FormService(null, null, null);
|
formService = new FormService(null, null, null);
|
||||||
formComponent = new ActivitiForm(formService, null);
|
formComponent = new ActivitiForm(formService, visibilityService);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should upgrade MDL content on view checked', () => {
|
it('should upgrade MDL content on view checked', () => {
|
||||||
@@ -139,6 +145,7 @@ describe('ActivitiForm', () => {
|
|||||||
formComponent.loadForm();
|
formComponent.loadForm();
|
||||||
|
|
||||||
expect(formComponent.getFormByTaskId).toHaveBeenCalledWith(taskId);
|
expect(formComponent.getFormByTaskId).toHaveBeenCalledWith(taskId);
|
||||||
|
expect(visibilityService.getTaskProcessVariableModelsForTask).toHaveBeenCalledWith(taskId);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get form definition by form id on load', () => {
|
it('should get form definition by form id on load', () => {
|
||||||
@@ -563,4 +570,16 @@ describe('ActivitiForm', () => {
|
|||||||
let form = formComponent.parseForm({ id: '<id>' });
|
let form = formComponent.parseForm({ id: '<id>' });
|
||||||
expect(formComponent.getFormDefinitionOutcomes).toHaveBeenCalledWith(form);
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -20,6 +20,7 @@ import { ContainerWidget } from './container.widget';
|
|||||||
import { FormModel } from './../core/form.model';
|
import { FormModel } from './../core/form.model';
|
||||||
import { ContainerModel } from './../core/container.model';
|
import { ContainerModel } from './../core/container.model';
|
||||||
import { FormFieldTypes } from './../core/form-field-types';
|
import { FormFieldTypes } from './../core/form-field-types';
|
||||||
|
import { FormFieldModel } from './../core/form-field.model';
|
||||||
|
|
||||||
describe('ContainerWidget', () => {
|
describe('ContainerWidget', () => {
|
||||||
|
|
||||||
@@ -94,4 +95,18 @@ describe('ContainerWidget', () => {
|
|||||||
expect(container.isExpanded).toBeTruthy();
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
import { it, describe, expect, beforeEach } from '@angular/core/testing';
|
import { it, describe, expect, beforeEach } from '@angular/core/testing';
|
||||||
import { WidgetComponent } from './widget.component';
|
import { WidgetComponent } from './widget.component';
|
||||||
import { FormFieldModel } from './core/form-field.model';
|
import { FormFieldModel } from './core/form-field.model';
|
||||||
|
import { FormModel } from './core/form.model';
|
||||||
|
|
||||||
describe('WidgetComponent', () => {
|
describe('WidgetComponent', () => {
|
||||||
|
|
||||||
@@ -52,4 +53,34 @@ describe('WidgetComponent', () => {
|
|||||||
component.field = new FormFieldModel(null);
|
component.field = new FormFieldModel(null);
|
||||||
expect(component.hasField()).toBeTruthy();
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user