From 9ae7898c19de3d3662f6b8d6e0a1bc0383d61f33 Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 27 Sep 2017 09:42:59 +0200 Subject: [PATCH 1/3] client side unit test for autocomplete field() > setValue() --- .../src/autocomplete/autocomplete.spec.js | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/client/core/src/autocomplete/autocomplete.spec.js b/client/core/src/autocomplete/autocomplete.spec.js index 060ec5c96..92369fcaf 100644 --- a/client/core/src/autocomplete/autocomplete.spec.js +++ b/client/core/src/autocomplete/autocomplete.spec.js @@ -75,24 +75,18 @@ describe('Component vnAutocomplete', () => { }); }); - describe('when value is not an object', () => { // not sure if it isnt an object actually + describe('when value is not an object', () => { it(`should set _field value`, () => { let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}); - controller.valueField = 'name'; - controller.items = [{name: 'test1'}, {name: 'test2'}]; - // controller.field = 6; puede ser cualquier cosa + controller.items = [{id: 1, name: 'test1'}, {id: 2, name: 'Bruce Wayne'}]; + controller.field = 2; - // // request datasources.development.json to Vicente to carry on - // // let json = find out the value of json stringify - // // let url = find out the url for get endpoint + expect(controller._field).toEqual(2); + expect(controller._multiField).toEqual([]); - // controller.field = {name: 'Bruce Wayne'}; + controller.field = {id: 3, name: 'The Joker'}; - // // same URL for requests - // $httpBackend.when('GET', `localhost:5000?filter=Bruce`).respond('done'); - // $httpBackend.expectGET(`localhost:5000?filter=Bruce`, {name: 'Bruce Wayne'}); - // // any value to be defined before the flush? - // $httpBackend.flush(); + expect(controller._field).toEqual(3); }); }); }); From ef7ee123739bab7a586e072bdfab4fa64f90634a Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 27 Sep 2017 11:51:25 +0200 Subject: [PATCH 2/3] client side unit test for autocomplete field() query functionality --- client/core/src/autocomplete/autocomplete.spec.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/client/core/src/autocomplete/autocomplete.spec.js b/client/core/src/autocomplete/autocomplete.spec.js index 92369fcaf..6e2b89bf6 100644 --- a/client/core/src/autocomplete/autocomplete.spec.js +++ b/client/core/src/autocomplete/autocomplete.spec.js @@ -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(); + }); }); }); }); From 5dc0608f865e0601f2d25c45da80214db96fc74a Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 27 Sep 2017 11:58:35 +0200 Subject: [PATCH 3/3] error corrected --- client/core/src/autocomplete/autocomplete.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/core/src/autocomplete/autocomplete.spec.js b/client/core/src/autocomplete/autocomplete.spec.js index 6e2b89bf6..21dbcec9b 100644 --- a/client/core/src/autocomplete/autocomplete.spec.js +++ b/client/core/src/autocomplete/autocomplete.spec.js @@ -91,7 +91,7 @@ describe('Component vnAutocomplete', () => { 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.whenGET('test.com?filter={"fields":{"id":true,"name":true},"where":{"id":3}}').respond(); $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;