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

131 lines
4.7 KiB
JavaScript
Raw Permalink Normal View History

2018-05-23 12:26:51 +00:00
import './index';
import watcher from 'core/mocks/watcher';
describe('Client', () => {
describe('Component vnClientAddressCreate', () => {
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_;
$state.params.id = '1234';
$element = angular.element('<vn-client-address-create></vn-client-address-create>');
controller = $componentController('vnClientAddressCreate', {$element, $scope});
controller.$.watcher = watcher;
controller.$.watcher.submit = () => {
return {
then: callback => {
callback({data: {id: 124}});
}
};
};
controller.client = {id: 1101, defaultAddressFk: 121};
}));
it('should define and set address property', () => {
2020-01-28 08:03:20 +00:00
expect(controller.address.isActive).toBe(true);
});
describe('onSubmit()', () => {
it('should perform a PATCH and not set value to defaultAddressFk property', () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller.$state, 'go');
2020-01-28 08:03:20 +00:00
controller.address.isDefaultAddress = false;
controller.onSubmit();
expect(controller.client.defaultAddressFk).toEqual(121);
expect(controller.$state.go).toHaveBeenCalledWith('client.card.address.index');
});
it('should perform a PATCH and set a value to defaultAddressFk property', () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller.$state, 'go');
2020-01-28 08:03:20 +00:00
controller.address.isDefaultAddress = true;
controller.onSubmit();
expect(controller.client.defaultAddressFk).toEqual(124);
expect(controller.$state.go).toHaveBeenCalledWith('client.card.address.index');
});
});
2019-07-08 12:07:09 +00:00
2020-03-03 14:03:54 +00:00
describe('town() setter', () => {
2020-10-20 12:42:23 +00:00
it(`should set provinceFk property`, () => {
2020-03-03 14:03:54 +00:00
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: []
};
2020-10-20 12:42:23 +00:00
expect(controller.address.provinceFk).toEqual(1);
2020-03-03 14:03:54 +00:00
});
2020-10-20 12:42:23 +00:00
it(`should set provinceFk property and fill the postalCode if there's just one`, () => {
2020-03-03 14:03:54 +00:00
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: [{code: '46001'}]
};
2020-10-20 12:42:23 +00:00
expect(controller.address.provinceFk).toEqual(1);
2020-03-03 14:03:54 +00:00
expect(controller.address.postalCode).toEqual('46001');
});
});
describe('postcode() setter', () => {
it(`should set the town and province properties`, () => {
controller.postcode = {
2019-07-08 12:07:09 +00:00
townFk: 1,
code: 46001,
town: {
id: 1,
name: 'New York',
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
}
}
};
expect(controller.address.city).toEqual('New York');
2020-10-20 12:42:23 +00:00
expect(controller.address.provinceFk).toEqual(1);
2019-07-08 12:07:09 +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();
2020-10-20 12:42:23 +00:00
expect(controller.address.customsAgentFk).toEqual(1);
});
});
});
});