From 57b03790a3d55b1ce0f037b19fac418c9c3b53ba Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 3 Oct 2017 11:32:25 +0200 Subject: [PATCH] Autocomplete client side unit tests finished --- .../src/autocomplete/autocomplete.spec.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/client/core/src/autocomplete/autocomplete.spec.js b/client/core/src/autocomplete/autocomplete.spec.js index 0f31b5d96..b554973dd 100644 --- a/client/core/src/autocomplete/autocomplete.spec.js +++ b/client/core/src/autocomplete/autocomplete.spec.js @@ -195,5 +195,24 @@ describe('Component vnAutocomplete', () => { expect(controller.items).toEqual([{id: 3, name: 'The Joker', checked: false}, {id: 4, name: 'Joker', checked: false}]); }); + + it(`should call getItems function if there's no search value`, () => { + let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'}); + spyOn(controller, 'getItems'); + controller.findItems(); + + expect(controller.getItems).toHaveBeenCalledWith(); + }); + }); + describe('getItem()', () => { + it(`should perfom a query to fill the items without filter`, () => { + let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'}); + $httpBackend.whenGET(`test.com?filter={"skip":0,"limit":10,"order":"name ASC"}`).respond([{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}]); + $httpBackend.expectGET(`test.com?filter={"skip":0,"limit":10,"order":"name ASC"}`); + controller.getItems(); + $httpBackend.flush(); + + expect(controller.items).toEqual([{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}]); + }); }); });