salix/modules/client/front/address/edit/index.spec.js

78 lines
2.8 KiB
JavaScript
Raw Normal View History

2018-05-23 12:26:51 +00:00
import './index';
describe('Client', () => {
describe('Component vnClientAddressEdit', () => {
let $scope;
let controller;
let $httpBackend;
let $element;
let $state;
beforeEach(ngModule('client'));
2020-07-23 14:46:16 +00:00
beforeEach(inject(($componentController, $rootScope, _$state_, _$httpBackend_) => {
$scope = $rootScope.$new();
$httpBackend = _$httpBackend_;
$state = _$state_;
2018-02-06 14:09:31 +00:00
$state.params.addressId = '1';
$element = angular.element('<vn-client-address-edit></vn-client-address-edit>');
controller = $componentController('vnClientAddressEdit', {$element, $scope});
controller.address = {id: 1, customsAgentFk: null};
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)', () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller.$.watcher, 'setDirty');
jest.spyOn(controller.$.model, 'remove');
controller.removeObservation(1);
expect(controller.$.model.remove).toHaveBeenCalledWith(1);
expect(controller.$.watcher.setDirty).toHaveBeenCalledWith();
});
});
describe('cancel()', () => {
it('should call goToIndex()', () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'goToIndex');
controller.cancel();
expect(controller.goToIndex).toHaveBeenCalledWith();
});
});
describe('goToIndex()', () => {
it('should call $state.go("client.card.address.index")', () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller.$state, 'go');
controller.goToIndex();
expect(controller.$state.go).toHaveBeenCalledWith('client.card.address.index');
});
});
describe('onCustomAgentAccept()', () => {
2020-05-28 07:54:31 +00:00
it(`should now create a new customs agent and then set the customsAgentFk property on the address`, () => {
const expectedResult = {id: 1, fiscalName: 'Customs agent one'};
$httpBackend.when('POST', 'CustomsAgents').respond(200, expectedResult);
controller.onCustomAgentAccept();
$httpBackend.flush();
expect(controller.address.customsAgentFk).toEqual(1);
});
});
});
});