Autocomplete client side unit test for findItems

This commit is contained in:
Carlos 2017-09-28 12:37:45 +02:00
parent 720cf89204
commit 86fdb010ae
2 changed files with 46 additions and 0 deletions

View File

@ -204,6 +204,7 @@ class Autocomplete extends Component {
this.getItems(); this.getItems();
} }
} }
getItems() { getItems() {
let filter = {}; let filter = {};
@ -233,6 +234,7 @@ class Autocomplete extends Component {
} }
); );
} }
$onInit() { $onInit() {
this.findMore = this.url && this.maxRow; this.findMore = this.url && this.maxRow;
this.mouseFocus = false; this.mouseFocus = false;

View File

@ -153,4 +153,48 @@ describe('Component vnAutocomplete', () => {
}); });
}); });
}); });
describe('findItem()', () => {
it(`should return items array if the controller does not provide a url and nither it has items`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.items = ['Batman', 'Bruce Wayne'];
controller.findItems('some search value');
expect(controller.items.length).toEqual(2);
});
it(`should perform a query with the search value if the finding flag is false`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.items = ['Batman', 'Bruce Wayne'];
controller.findItems('Gotham');
expect(controller.items.length).toEqual(2);
});
it(`should perform a query with the search value if the finding flag is false`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
let search = 'The Joker';
let json = JSON.stringify({where: {name: {regexp: search}}});
$httpBackend.whenGET(`test.com?filter=${json}`).respond([{id: 3, name: 'The Joker'}]);
$httpBackend.expectGET(`test.com?filter=${json}`);
controller.findItems(search);
$httpBackend.flush();
expect(controller.items[0]).toEqual({id: 3, name: 'The Joker'});
});
it(`should perform a query with the search value if the finding flag is false`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
let search = 'The Joker';
let json = JSON.stringify({where: {name: {regexp: search}}});
$httpBackend.whenGET(`test.com?filter=${json}`).respond([{id: 3, name: 'The Joker'}]);
$httpBackend.expectGET(`test.com?filter=${json}`);
controller.findItems(search);
$httpBackend.flush();
expect(controller.items[0]).toEqual({id: 3, name: 'The Joker'});
});
// siguiente test el de Multiple!
});
}); });