salix/front/core/components/autocomplete/index.spec.js

55 lines
1.5 KiB
JavaScript

describe('Component vnAutocomplete', () => {
let $element;
let controller;
let data = {id: 1, name: 'Bruce Wayne'};
beforeEach(ngModule('vnCore'));
beforeEach(inject(($compile, $rootScope) => {
$element = $compile(`<vn-autocomplete></vn-autocomplete>`)($rootScope);
controller = $element.controller('vnAutocomplete');
}));
afterEach(() => {
$element.remove();
});
describe('url() setter', () => {
it(`should set the url property`, () => {
controller.url = '/TestModels';
expect(controller.url).toEqual('/TestModels');
});
});
describe('field() setter/getter', () => {
it(`should set the field property`, () => {
controller.field = 'id';
expect(controller.field).toEqual('id');
});
});
describe('selection property', () => {
beforeEach(() => {
controller.field = data.id;
});
it(`should set selection finding an existing item in the initialData property`, () => {
controller.initialData = data;
expect(controller.selection).toEqual(data);
});
it(`should set selection finding an existing item in the data property`, () => {
controller.data = [data];
expect(controller.selection).toEqual(data);
});
it(`should set selection to null when can't find an existing item in the data property`, () => {
expect(controller.selection).toEqual(null);
});
});
});