2018-08-09 11:13:50 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Item', () => {
|
|
|
|
describe('Component vnItemTax', () => {
|
|
|
|
let $stateParams;
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
let vnApp;
|
|
|
|
|
2019-09-13 14:09:14 +00:00
|
|
|
beforeEach(angular.mock.module('item', $translateProvider => {
|
|
|
|
$translateProvider.translations('en', {});
|
|
|
|
}));
|
2018-08-09 11:13:50 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _$stateParams_, _vnApp_) => {
|
2018-08-09 11:13:50 +00:00
|
|
|
$stateParams = _$stateParams_;
|
|
|
|
$stateParams.id = 1;
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
vnApp = _vnApp_;
|
|
|
|
spyOn(vnApp, 'showSuccess');
|
|
|
|
controller = $componentController('vnItemTax', {$state: $stateParams});
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('getTaxes()', () => {
|
2018-12-22 10:59:26 +00:00
|
|
|
it('should perform a query to set the array of taxes into the controller', () => {
|
2018-08-09 11:13:50 +00:00
|
|
|
let filter = {
|
|
|
|
fields: ['id', 'countryFk', 'taxClassFk'],
|
|
|
|
include: [{
|
|
|
|
relation: 'country',
|
|
|
|
scope: {fields: ['country']}
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
let response = [{id: 1, taxClassFk: 1}];
|
|
|
|
filter = encodeURIComponent(JSON.stringify(filter));
|
|
|
|
$httpBackend.when('GET', `/item/api/Items/1/taxes?filter=${filter}`).respond(response);
|
|
|
|
$httpBackend.expect('GET', `/item/api/Items/1/taxes?filter=${filter}`);
|
|
|
|
controller.$onInit();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.taxes).toEqual(response);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('submit()', () => {
|
2018-12-22 10:59:26 +00:00
|
|
|
it('should perform a post to update taxes', () => {
|
2018-08-09 11:13:50 +00:00
|
|
|
let filter = {
|
|
|
|
fields: ['id', 'countryFk', 'taxClassFk'],
|
|
|
|
include: [{
|
|
|
|
relation: 'country',
|
|
|
|
scope: {fields: ['country']}
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
let response = [{id: 1, taxClassFk: 1}];
|
|
|
|
filter = encodeURIComponent(JSON.stringify(filter));
|
|
|
|
$httpBackend.when('GET', `/item/api/Items/1/taxes?filter=${filter}`).respond(response);
|
|
|
|
controller.$onInit();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2018-08-30 05:15:04 +00:00
|
|
|
$httpBackend.when('POST', `/item/api/Items/updateTaxes`).respond('ok');
|
|
|
|
$httpBackend.expect('POST', `/item/api/Items/updateTaxes`);
|
2018-08-09 11:13:50 +00:00
|
|
|
controller.submit();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|