salix/modules/item/front/tax/index.spec.js

66 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-08-09 11:13:50 +00:00
import './index.js';
describe('Item', () => {
describe('Component vnItemTax', () => {
let $element;
2018-08-09 11:13:50 +00:00
let $stateParams;
let controller;
let $httpBackend;
beforeEach(ngModule('item'));
2018-08-09 11:13:50 +00:00
beforeEach(angular.mock.inject((_$httpBackend_, $rootScope, _$stateParams_, $compile) => {
2018-08-09 11:13:50 +00:00
$stateParams = _$stateParams_;
$stateParams.id = 1;
$httpBackend = _$httpBackend_;
$httpBackend.whenRoute('GET', 'TaxClasses')
.respond([
{id: 1, description: 'Reduced VAT', code: 'R'},
{id: 2, description: 'General VAT', code: 'G'}
]);
$httpBackend.whenRoute('GET', 'Items/:id/taxes')
.respond([
{id: 1, taxClassFk: 1}
]);
$element = $compile(`<vn-item-tax></vn-item-tax`)($rootScope);
controller = $element.controller('vnItemTax');
2018-08-09 11:13:50 +00:00
}));
afterEach(() => {
$element.remove();
});
2018-08-09 11:13:50 +00:00
describe('getTaxes()', () => {
it('should perform a query to set the array of taxes into the controller', () => {
2018-08-09 11:13:50 +00:00
$httpBackend.flush();
expect(controller.taxes[0].id).toEqual(1);
expect(controller.taxes[0].taxClassFk).toEqual(1);
2018-08-09 11:13:50 +00:00
});
});
describe('submit()', () => {
it('should perform a post to update taxes', () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller.$.watcher, 'notifySaved');
jest.spyOn(controller.$.watcher, 'updateOriginalData');
controller.taxes = [
{id: 37, countryFk: 1, taxClassFk: 1, country: {id: 1, country: 'España'}}
];
controller.$.watcher.data = [
{id: 37, countryFk: 1, taxClassFk: 2, country: {id: 1, country: 'España'}}
];
2018-08-09 11:13:50 +00:00
$httpBackend.whenPOST(`Items/updateTaxes`).respond('oki doki');
2018-08-09 11:13:50 +00:00
controller.submit();
$httpBackend.flush();
expect(controller.$.watcher.notifySaved).toHaveBeenCalledWith();
expect(controller.$.watcher.updateOriginalData).toHaveBeenCalledWith();
2018-08-09 11:13:50 +00:00
});
});
});
});