2018-09-13 09:27:38 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Component vnInputNumber', () => {
|
|
|
|
let $element;
|
2019-10-08 21:57:02 +00:00
|
|
|
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
|
|
|
|
2019-10-08 21:57:02 +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
|
|
|
}));
|
|
|
|
|
2019-10-08 21:57:02 +00:00
|
|
|
afterEach(() => {
|
|
|
|
$element.remove();
|
|
|
|
});
|
2018-09-13 09:27:38 +00:00
|
|
|
|
2019-10-08 21:57:02 +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
|
|
|
|
2019-10-08 21:57:02 +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
|
|
|
});
|
|
|
|
|
2019-10-08 21:57:02 +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-08 21:57:02 +00:00
|
|
|
expect($ctrl.error).toBeNull();
|
2018-09-13 09:27:38 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-08 21:57:02 +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
|
|
|
|
2019-10-08 21:57:02 +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
|
|
|
|
2019-10-08 21:57:02 +00:00
|
|
|
expect($ctrl.error).toBeNull();
|
2018-09-13 09:27:38 +00:00
|
|
|
});
|
2019-10-08 21:57:02 +00:00
|
|
|
});
|
2018-09-13 09:27:38 +00:00
|
|
|
|
2019-10-08 21:57:02 +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
|
|
|
|
2019-10-08 21:57:02 +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
|
|
|
|
2019-10-08 21:57:02 +00:00
|
|
|
expect($ctrl.field).toBe(1);
|
2018-09-13 09:27:38 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|