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.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { ElementRef } from '@angular/core';
|
||||||
import { TextWidget } from './text.widget';
|
import { TextWidget } from './text.widget';
|
||||||
|
import { FormFieldModel } from './../core/form-field.model';
|
||||||
|
import { FormFieldTypes } from '../core/form-field-types';
|
||||||
|
|
||||||
describe('TextWidget', () => {
|
describe('TextWidget', () => {
|
||||||
|
|
||||||
let widget: TextWidget;
|
let widget: TextWidget;
|
||||||
|
let elementRef: ElementRef;
|
||||||
|
let componentHandler;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
widget = new TextWidget(null);
|
elementRef = new ElementRef(null);
|
||||||
|
widget = new TextWidget(elementRef);
|
||||||
|
|
||||||
|
componentHandler = jasmine.createSpyObj('componentHandler', [
|
||||||
|
'upgradeAllRegistered'
|
||||||
|
]);
|
||||||
|
|
||||||
|
window['componentHandler'] = componentHandler;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should exist', () => {
|
it('should upgrade material textfield', () => {
|
||||||
expect(widget).toBeDefined();
|
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 require field value to setup textfield', () => {
|
||||||
|
widget.field = new FormFieldModel(null, {
|
||||||
|
type: FormFieldTypes.TEXT,
|
||||||
|
value: null
|
||||||
|
});
|
||||||
|
expect(widget.setupMaterialComponents(componentHandler)).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -32,9 +32,9 @@ export abstract class TextFieldWidgetComponent extends WidgetComponent {
|
|||||||
// workaround for MDL issues with dynamic components
|
// workaround for MDL issues with dynamic components
|
||||||
if (handler) {
|
if (handler) {
|
||||||
if (this.elementRef && this.hasValue()) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user