diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/text/text.widget.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/text/text.widget.spec.ts index 9248d824f3..14548449fe 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/text/text.widget.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/text/text.widget.spec.ts @@ -15,18 +15,54 @@ * limitations under the License. */ +import { ElementRef } from '@angular/core'; import { TextWidget } from './text.widget'; +import { FormFieldModel } from './../core/form-field.model'; +import { FormFieldTypes } from '../core/form-field-types'; describe('TextWidget', () => { let widget: TextWidget; + let elementRef: ElementRef; + let componentHandler; beforeEach(() => { - widget = new TextWidget(null); + elementRef = new ElementRef(null); + widget = new TextWidget(elementRef); + + componentHandler = jasmine.createSpyObj('componentHandler', [ + 'upgradeAllRegistered' + ]); + + window['componentHandler'] = componentHandler; }); - it('should exist', () => { - expect(widget).toBeDefined(); + it('should upgrade material textfield', () => { + spyOn(widget, 'setupMaterialTextField').and.stub(); + + widget.field = new FormFieldModel(null, { + type: FormFieldTypes.TEXT, + value: '' + }); + widget.ngAfterViewInit(); + expect(widget.setupMaterialTextField).toHaveBeenCalled(); + }); + + it('should require mdl component handler to setup textfield', () => { + expect(widget.setupMaterialComponents(null)).toBeFalsy(); + }); + + it('should require element reference to setup textfield', () => { + widget = new TextWidget(null); + expect(widget.setupMaterialComponents(componentHandler)).toBeFalsy(); + }); + + it('should require field value to setup textfield', () => { + widget.field = new FormFieldModel(null, { + type: FormFieldTypes.TEXT, + value: null + }); + expect(widget.setupMaterialComponents(componentHandler)).toBeFalsy(); }); }); diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/textfield-widget.component.ts b/ng2-components/ng2-activiti-form/src/components/widgets/textfield-widget.component.ts index 12e8325c5d..f14ecaca81 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/textfield-widget.component.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/textfield-widget.component.ts @@ -32,9 +32,9 @@ export abstract class TextFieldWidgetComponent extends WidgetComponent { // workaround for MDL issues with dynamic components if (handler) { if (this.elementRef && this.hasValue()) { - super.setupMaterialTextField(this.elementRef, handler, this.field.value.toString()); + this.setupMaterialTextField(this.elementRef, handler, this.field.value.toString()); + return true; } - return true; } return false; }