Tarea #468 /address/edit/index.js Front unit test
This commit is contained in:
parent
e359fd4d16
commit
dd3f13942f
|
@ -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");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue