salix/front/core/components/textfield/textfield.spec.js

85 lines
2.9 KiB
JavaScript

import './textfield.js';
describe('Component vnTextfield', () => {
let $scope;
let $attrs;
let $timeout;
let $element;
let controller;
beforeEach(angular.mock.module('vnCore', $translateProvider => {
$translateProvider.translations('en', {});
}));
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
$scope = $rootScope.$new();
$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>');
controller = $componentController('vnTextfield', {$scope, $element, $attrs, $timeout, $transclude: () => {}});
}));
describe('saveOldValue()', () => {
it(`should equal oldValue property to the actual input value`, () => {
controller.value = 'pepino';
controller.saveOldValue();
expect(controller.oldValue).toEqual('pepino');
});
});
describe('value() setter', () => {
it(`should set _value, input.value and hasValue properties to null, '' and false`, () => {
let testValue = '';
controller.value = testValue;
expect(controller._value).toEqual(null);
expect(controller.input.value).toEqual(testValue);
expect(controller.hasValue).toEqual(Boolean(testValue));
});
it(`should set _value, input.value and hasValue propertiest to test, test and true`, () => {
let testValue = 'test';
controller.value = testValue;
expect(controller._value).toEqual(testValue);
expect(controller.input.value).toEqual(testValue);
expect(controller.hasValue).toEqual(Boolean(testValue));
});
it(`should add the class not-empty to the div`, () => {
let testValue = 'test';
controller.value = testValue;
expect(controller.element.classList).toContain('not-empty');
});
});
describe('type() setter', () => {
it(`should set _type to 'text' if theres not given value`, () => {
controller.type = null;
expect(controller._type).toEqual('text');
});
});
describe('vnTabIndex() setter', () => {
it(`should set input.tabindex to a given value`, () => {
controller.vnTabIndex = 9;
expect(controller.input.tabindex).toEqual(9);
});
});
describe('clear()', () => {
it(`should set value property to null, call focus and saveOldValue`, () => {
spyOn(controller.input, 'focus');
spyOn(controller, 'saveOldValue');
controller.clear();
expect(controller.value).toEqual(null);
expect(controller.saveOldValue).toHaveBeenCalledWith();
expect(controller.input.focus).toHaveBeenCalledWith();
});
});
});