From dd3f13942faf11427ccc06adbad35fd50a1f57ae Mon Sep 17 00:00:00 2001 From: gerard Date: Tue, 21 Aug 2018 14:13:11 +0200 Subject: [PATCH] Tarea #468 /address/edit/index.js Front unit test --- client/client/src/address/edit/index.spec.js | 52 ++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/client/client/src/address/edit/index.spec.js b/client/client/src/address/edit/index.spec.js index 902f4ee22..f50116348 100644 --- a/client/client/src/address/edit/index.spec.js +++ b/client/client/src/address/edit/index.spec.js @@ -5,6 +5,7 @@ describe('Client', () => { let $componentController; let $state; let $httpBackend; + let controller; beforeEach(() => { angular.mock.module('client'); @@ -17,6 +18,57 @@ describe('Client', () => { $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); $state.params.addressId = '1'; controller = $componentController('vnClientAddressEdit', {$state: $state}); + controller.$.watcher = { + setDirty: () => {}, + setPristine: () => {}, + realSubmit: () => {}, + check: () => {}, + notifySaved: () => {} + }; + controller.$.model = { + remove: () => {}, + save: () => {} + }; + controller.card = { + reload: () => {} + }; })); + + describe('removeObservation()', () => { + it('should call $.watcher.setDirty() and $.model.remove(index)', () => { + spyOn(controller.$.watcher, 'setDirty'); + spyOn(controller.$.model, 'remove'); + controller.removeObservation(1); + + expect(controller.$.model.remove).toHaveBeenCalledWith(1); + expect(controller.$.watcher.setDirty).toHaveBeenCalledWith(); + }); + }); + + describe('cancel(event)', () => { + it('should call event.preventDefault(), event.stopImmediatePropagation() and goToIndex', () => { + let event = { + preventDefault: () => {}, + stopImmediatePropagation: () => {} + }; + spyOn(event, 'preventDefault'); + spyOn(event, 'stopImmediatePropagation'); + spyOn(controller, 'goToIndex'); + controller.cancel(event); + + expect(event.preventDefault).toHaveBeenCalledWith(); + expect(event.stopImmediatePropagation).toHaveBeenCalledWith(); + expect(controller.goToIndex).toHaveBeenCalledWith(); + }); + }); + + describe('goToIndex()', () => { + it('should call $state.go("client.card.address.index")', () => { + spyOn(controller.$state, 'go'); + controller.goToIndex(); + + expect(controller.$state.go).toHaveBeenCalledWith("client.card.address.index"); + }); + }); }); });