2019-02-06 13:56:36 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Order', () => {
|
|
|
|
describe('Component vnOrderBasicData', () => {
|
|
|
|
let $httpBackend;
|
2021-08-31 11:02:14 +00:00
|
|
|
let $httpParamSerializer;
|
2019-02-06 13:56:36 +00:00
|
|
|
let controller;
|
|
|
|
let $scope;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('order'));
|
2019-02-06 13:56:36 +00:00
|
|
|
|
2021-08-31 11:02:14 +00:00
|
|
|
beforeEach(inject(($compile, _$httpBackend_, $rootScope, _$httpParamSerializer_) => {
|
2019-02-06 13:56:36 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2021-08-31 11:02:14 +00:00
|
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
2019-02-06 13:56:36 +00:00
|
|
|
$scope = $rootScope.$new();
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.whenRoute('GET', 'Addresses')
|
2019-02-06 13:56:36 +00:00
|
|
|
.respond([{id: 2, nickname: 'address 2'}]);
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.whenRoute('GET', 'Clients')
|
2019-02-06 13:56:36 +00:00
|
|
|
.respond([{id: 1, defaultAddressFk: 1}]);
|
2019-02-15 12:26:49 +00:00
|
|
|
$scope.order = {clientFk: 1, addressFk: 1};
|
2019-02-06 13:56:36 +00:00
|
|
|
|
|
|
|
let $element = $compile('<vn-order-basic-data order="order"></vn-order-basic-data>')($scope);
|
|
|
|
$httpBackend.flush();
|
|
|
|
controller = $element.controller('vnOrderBasicData');
|
|
|
|
}));
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
afterAll(() => {
|
|
|
|
$scope.$destroy();
|
|
|
|
$element.remove();
|
|
|
|
});
|
|
|
|
|
2019-02-06 13:56:36 +00:00
|
|
|
describe('constructor()', () => {
|
|
|
|
it('should update the address after the client changes', async() => {
|
2021-08-31 11:02:14 +00:00
|
|
|
const addressId = 999;
|
|
|
|
const id = 444;
|
|
|
|
|
|
|
|
controller.selection = {id: id, defaultAddressFk: addressId};
|
2019-02-06 13:56:36 +00:00
|
|
|
$scope.$digest();
|
|
|
|
|
2021-08-31 11:02:14 +00:00
|
|
|
expect(controller.order.addressFk).toEqual(addressId);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getAvailableAgencies()', () => {
|
|
|
|
it('should set agencyModeFk to null and get the available agencies if the order has landed and client', async() => {
|
|
|
|
controller.order.agencyModeFk = 999;
|
2021-08-31 12:10:37 +00:00
|
|
|
controller.order.addressFk = 999;
|
2021-08-31 11:02:14 +00:00
|
|
|
controller.order.landed = new Date();
|
|
|
|
|
|
|
|
const expectedAgencies = [{id: 1}, {id: 2}];
|
|
|
|
|
|
|
|
const paramsObj = {
|
|
|
|
addressFk: controller.order.addressFk,
|
|
|
|
landed: controller.order.landed
|
|
|
|
};
|
|
|
|
const serializedParams = $httpParamSerializer(paramsObj);
|
|
|
|
$httpBackend.expect('GET', `Agencies/landsThatDay?${serializedParams}`).respond(expectedAgencies);
|
|
|
|
controller.getAvailableAgencies();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.order.agencyModeFk).toBeDefined();
|
|
|
|
expect(controller._availableAgencies).toEqual(expectedAgencies);
|
2019-02-06 13:56:36 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|