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

70 lines
2.1 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
2019-09-13 14:09:14 +00:00
beforeEach(angular.mock.module('vnCore', $translateProvider => {
$translateProvider.translations('en', {});
}));
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?
// expect($ctrl.error).toContain('Please select a value that is no less than 0');
expect($ctrl.error).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
expect($ctrl.error).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?
// expect($ctrl.error).toContain('Please select a value that is no more than 0');
expect($ctrl.error).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
expect($ctrl.error).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
});
});
});