2017-09-26 08:26:21 +00:00
|
|
|
describe('Component vnAutocomplete', () => {
|
2018-03-09 13:15:30 +00:00
|
|
|
let $element;
|
2018-11-06 13:27:16 +00:00
|
|
|
let controller;
|
2018-03-09 13:15:30 +00:00
|
|
|
let data = {id: 1, name: 'Bruce Wayne'};
|
|
|
|
|
2019-09-13 14:09:14 +00:00
|
|
|
beforeEach(angular.mock.module('vnCore', $translateProvider => {
|
|
|
|
$translateProvider.translations('en', {});
|
|
|
|
}));
|
2017-09-26 08:26:21 +00:00
|
|
|
|
2018-10-18 19:04:46 +00:00
|
|
|
beforeEach(inject(($compile, $rootScope) => {
|
2018-10-18 18:48:21 +00:00
|
|
|
$element = $compile(`<vn-autocomplete></vn-autocomplete>`)($rootScope);
|
2018-11-06 13:27:16 +00:00
|
|
|
controller = $element.controller('vnAutocomplete');
|
2017-09-26 08:26:21 +00:00
|
|
|
}));
|
|
|
|
|
2018-10-18 18:48:21 +00:00
|
|
|
afterEach(() => {
|
|
|
|
$element.remove();
|
|
|
|
});
|
|
|
|
|
2018-07-02 11:13:26 +00:00
|
|
|
describe('url() setter', () => {
|
2018-10-18 18:48:21 +00:00
|
|
|
it(`should set the url property`, () => {
|
2018-11-06 13:27:16 +00:00
|
|
|
controller.url = '/TestModels';
|
2018-07-02 11:13:26 +00:00
|
|
|
|
2018-11-06 13:27:16 +00:00
|
|
|
expect(controller.url).toEqual('/TestModels');
|
2018-07-02 11:13:26 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-09 13:15:30 +00:00
|
|
|
describe('field() setter/getter', () => {
|
2018-10-18 18:48:21 +00:00
|
|
|
it(`should set the field property`, () => {
|
2018-11-06 13:27:16 +00:00
|
|
|
controller.field = 'id';
|
2017-09-26 08:26:21 +00:00
|
|
|
|
2018-11-06 13:27:16 +00:00
|
|
|
expect(controller.field).toEqual('id');
|
2017-09-26 08:26:21 +00:00
|
|
|
});
|
2018-10-18 18:48:21 +00:00
|
|
|
});
|
2017-09-26 12:10:55 +00:00
|
|
|
|
2018-10-18 18:48:21 +00:00
|
|
|
describe('selection property', () => {
|
2018-10-19 07:33:12 +00:00
|
|
|
beforeEach(() => {
|
2018-11-06 13:27:16 +00:00
|
|
|
controller.field = data.id;
|
2018-10-19 07:33:12 +00:00
|
|
|
});
|
|
|
|
|
2018-03-09 13:15:30 +00:00
|
|
|
it(`should set selection finding an existing item in the initialData property`, () => {
|
2018-11-06 13:27:16 +00:00
|
|
|
controller.initialData = data;
|
2017-09-26 12:10:55 +00:00
|
|
|
|
2018-11-06 13:27:16 +00:00
|
|
|
expect(controller.selection).toEqual(data);
|
2017-09-26 12:10:55 +00:00
|
|
|
});
|
|
|
|
|
2018-03-09 13:15:30 +00:00
|
|
|
it(`should set selection finding an existing item in the data property`, () => {
|
2018-11-06 13:27:16 +00:00
|
|
|
controller.data = [data];
|
2017-09-26 12:10:55 +00:00
|
|
|
|
2018-11-06 13:27:16 +00:00
|
|
|
expect(controller.selection).toEqual(data);
|
2017-09-26 12:10:55 +00:00
|
|
|
});
|
|
|
|
|
2018-10-18 19:04:46 +00:00
|
|
|
it(`should set selection to null when can't find an existing item in the data property`, () => {
|
2018-11-06 13:27:16 +00:00
|
|
|
expect(controller.selection).toEqual(null);
|
2018-10-18 19:04:46 +00:00
|
|
|
});
|
2017-09-28 10:37:45 +00:00
|
|
|
});
|
2017-09-26 08:26:21 +00:00
|
|
|
});
|