2017-09-26 08:26:21 +00:00
|
|
|
import './autocomplete.js';
|
|
|
|
|
|
|
|
describe('Component vnAutocomplete', () => {
|
|
|
|
let $componentController;
|
|
|
|
let $scope;
|
|
|
|
let $httpBackend;
|
|
|
|
let $timeout;
|
|
|
|
let $element;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
angular.mock.module('client');
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_, _$timeout_) => {
|
|
|
|
$componentController = _$componentController_;
|
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$timeout = _$timeout_;
|
|
|
|
$element = angular.element('<div></div>');
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('showDropDown() setter', () => {
|
|
|
|
it(`should set _showDropDown value`, () => {
|
|
|
|
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
|
|
|
|
controller._showDropDown = '';
|
|
|
|
controller.showDropDown = 'some value';
|
|
|
|
|
|
|
|
expect(controller._showDropDown).toEqual('some value');
|
|
|
|
});
|
2017-09-26 12:10:55 +00:00
|
|
|
|
|
|
|
it(`should set _showDropDown value`, () => {
|
|
|
|
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
|
|
|
|
controller._showDropDown = '';
|
|
|
|
controller.showDropDown = 'some value';
|
|
|
|
|
|
|
|
expect(controller._showDropDown).toEqual('some value');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('displayValue() setter', () => {
|
|
|
|
it(`should display value in a formated way`, () => {
|
|
|
|
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
|
|
|
|
let value = 'some value';
|
|
|
|
controller.displayValue = value;
|
|
|
|
|
|
|
|
expect(controller._value).toEqual(value);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when the autocomeplete is multiple', () => {
|
|
|
|
it(`should display values separated with commas`, () => {
|
|
|
|
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
|
|
|
|
controller.multiple = true;
|
|
|
|
controller.displayValue = 'some value';
|
|
|
|
controller.displayValue = 'another value';
|
|
|
|
|
|
|
|
expect(controller._value).toEqual('some value, another value');
|
|
|
|
});
|
|
|
|
});
|
2017-09-26 08:26:21 +00:00
|
|
|
});
|
2017-09-26 16:21:11 +00:00
|
|
|
|
|
|
|
describe('field() setter', () => {
|
|
|
|
describe('when value is an object with valueField property', () => {
|
|
|
|
it(`should set _field and _multifield values and remove it from _multifield if called again`, () => {
|
|
|
|
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
|
|
|
|
controller.valueField = 'name';
|
|
|
|
controller.field = {name: 'Bruce Wayne'};
|
|
|
|
|
|
|
|
expect(controller._field).toEqual('Bruce Wayne');
|
|
|
|
expect(controller._multiField[0]).toEqual('Bruce Wayne');
|
|
|
|
|
|
|
|
controller.field = {name: 'Bruce Wayne'};
|
|
|
|
|
|
|
|
expect(controller._multiField).toEqual([]);
|
|
|
|
|
|
|
|
// value is still stored in _field after second call... is this correct? or should be deleted as per _multifield? ask Dani!
|
|
|
|
expect(controller._field).toEqual('Bruce Wayne');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-09-26 08:26:21 +00:00
|
|
|
});
|