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

61 lines
1.6 KiB
JavaScript

import './index.js';
describe('Component vnInputNumber', () => {
let $element;
let $ctrl;
beforeEach(ngModule('vnCore'));
beforeEach(inject(($compile, $rootScope) => {
$element = $compile(`<vn-input-number ng-model="model" />`)($rootScope);
$ctrl = $element.controller('vnInputNumber');
}));
afterEach(() => {
$element.remove();
});
describe('min() setter', () => {
it(`should set error property when value is lower than min`, () => {
$ctrl.field = -1;
$ctrl.min = 0;
expect($ctrl.shownError).toContain('Constraints not satisfied');
});
it(`should unset error property when value is greater than min`, () => {
$ctrl.field = 1;
$ctrl.min = 0;
expect($ctrl.shownError).toBeNull();
});
});
describe('max() setter', () => {
it(`should set error property when value is greater than max`, () => {
$ctrl.field = 1;
$ctrl.max = 0;
expect($ctrl.shownError).toContain('Constraints not satisfied');
});
it(`should unset error property when value is lower than max`, () => {
$ctrl.field = -1;
$ctrl.max = 0;
expect($ctrl.shownError).toBeNull();
});
});
describe('step() setter', () => {
it(`should increase value when add icon is clicked`, () => {
$ctrl.input.step = 1;
$ctrl.input.value = 0;
$ctrl.stepUp();
expect($ctrl.input.value).toBe('1');
});
});
});