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

67 lines
2.3 KiB
JavaScript
Raw Normal View History

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