client side unit test for autocomplete field() query functionality

This commit is contained in:
Carlos 2017-09-27 11:51:25 +02:00
parent 7b391ef9a1
commit ef7ee12373
1 changed files with 11 additions and 2 deletions

View File

@ -75,8 +75,8 @@ describe('Component vnAutocomplete', () => {
});
});
describe('when value is not an object', () => {
it(`should set _field value`, () => {
describe('when value is a number', () => {
it(`should set field find an existing item in the controller.items property`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.items = [{id: 1, name: 'test1'}, {id: 2, name: 'Bruce Wayne'}];
controller.field = 2;
@ -88,6 +88,15 @@ describe('Component vnAutocomplete', () => {
expect(controller._field).toEqual(3);
});
it(`should set field performing a query as the item id isn't present in the controller.items property`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
$httpBackend.whenGET('test.com?filter={"fields":{"id":true,"name":true},"where":{"id":3}}').respond(3);
$httpBackend.expectGET('test.com?filter={"fields":{"id":true,"name":true},"where":{"id":3}}');
controller.items = [{id: 1, name: 'test1'}, {id: 2, name: 'Bruce Wayne'}];
controller.field = 3;
$httpBackend.flush();
});
});
});
});