salix/modules/order/front/basic-data/index.spec.js

68 lines
2.5 KiB
JavaScript
Raw Permalink Normal View History

2019-02-06 13:56:36 +00:00
import './index.js';
describe('Order', () => {
describe('Component vnOrderBasicData', () => {
let $httpBackend;
let $httpParamSerializer;
2019-02-06 13:56:36 +00:00
let controller;
let $scope;
beforeEach(ngModule('order'));
2019-02-06 13:56:36 +00:00
beforeEach(inject(($compile, _$httpBackend_, $rootScope, _$httpParamSerializer_) => {
2019-02-06 13:56:36 +00:00
$httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
2019-02-06 13:56:36 +00:00
$scope = $rootScope.$new();
$httpBackend.whenRoute('GET', 'Addresses')
2019-02-06 13:56:36 +00:00
.respond([{id: 2, nickname: 'address 2'}]);
$httpBackend.whenRoute('GET', 'Clients')
2019-02-06 13:56:36 +00:00
.respond([{id: 1, defaultAddressFk: 1}]);
$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');
}));
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() => {
const addressId = 999;
const id = 444;
controller.selection = {id: id, defaultAddressFk: addressId};
2019-02-06 13:56:36 +00:00
$scope.$digest();
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;
controller.order.addressFk = 999;
2023-01-16 14:18:24 +00:00
controller.order.landed = Date.vnNew();
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
});
});
});
});