2017-10-04 14:02:53 +00:00
|
|
|
import './textfield.js';
|
|
|
|
|
|
|
|
describe('Component vnTextfield', () => {
|
|
|
|
let $scope;
|
|
|
|
let $attrs;
|
|
|
|
let $timeout;
|
|
|
|
let $element;
|
2017-10-17 12:24:40 +00:00
|
|
|
let controller;
|
2017-10-04 14:02:53 +00:00
|
|
|
|
2019-09-13 14:09:14 +00:00
|
|
|
beforeEach(angular.mock.module('vnCore', $translateProvider => {
|
|
|
|
$translateProvider.translations('en', {});
|
|
|
|
}));
|
2017-10-04 14:02:53 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
|
2017-10-04 14:02:53 +00:00
|
|
|
$scope = $rootScope.$new();
|
2019-09-09 08:57:10 +00:00
|
|
|
$attrs = {field: '$ctrl.client.phone'};
|
|
|
|
$element = angular.element('<vn-textfield label="Phone" field="$ctrl.client.phone"><input><div class="leftIcons"><div class="rightIcons"></div></vn-textfield>');
|
2018-08-06 12:09:55 +00:00
|
|
|
controller = $componentController('vnTextfield', {$scope, $element, $attrs, $timeout, $transclude: () => {}});
|
2017-10-04 14:02:53 +00:00
|
|
|
}));
|
|
|
|
|
2018-08-06 12:09:55 +00:00
|
|
|
describe('saveOldValue()', () => {
|
|
|
|
it(`should equal oldValue property to the actual input value`, () => {
|
|
|
|
controller.value = 'pepino';
|
|
|
|
controller.saveOldValue();
|
|
|
|
|
|
|
|
expect(controller.oldValue).toEqual('pepino');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-04 14:02:53 +00:00
|
|
|
describe('value() setter', () => {
|
2018-06-28 13:54:54 +00:00
|
|
|
it(`should set _value, input.value and hasValue properties to null, '' and false`, () => {
|
2017-10-04 14:02:53 +00:00
|
|
|
let testValue = '';
|
|
|
|
controller.value = testValue;
|
|
|
|
|
|
|
|
expect(controller._value).toEqual(null);
|
|
|
|
expect(controller.input.value).toEqual(testValue);
|
|
|
|
expect(controller.hasValue).toEqual(Boolean(testValue));
|
|
|
|
});
|
|
|
|
|
2018-06-28 13:54:54 +00:00
|
|
|
it(`should set _value, input.value and hasValue propertiest to test, test and true`, () => {
|
2017-10-04 14:02:53 +00:00
|
|
|
let testValue = 'test';
|
|
|
|
controller.value = testValue;
|
|
|
|
|
|
|
|
expect(controller._value).toEqual(testValue);
|
|
|
|
expect(controller.input.value).toEqual(testValue);
|
|
|
|
expect(controller.hasValue).toEqual(Boolean(testValue));
|
2018-06-28 13:54:54 +00:00
|
|
|
});
|
2018-08-06 12:09:55 +00:00
|
|
|
|
|
|
|
it(`should add the class not-empty to the div`, () => {
|
|
|
|
let testValue = 'test';
|
|
|
|
controller.value = testValue;
|
|
|
|
|
|
|
|
expect(controller.element.classList).toContain('not-empty');
|
|
|
|
});
|
2018-06-28 13:54:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('type() setter', () => {
|
|
|
|
it(`should set _type to 'text' if theres not given value`, () => {
|
|
|
|
controller.type = null;
|
|
|
|
|
|
|
|
expect(controller._type).toEqual('text');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-08-06 12:09:55 +00:00
|
|
|
describe('vnTabIndex() setter', () => {
|
|
|
|
it(`should set input.tabindex to a given value`, () => {
|
|
|
|
controller.vnTabIndex = 9;
|
|
|
|
|
|
|
|
expect(controller.input.tabindex).toEqual(9);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-28 13:54:54 +00:00
|
|
|
describe('clear()', () => {
|
2018-09-04 14:51:29 +00:00
|
|
|
it(`should set value property to null, call focus and saveOldValue`, () => {
|
2018-06-28 13:54:54 +00:00
|
|
|
spyOn(controller.input, 'focus');
|
2018-09-04 14:51:29 +00:00
|
|
|
spyOn(controller, 'saveOldValue');
|
2018-06-28 13:54:54 +00:00
|
|
|
controller.clear();
|
|
|
|
|
|
|
|
expect(controller.value).toEqual(null);
|
2018-09-04 14:51:29 +00:00
|
|
|
expect(controller.saveOldValue).toHaveBeenCalledWith();
|
2018-06-28 13:54:54 +00:00
|
|
|
expect(controller.input.focus).toHaveBeenCalledWith();
|
2017-10-04 14:02:53 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|