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;
|
|
|
|
|
2019-09-13 14:09:14 +00:00
|
|
|
beforeEach(angular.mock.module('vnCore', $translateProvider => {
|
|
|
|
$translateProvider.translations('en', {});
|
|
|
|
}));
|
2018-09-19 13:05:07 +00:00
|
|
|
|
2018-12-22 10:59:26 +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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|