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

61 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-09-13 09:27:38 +00:00
import './index.js';
describe('Component vnInputNumber', () => {
let $element;
let $ctrl;
2018-09-13 09:27:38 +00:00
beforeEach(ngModule('vnCore'));
2018-09-13 09:27:38 +00:00
2020-07-23 14:46:16 +00:00
beforeEach(inject(($compile, $rootScope) => {
2020-07-03 10:13:42 +00:00
$element = $compile(`<vn-input-number ng-model="model" />`)($rootScope);
$ctrl = $element.controller('vnInputNumber');
2018-09-13 09:27:38 +00:00
}));
afterEach(() => {
$element.remove();
});
2018-09-13 09:27:38 +00:00
describe('min() setter', () => {
it(`should set error property when value is lower than min`, () => {
$ctrl.field = -1;
$ctrl.min = 0;
2018-09-13 09:27:38 +00:00
2020-07-03 10:13:42 +00:00
expect($ctrl.shownError).toContain('Constraints not satisfied');
2018-09-13 09:27:38 +00:00
});
2020-07-03 10:13:42 +00:00
it(`should unset error property when value is greater than min`, () => {
$ctrl.field = 1;
$ctrl.min = 0;
2018-09-13 09:27:38 +00:00
2019-10-11 15:38:04 +00:00
expect($ctrl.shownError).toBeNull();
2018-09-13 09:27:38 +00:00
});
});
describe('max() setter', () => {
2020-07-03 10:13:42 +00:00
it(`should set error property when value is greater than max`, () => {
$ctrl.field = 1;
$ctrl.max = 0;
2018-09-13 09:27:38 +00:00
2020-07-03 10:13:42 +00:00
expect($ctrl.shownError).toContain('Constraints not satisfied');
});
it(`should unset error property when value is lower than max`, () => {
$ctrl.field = -1;
2020-07-03 10:13:42 +00:00
$ctrl.max = 0;
2018-09-13 09:27:38 +00:00
2019-10-11 15:38:04 +00:00
expect($ctrl.shownError).toBeNull();
2018-09-13 09:27:38 +00:00
});
});
2018-09-13 09:27:38 +00:00
describe('step() setter', () => {
it(`should increase value when add icon is clicked`, () => {
2020-07-03 10:13:42 +00:00
$ctrl.input.step = 1;
$ctrl.input.value = 0;
2018-09-13 09:27:38 +00:00
2020-07-03 10:13:42 +00:00
$ctrl.stepUp();
2018-09-13 09:27:38 +00:00
2020-07-03 10:13:42 +00:00
expect($ctrl.input.value).toBe('1');
2018-09-13 09:27:38 +00:00
});
});
});