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

55 lines
1.5 KiB
JavaScript
Raw Normal View History

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'};
beforeEach(ngModule('vnCore'));
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');
}));
2018-10-18 18:48:21 +00:00
afterEach(() => {
$element.remove();
});
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-11-06 13:27:16 +00:00
expect(controller.url).toEqual('/TestModels');
});
});
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';
2018-11-06 13:27:16 +00:00
expect(controller.field).toEqual('id');
});
2018-10-18 18:48:21 +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;
2018-11-06 13:27:16 +00:00
expect(controller.selection).toEqual(data);
});
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];
2018-11-06 13:27:16 +00:00
expect(controller.selection).toEqual(data);
});
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
});
});
});