2017-10-04 14:02:53 +00:00
|
|
|
import './textfield.js';
|
|
|
|
|
|
|
|
describe('Component vnTextfield', () => {
|
|
|
|
let $componentController;
|
|
|
|
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
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
angular.mock.module('client');
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_, _$timeout_) => {
|
|
|
|
$componentController = _$componentController_;
|
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$attrs = {};
|
|
|
|
$timeout = _$timeout_;
|
|
|
|
$element = angular.element('<div><input></div>');
|
2018-06-28 13:54:54 +00:00
|
|
|
controller = $componentController('vnTextfield', {$scope, $element, $attrs, $timeout, $transclude: null});
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('type() setter', () => {
|
|
|
|
it(`should set _type to 'text' if theres not given value`, () => {
|
|
|
|
controller.type = null;
|
|
|
|
|
|
|
|
expect(controller._type).toEqual('text');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('clear()', () => {
|
|
|
|
it(`should set value property to null and call focus`, () => {
|
|
|
|
spyOn(controller.input, 'focus');
|
|
|
|
controller.clear();
|
|
|
|
|
|
|
|
expect(controller.value).toEqual(null);
|
|
|
|
expect(controller.input.focus).toHaveBeenCalledWith();
|
2017-10-04 14:02:53 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|