2018-09-13 09:27:38 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Component vnInputNumber', () => {
|
|
|
|
let $scope;
|
|
|
|
let $attrs;
|
|
|
|
let $timeout;
|
|
|
|
let $element;
|
|
|
|
let controller;
|
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(ngModule('vnCore'));
|
2018-09-13 09:27:38 +00:00
|
|
|
|
2018-12-22 10:59:26 +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();
|
|
|
|
|
2019-04-10 10:04:11 +00:00
|
|
|
expect(classes).not.toContain('validated invalid');
|
2018-09-13 09:27:38 +00:00
|
|
|
});
|
|
|
|
|
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-10 10:04:11 +00:00
|
|
|
expect(classes).toContain('validated invalid');
|
2018-09-13 09:27:38 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|