2018-05-23 12:26:51 +00:00
|
|
|
import './index';
|
2017-08-31 06:53:17 +00:00
|
|
|
|
2017-09-04 13:06:43 +00:00
|
|
|
describe('Client', () => {
|
2018-05-24 13:02:38 +00:00
|
|
|
describe('Component vnClientAddressEdit', () => {
|
2020-01-24 08:47:24 +00:00
|
|
|
let $scope;
|
2018-08-21 12:13:11 +00:00
|
|
|
let controller;
|
2020-01-24 08:47:24 +00:00
|
|
|
let $httpBackend;
|
|
|
|
let $element;
|
|
|
|
let $state;
|
2017-08-31 06:53:17 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('client'));
|
2017-08-31 06:53:17 +00:00
|
|
|
|
2020-01-24 08:47:24 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$state_, _$httpBackend_) => {
|
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$httpBackend = _$httpBackend_;
|
2017-09-04 13:06:43 +00:00
|
|
|
$state = _$state_;
|
2018-02-06 14:09:31 +00:00
|
|
|
$state.params.addressId = '1';
|
2020-01-24 08:47:24 +00:00
|
|
|
$element = angular.element('<vn-client-address-edit></vn-client-address-edit>');
|
|
|
|
controller = $componentController('vnClientAddressEdit', {$element, $scope});
|
|
|
|
controller.address = {id: 1, customsAgentFk: null};
|
2018-08-21 12:13:11 +00:00
|
|
|
controller.$.watcher = {
|
|
|
|
setDirty: () => {},
|
|
|
|
setPristine: () => {},
|
|
|
|
realSubmit: () => {},
|
|
|
|
check: () => {},
|
|
|
|
notifySaved: () => {}
|
|
|
|
};
|
|
|
|
controller.$.model = {
|
|
|
|
remove: () => {},
|
|
|
|
save: () => {}
|
|
|
|
};
|
|
|
|
controller.card = {
|
|
|
|
reload: () => {}
|
|
|
|
};
|
2017-09-04 13:06:43 +00:00
|
|
|
}));
|
2018-08-21 12:13:11 +00:00
|
|
|
|
|
|
|
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');
|
2018-08-21 12:13:11 +00:00
|
|
|
controller.removeObservation(1);
|
|
|
|
|
|
|
|
expect(controller.$.model.remove).toHaveBeenCalledWith(1);
|
|
|
|
expect(controller.$.watcher.setDirty).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-17 07:28:38 +00:00
|
|
|
describe('cancel()', () => {
|
|
|
|
it('should call goToIndex()', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'goToIndex');
|
2018-10-17 07:28:38 +00:00
|
|
|
controller.cancel();
|
2018-08-21 12:13:11 +00:00
|
|
|
|
|
|
|
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');
|
2018-08-21 12:13:11 +00:00
|
|
|
controller.goToIndex();
|
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('client.card.address.index');
|
2018-08-21 12:13:11 +00:00
|
|
|
});
|
|
|
|
});
|
2020-01-24 08:47:24 +00:00
|
|
|
|
|
|
|
describe('onCustomAgentAccept()', () => {
|
|
|
|
it(`should 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);
|
|
|
|
});
|
|
|
|
});
|
2017-08-31 06:53:17 +00:00
|
|
|
});
|
|
|
|
});
|