new testing in address-edit

This commit is contained in:
Daniel Herrero 2018-02-07 14:47:08 +01:00
parent d251227107
commit 87d423fd52
2 changed files with 41 additions and 2 deletions

View File

@ -61,7 +61,7 @@ export default class Controller {
} }
_observationsEquals(ob1, ob2) { _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() { submit() {

View File

@ -20,7 +20,46 @@ describe('Client', () => {
})); }));
it('should define and set address property', () => { 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()', () => { describe('$onInit()', () => {