From d2512271076660ec8694643323721efe360594cd Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Wed, 7 Feb 2018 13:26:21 +0100 Subject: [PATCH 1/3] changes in logic address-edit --- client/client/src/address-edit/address-edit.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/client/src/address-edit/address-edit.js b/client/client/src/address-edit/address-edit.js index 90009cbe8..7cfc8bd06 100644 --- a/client/client/src/address-edit/address-edit.js +++ b/client/client/src/address-edit/address-edit.js @@ -80,12 +80,13 @@ export default class Controller { let observation = this.observations[i]; let isNewObservation = observation.id === undefined; - if (types.indexOf(observation.observationTypeFk) !== -1) { + if (observation.observationTypeFk && types.indexOf(observation.observationTypeFk) !== -1) { repeatedTypes = true; break; } - types.push(observation.observationTypeFk); + if (observation.observationTypeFk) + types.push(observation.observationTypeFk); if (isNewObservation && observation.observationTypeFk && observation.description) { observationsObj.create.push(observation); From 87d423fd52f25b257fa5be650e711ae3352895c2 Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Wed, 7 Feb 2018 14:47:08 +0100 Subject: [PATCH 2/3] new testing in address-edit --- .../client/src/address-edit/address-edit.js | 2 +- .../src/address-edit/address-edit.spec.js | 41 ++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/client/client/src/address-edit/address-edit.js b/client/client/src/address-edit/address-edit.js index 7cfc8bd06..3046b2733 100644 --- a/client/client/src/address-edit/address-edit.js +++ b/client/client/src/address-edit/address-edit.js @@ -61,7 +61,7 @@ export default class Controller { } _observationsEquals(ob1, ob2) { - return ob1.observationTypeFk === ob2.observationTypeFk && ob1.description === ob2.description; + return ob1.id === ob2.id && ob1.observationTypeFk === ob2.observationTypeFk && ob1.description === ob2.description; } submit() { diff --git a/client/client/src/address-edit/address-edit.spec.js b/client/client/src/address-edit/address-edit.spec.js index 18fff508f..8f14a2ec9 100644 --- a/client/client/src/address-edit/address-edit.spec.js +++ b/client/client/src/address-edit/address-edit.spec.js @@ -20,7 +20,46 @@ describe('Client', () => { })); it('should define and set address property', () => { - expect(controller.address.id).toBe(1); + expect(controller.address.id).toEqual(1); + }); + + describe('removeObservation(index)', () => { + it('should remove an observation that occupies the index given and restore showAddIcon properties', () => { + let index = 2; + controller.observations = [ + {id: 1, description: 'Spiderman rocks', showAddIcon: false}, + {id: 2, description: 'Batman sucks', showAddIcon: false}, + {id: 3, description: 'Ironman rules', showAddIcon: true} + ]; + + spyOn(controller, '_setIconAdd').and.callThrough(); + + controller.removeObservation(index); + + expect(controller._setIconAdd).toHaveBeenCalledWith(); + expect(controller.observations.length).toEqual(2); + expect(controller.observations[0].showAddIcon).toBeFalsy(); + expect(controller.observations[1].showAddIcon).toBeTruthy(); + expect(controller.observations[index]).toBe(undefined); + }); + }); + + describe('_observationsEquals', () => { + it('should return true if two observations are equals independent of control attributes', () => { + let ob1 = {id: 1, observationTypeFk: 1, description: 'Spiderman rocks', showAddIcon: true}; + let ob2 = {id: 1, observationTypeFk: 1, description: 'Spiderman rocks', showAddIcon: false}; + let equals = controller._observationsEquals(ob2, ob1); + + expect(equals).toBeTruthy(); + }); + + it('should return false if two observations are not equals independent of control attributes', () => { + let ob1 = {id: 1, observationTypeFk: 1, description: 'Spiderman rocks', showAddIcon: true}; + let ob2 = {id: 1, observationTypeFk: 1, description: 'Spiderman sucks', showAddIcon: true}; + let equals = controller._observationsEquals(ob2, ob1); + + expect(equals).toBeFalsy(); + }); }); describe('$onInit()', () => { From 2cc6dfd55353dcd8d880d47dac4cdd46502ee7ba Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Wed, 7 Feb 2018 14:48:11 +0100 Subject: [PATCH 3/3] changes in last test --- client/client/src/address-edit/address-edit.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/client/src/address-edit/address-edit.spec.js b/client/client/src/address-edit/address-edit.spec.js index 8f14a2ec9..5c41d653c 100644 --- a/client/client/src/address-edit/address-edit.spec.js +++ b/client/client/src/address-edit/address-edit.spec.js @@ -24,7 +24,7 @@ describe('Client', () => { }); describe('removeObservation(index)', () => { - it('should remove an observation that occupies the index given and restore showAddIcon properties', () => { + it('should remove an observation that occupies in the index given and restore showAddIcon properties', () => { let index = 2; controller.observations = [ {id: 1, description: 'Spiderman rocks', showAddIcon: false},