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()', () => {