Tarea #468 /address/edit/index.js Front unit test

This commit is contained in:
gerard 2018-08-21 14:13:11 +02:00
parent e359fd4d16
commit dd3f13942f
1 changed files with 52 additions and 0 deletions

View File

@ -5,6 +5,7 @@ describe('Client', () => {
let $componentController; let $componentController;
let $state; let $state;
let $httpBackend; let $httpBackend;
let controller;
beforeEach(() => { beforeEach(() => {
angular.mock.module('client'); angular.mock.module('client');
@ -17,6 +18,57 @@ describe('Client', () => {
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
$state.params.addressId = '1'; $state.params.addressId = '1';
controller = $componentController('vnClientAddressEdit', {$state: $state}); 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");
});
});
}); });
}); });