salix/front/core/components/input-number/index.spec.js

67 lines
2.3 KiB
JavaScript

import './index.js';
describe('Component vnInputNumber', () => {
let $scope;
let $attrs;
let $timeout;
let $element;
let controller;
beforeEach(ngModule('vnCore'));
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
$scope = $rootScope.$new();
$attrs = {};
$element = angular.element('<div><input type="number"><div class="infix"><div class="rightIcons"></div></div>');
controller = $componentController('vnInputNumber', {$element, $scope, $attrs, $timeout, $transclude: () => {}});
controller.input = $element[0].querySelector('input');
controller.validate = () => {};
}));
describe('value() setter', () => {
it(`should set a value, add the class 'not-empty' and then call validateValue() method`, () => {
spyOn(controller, 'validateValue');
controller.value = 10;
let classes = controller.element.classList.toString();
expect(classes).toContain('not-empty');
expect(controller.validateValue).toHaveBeenCalledWith();
});
it(`should set an empty value, remove the class 'not-empty' and then call validateValue() method`, () => {
spyOn(controller, 'validateValue');
controller.value = null;
let classes = controller.element.classList.toString();
expect(classes).not.toContain('not-empty');
expect(controller.validateValue).toHaveBeenCalledWith();
});
});
describe('validateValue()', () => {
it(`should call hasValidValue() and not add the class invalid and validated`, () => {
controller.input.min = 0;
controller.input.value = 10;
controller.validateValue();
let classes = controller.element.querySelector('.infix').classList.toString();
expect(classes).not.toContain('validated invalid');
});
it(`should call hasValidValue() and add the class invalid and validated`, () => {
controller.input.min = 0;
controller.input.value = -10;
controller.validateValue();
let classes = controller.element.querySelector('.infix').classList.toString();
expect(classes).toContain('validated invalid');
});
});
});