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

68 lines
2.0 KiB
JavaScript

import './index.js';
describe('Component vnInputNumber', () => {
let $element;
let $ctrl;
beforeEach(ngModule('vnCore'));
beforeEach(angular.mock.inject(($compile, $rootScope) => {
$element = $compile(`<vn-input-number></vn-input-number>`)($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;
// FIXME: Input validation doesn't work with Jest?
// expect($ctrl.shownError).toContain('Please select a value that is no less than 0');
expect($ctrl.shownError).toBeNull();
});
it(`should unset error property when value is upper than min`, () => {
$ctrl.field = 1;
$ctrl.min = 0;
expect($ctrl.shownError).toBeNull();
});
});
describe('max() setter', () => {
it(`should set error property when value is upper than max`, () => {
$ctrl.field = 1;
$ctrl.max = 0;
// FIXME: Input validation doesn't work with Jest?
// 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;
expect($ctrl.shownError).toBeNull();
});
});
describe('step() setter', () => {
it(`should increase value when add icon is clicked`, () => {
$ctrl.step = 1;
$ctrl.field = 1;
// FIXME: Doesn't work with Jest?
// $ctrl.stepUp();
// $element[0].querySelector('vn-icon[icon=add]').click();
expect($ctrl.field).toBe(1);
});
});
});