salix/front/core/components/textarea/textarea.spec.js

57 lines
2.1 KiB
JavaScript

import './textarea.js';
describe('Component vnTextarea', () => {
let $scope;
let $attrs;
let $element;
let controller;
beforeEach(angular.mock.module('vnCore', $translateProvider => {
$translateProvider.translations('en', {});
}));
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
$scope = $rootScope.$new();
$attrs = {field: '$ctrl.claim.observation'};
$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});
}));
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);
});
});
});