69 lines
2.5 KiB
JavaScript
69 lines
2.5 KiB
JavaScript
import './index.js';
|
|
|
|
describe('Component vnInputNumber', () => {
|
|
let $scope;
|
|
let $attrs;
|
|
let $timeout;
|
|
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.client.socialName'};
|
|
$element = angular.element('<vn-input-number label="SocialName" field="$ctrl.client.socialName"><input type="number"><div class="infix"><div class="rightIcons"></div></vn-input-number>');
|
|
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');
|
|
});
|
|
});
|
|
});
|