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

57 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-09-19 13:05:07 +00:00
import './index.js';
2019-09-09 08:57:10 +00:00
describe('Component vnInputTime', () => {
2018-09-19 13:05:07 +00:00
let $scope;
let $attrs;
let $timeout;
let $element;
let controller;
beforeEach(ngModule('vnCore'));
2018-09-19 13:05:07 +00:00
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
2018-09-19 13:05:07 +00:00
$scope = $rootScope.$new();
2019-09-09 08:57:10 +00:00
$attrs = {field: '$ctrl.zone.hour'};
$element = angular.element('<vn-input-time label="Hour" field="$ctrl.zone.hour"><input><div class="infix invalid validated"><div class="rightIcons"></div></vn-input-time>');
controller = $componentController('vnInputTime', {$element, $scope, $attrs, $timeout, $transclude: () => {}});
2018-09-19 13:05:07 +00:00
}));
describe('value() setter', () => {
it(`should set _value to a given value, add the class not-empty and remove invalid and validated`, () => {
2019-09-09 08:57:10 +00:00
const today = new Date();
controller.value = today;
2018-09-19 13:05:07 +00:00
let classes = controller.element.classList.toString();
expect(classes).toContain('not-empty');
2019-09-09 08:57:10 +00:00
expect(controller._value).toEqual(today);
2018-09-19 13:05:07 +00:00
classes = controller.element.querySelector('.infix').classList.toString();
expect(classes).not.toContain('invalid validated');
});
it(`should set _value to a given value and not add the class not-empty if the given value is null`, () => {
controller.value = null;
let classes = controller.element.classList.toString();
expect(classes).not.toContain('not-empty');
expect(controller._value).toEqual(null);
});
});
describe('step() setter/getter', () => {
it(`should set input.step to a given value`, () => {
2019-09-09 08:57:10 +00:00
controller.step = 2;
2018-09-19 13:05:07 +00:00
2019-09-09 08:57:10 +00:00
expect(controller.input.step).toEqual('2');
2018-09-19 13:05:07 +00:00
});
it(`should return a number`, () => {
2019-09-09 08:57:10 +00:00
controller.step = 2;
2018-09-19 13:05:07 +00:00
2019-09-09 08:57:10 +00:00
expect(controller.step).toEqual(2);
2018-09-19 13:05:07 +00:00
expect(typeof controller.step).toEqual('number');
});
});
});