Tarea #489 /components/textarea/textarea.js Front unit test
This commit is contained in:
parent
6967480398
commit
e8d7fbbf96
|
@ -0,0 +1,60 @@
|
|||
import './textarea.js';
|
||||
|
||||
describe('Component vnTextarea', () => {
|
||||
let $componentController;
|
||||
let $scope;
|
||||
let $attrs;
|
||||
let $timeout;
|
||||
let $element;
|
||||
let controller;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('client');
|
||||
});
|
||||
|
||||
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$timeout_) => {
|
||||
$componentController = _$componentController_;
|
||||
$scope = $rootScope.$new();
|
||||
$attrs = {};
|
||||
$timeout = _$timeout_;
|
||||
$element = angular.element('<vn-textarea vn-three label="Observation" field="$ctrl.claim.observation" rows="9"><textarea></vn-textarea>');
|
||||
$element[0].firstChild.MaterialTextfield = {updateClasses_: () => {}};
|
||||
controller = $componentController('vnTextarea', {$scope, $element, $attrs, $timeout});
|
||||
}));
|
||||
|
||||
describe('model() setter', () => {
|
||||
it(`should set model and call mdlUpdate`, () => {
|
||||
spyOn(controller, 'mdlUpdate');
|
||||
let model = 'model';
|
||||
controller.model = model;
|
||||
|
||||
expect(controller._model).toEqual(model);
|
||||
expect(controller.mdlUpdate).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
describe('rows() setter', () => {
|
||||
it(`should set rows property of the element to the given value if its not null`, () => {
|
||||
controller.rows = 27;
|
||||
|
||||
expect(controller.textarea.rows).toEqual(27);
|
||||
});
|
||||
|
||||
it(`should set rows property of the element to 3 if the given value if its null`, () => {
|
||||
controller.rows = null;
|
||||
|
||||
expect(controller.textarea.rows).toEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mdlUpdate()', () => {
|
||||
it(`should should call mdlField.updateClasses if theres an mdlField defined and call upgradeElement with the textarea element`, () => {
|
||||
spyOn($element[0].firstChild.MaterialTextfield, 'updateClasses_');
|
||||
spyOn(componentHandler, 'upgradeElement');
|
||||
controller.mdlUpdate();
|
||||
|
||||
expect($element[0].firstChild.MaterialTextfield.updateClasses_).toHaveBeenCalledWith();
|
||||
expect(componentHandler.upgradeElement).toHaveBeenCalledWith(controller.element[0].firstChild);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue