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

68 lines
2.0 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
beforeEach(angular.mock.inject(($compile, $rootScope) => {
$element = $compile(`<vn-input-number></vn-input-number>`)($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
// FIXME: Input validation doesn't work with Jest?
2019-10-11 15:38:04 +00:00
// expect($ctrl.shownError).toContain('Please select a value that is no less than 0');
expect($ctrl.shownError).toBeNull();
2018-09-13 09:27:38 +00:00
});
it(`should unset error property when value is upper 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', () => {
it(`should set error property when value is upper than max`, () => {
$ctrl.field = 1;
$ctrl.max = 0;
2018-09-13 09:27:38 +00:00
// FIXME: Input validation doesn't work with Jest?
2019-10-11 15:38:04 +00:00
// expect($ctrl.shownError).toContain('Please select a value that is no more than 0');
expect($ctrl.shownError).toBeNull();
});
// FIXME: Input validation doesn't work with Jest?
it(`should unset error property when value is lower than max`, () => {
$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
});
});
2018-09-13 09:27:38 +00:00
describe('step() setter', () => {
it(`should increase value when add icon is clicked`, () => {
$ctrl.step = 1;
$ctrl.field = 1;
2018-09-13 09:27:38 +00:00
// FIXME: Doesn't work with Jest?
// $ctrl.stepUp();
// $element[0].querySelector('vn-icon[icon=add]').click();
2018-09-13 09:27:38 +00:00
expect($ctrl.field).toBe(1);
2018-09-13 09:27:38 +00:00
});
});
});