diff --git a/client/core/src/autocomplete/autocomplete.js b/client/core/src/autocomplete/autocomplete.js index 98ad4675a..b87361fdc 100644 --- a/client/core/src/autocomplete/autocomplete.js +++ b/client/core/src/autocomplete/autocomplete.js @@ -204,6 +204,7 @@ class Autocomplete extends Component { this.getItems(); } } + getItems() { let filter = {}; @@ -233,6 +234,7 @@ class Autocomplete extends Component { } ); } + $onInit() { this.findMore = this.url && this.maxRow; this.mouseFocus = false; diff --git a/client/core/src/autocomplete/autocomplete.spec.js b/client/core/src/autocomplete/autocomplete.spec.js index 67d48c147..8999e25b0 100644 --- a/client/core/src/autocomplete/autocomplete.spec.js +++ b/client/core/src/autocomplete/autocomplete.spec.js @@ -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! + }); });