salix/modules/order/front/create/card.spec.js

107 lines
4.0 KiB
JavaScript
Raw Normal View History

import './card.js';
2019-04-05 05:52:08 +00:00
describe('Order', () => {
describe('Component vnOrderCreateCard', () => {
let controller;
let $httpBackend;
2019-09-13 14:09:14 +00:00
beforeEach(angular.mock.module('order', $translateProvider => {
$translateProvider.translations('en', {});
}));
beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _vnApp_) => {
$httpBackend = _$httpBackend_;
controller = $componentController('vnOrderCreateCard');
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}
}
];
$httpBackend.whenGET(`/api/Clients?filter=${filter}`).respond(response);
$httpBackend.expectGET(`/api/Clients?filter=${filter}`);
controller.clientFk = 2;
2019-04-05 05:52:08 +00:00
$httpBackend.flush();
expect(controller.clientFk).toEqual(2);
2019-04-05 05:52:08 +00:00
expect(controller.order.addressFk).toBe(1);
});
});
describe('set addressFk', () => {
it(`should set agencyModeFk property to null and addressFk to a value`, () => {
controller.addressFk = 101;
expect(controller.addressFk).toEqual(101);
expect(controller.order.agencyModeFk).toBe(null);
});
});
describe('getAvailableAgencies()', () => {
it(`should make a query if landed and addressFk exists`, () => {
controller.order.addressFk = 101;
controller.order.landed = 101;
let filter = {addressFk: controller.order.addressFk, landed: controller.order.landed};
filter = encodeURIComponent(JSON.stringify(filter));
$httpBackend.whenGET(`/api/Agencies/landsThatDay?filter=${filter}`).respond({data: 1});
$httpBackend.expectGET(`/api/Agencies/landsThatDay?filter=${filter}`);
controller.getAvailableAgencies();
$httpBackend.flush();
});
});
describe('onSubmit()', () => {
it(`should call createOrder()`, () => {
spyOn(controller, 'createOrder');
controller.onSubmit();
expect(controller.createOrder).toHaveBeenCalledWith();
});
});
describe('createOrder()', () => {
it(`should make a query, call vnApp.showSuccess and $state.go if the response is defined`, () => {
controller.order.landed = 101;
controller.order.addressFk = 101;
controller.order.agencyModeFk = 101;
spyOn(controller.vnApp, 'showSuccess');
spyOn(controller.$state, 'go');
2019-06-03 10:41:57 +00:00
$httpBackend.when('POST', 'order/api/Orders/new', {landed: 101, addressId: 101, agencyModeId: 101}).respond(200, 1);
$httpBackend.expect('POST', 'order/api/Orders/new', {landed: 101, addressId: 101, agencyModeId: 101});
controller.createOrder();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
2018-11-23 07:56:53 +00:00
expect(controller.$state.go).toHaveBeenCalledWith('order.card.catalog', {id: 1});
});
});
});
});