mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
Text widget unit tests
This commit is contained in:
parent
4c66b9ef93
commit
16231791c4
@ -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(() => {
|
||||
elementRef = new ElementRef(null);
|
||||
widget = new TextWidget(elementRef);
|
||||
|
||||
componentHandler = jasmine.createSpyObj('componentHandler', [
|
||||
'upgradeAllRegistered'
|
||||
]);
|
||||
|
||||
window['componentHandler'] = componentHandler;
|
||||
});
|
||||
|
||||
it('should upgrade material textfield', () => {
|
||||
spyOn(widget, 'setupMaterialTextField').and.stub();
|
||||
|
||||
widget.field = new FormFieldModel(null, {
|
||||
type: FormFieldTypes.TEXT,
|
||||
value: '<text>'
|
||||
});
|
||||
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 exist', () => {
|
||||
expect(widget).toBeDefined();
|
||||
it('should require field value to setup textfield', () => {
|
||||
widget.field = new FormFieldModel(null, {
|
||||
type: FormFieldTypes.TEXT,
|
||||
value: null
|
||||
});
|
||||
expect(widget.setupMaterialComponents(componentHandler)).toBeFalsy();
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -32,10 +32,10 @@ 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 false;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user