#726 fix unit tests

This commit is contained in:
Denys Vuika
2016-09-14 21:17:13 +01:00
parent 2d5944c8bf
commit ca2267faff
6 changed files with 22 additions and 24 deletions

View File

@@ -17,6 +17,7 @@
import { it, describe, expect } from '@angular/core/testing';
import { ContainerColumnModel } from './container-column.model';
import { FormModel } from './form.model';
import { FormFieldModel } from './form-field.model';
describe('ContainerColumnModel', () => {
@@ -35,7 +36,7 @@ describe('ContainerColumnModel', () => {
column.fields = [];
expect(column.hasFields()).toBeFalsy();
column.fields = [new FormFieldModel(null, null)];
column.fields = [new FormFieldModel(new FormModel(), null)];
expect(column.hasFields()).toBeTruthy();
});

View File

@@ -113,15 +113,6 @@ describe('FormFieldModel', () => {
expect(field.readOnly).toBeTruthy();
});
it('should parse and convert empty dropdown value', () => {
let field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.DROPDOWN,
value: ''
});
expect(field.value).toBe('empty');
});
it('should parse and leave dropdown value as is', () => {
let field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.DROPDOWN,
@@ -145,19 +136,6 @@ describe('FormFieldModel', () => {
expect(field.value).toBe('opt2');
});
it('should parse and fall back to first radio button value', () => {
let field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.RADIO_BUTTONS,
options: [
{ id: 'opt1', value: 'Option 1' },
{ id: 'opt2', value: 'Option 2' }
],
value: 'opt3'
});
expect(field.value).toBe('opt1');
});
it('should parse and leave radio button value as is', () => {
let field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.RADIO_BUTTONS,

View File

@@ -195,6 +195,10 @@ export class FormFieldModel extends FormWidgetModel {
}
updateForm() {
if (!this.form) {
return;
}
switch (this.type) {
case FormFieldTypes.DROPDOWN:
/*

View File

@@ -37,7 +37,16 @@ describe('FunctionalGroupWidget', () => {
it('should setup text from underlying field on init', () => {
let group = new GroupModel({ name: 'group-1'});
widget.field.value = group;
spyOn(formService, 'getWorkflowGroups').and.returnValue(
Observable.create(observer => {
observer.next([]);
observer.complete();
})
);
widget.ngOnInit();
expect(formService.getWorkflowGroups).toHaveBeenCalled();
expect(widget.value).toBe(group.name);
});

View File

@@ -62,6 +62,12 @@ describe('PeopleWidget', () => {
firstName: 'John',
lastName: 'Doe'
});
spyOn(formService, 'getWorkflowUsers').and.returnValue(Observable.create(observer => {
observer.next([]);
observer.complete();
}));
widget.ngOnInit();
expect(widget.value).toBe('John Doe');
});

View File

@@ -50,7 +50,7 @@ describe('WidgetComponent', () => {
let component = new WidgetComponent();
expect(component.hasField()).toBeFalsy();
component.field = new FormFieldModel(null);
component.field = new FormFieldModel(new FormModel());
expect(component.hasField()).toBeTruthy();
});