2018-08-09 13:40:37 +00:00
|
|
|
import './card.js';
|
|
|
|
|
2019-04-05 05:52:08 +00:00
|
|
|
describe('Order', () => {
|
2018-08-09 13:40:37 +00:00
|
|
|
describe('Component vnOrderCreateCard', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
2020-03-17 14:18:02 +00:00
|
|
|
let $scope;
|
2018-08-09 13:40:37 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('order'));
|
2018-08-09 13:40:37 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, _$httpBackend_, _vnApp_, $rootScope) => {
|
2018-08-09 13:40:37 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2020-03-17 14:18:02 +00:00
|
|
|
$scope = $rootScope.$new();
|
|
|
|
const $element = angular.element('<vn-order-create-card></vn-order-create-card>');
|
|
|
|
controller = $componentController('vnOrderCreateCard', {$element, $scope});
|
2018-08-09 13:40:37 +00:00
|
|
|
controller.item = {id: 3};
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('set order', () => {
|
|
|
|
it(`should set order if the value given is not null`, () => {
|
|
|
|
controller.order = 1;
|
|
|
|
|
|
|
|
expect(controller.order).toEqual(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('set clientFk', () => {
|
2019-04-05 05:52:08 +00:00
|
|
|
it(`should set addressFk to null and clientFk to a value and set addressFk to a value given`, () => {
|
|
|
|
let filter = {
|
|
|
|
include: {
|
|
|
|
relation: 'defaultAddress',
|
|
|
|
scope: {
|
|
|
|
fields: 'id'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
where: {id: 2}
|
|
|
|
};
|
|
|
|
filter = encodeURIComponent(JSON.stringify(filter));
|
|
|
|
let response = [
|
|
|
|
{
|
|
|
|
defaultAddress: {id: 1}
|
|
|
|
}
|
|
|
|
];
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.whenGET(`Clients?filter=${filter}`).respond(response);
|
|
|
|
$httpBackend.expectGET(`Clients?filter=${filter}`);
|
2019-04-05 05:52:08 +00:00
|
|
|
|
2018-08-09 13:40:37 +00:00
|
|
|
controller.clientFk = 2;
|
2019-04-05 05:52:08 +00:00
|
|
|
$httpBackend.flush();
|
2018-08-09 13:40:37 +00:00
|
|
|
|
|
|
|
expect(controller.clientFk).toEqual(2);
|
2019-04-05 05:52:08 +00:00
|
|
|
expect(controller.order.addressFk).toBe(1);
|
2018-08-09 13:40:37 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('set addressFk', () => {
|
|
|
|
it(`should set agencyModeFk property to null and addressFk to a value`, () => {
|
2021-06-23 11:24:23 +00:00
|
|
|
controller.addressFk = 1101;
|
2018-08-09 13:40:37 +00:00
|
|
|
|
2021-06-23 11:24:23 +00:00
|
|
|
expect(controller.addressFk).toEqual(1101);
|
2018-08-09 13:40:37 +00:00
|
|
|
expect(controller.order.agencyModeFk).toBe(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getAvailableAgencies()', () => {
|
|
|
|
it(`should make a query if landed and addressFk exists`, () => {
|
2021-06-23 11:24:23 +00:00
|
|
|
controller.order.addressFk = 1101;
|
|
|
|
controller.order.landed = 1101;
|
2018-08-09 13:40:37 +00:00
|
|
|
|
2019-10-31 14:38:20 +00:00
|
|
|
$httpBackend.whenRoute('GET', 'Agencies/landsThatDay')
|
|
|
|
.respond({data: 1});
|
2018-08-09 13:40:37 +00:00
|
|
|
|
|
|
|
controller.getAvailableAgencies();
|
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onSubmit()', () => {
|
|
|
|
it(`should call createOrder()`, () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'createOrder');
|
2018-08-09 13:40:37 +00:00
|
|
|
controller.onSubmit();
|
|
|
|
|
|
|
|
expect(controller.createOrder).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('createOrder()', () => {
|
|
|
|
it(`should make a query, call vnApp.showSuccess and $state.go if the response is defined`, () => {
|
2021-06-23 11:24:23 +00:00
|
|
|
controller.order.landed = 1101;
|
|
|
|
controller.order.addressFk = 1101;
|
|
|
|
controller.order.agencyModeFk = 1101;
|
2018-08-09 13:40:37 +00:00
|
|
|
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
jest.spyOn(controller.$state, 'go');
|
2021-06-23 11:24:23 +00:00
|
|
|
$httpBackend.expect('POST', 'Orders/new', {landed: 1101, addressId: 1101, agencyModeId: 1101}).respond(200, 1);
|
2018-08-09 13:40:37 +00:00
|
|
|
controller.createOrder();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2020-07-23 15:10:07 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2018-11-23 07:56:53 +00:00
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('order.card.catalog', {id: 1});
|
2018-08-09 13:40:37 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|