68 lines
2.4 KiB
JavaScript
68 lines
2.4 KiB
JavaScript
import './index.js';
|
|
|
|
describe('Item', () => {
|
|
describe('Component vnItemTax', () => {
|
|
let $element;
|
|
let $stateParams;
|
|
let controller;
|
|
let $httpBackend;
|
|
|
|
beforeEach(angular.mock.module('item', $translateProvider => {
|
|
$translateProvider.translations('en', {});
|
|
}));
|
|
|
|
beforeEach(angular.mock.inject((_$httpBackend_, $rootScope, _$stateParams_, $compile) => {
|
|
$stateParams = _$stateParams_;
|
|
$stateParams.id = 1;
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$httpBackend.whenGET(url => url.startsWith(`api/TaxClasses`))
|
|
.respond([
|
|
{id: 1, description: 'Reduced VAT', code: 'R'},
|
|
{id: 2, description: 'General VAT', code: 'G'}
|
|
]);
|
|
|
|
$httpBackend.whenGET(url => url.startsWith(`api/Items/${$stateParams.id}/taxes`))
|
|
.respond([
|
|
{id: 1, taxClassFk: 1}
|
|
]);
|
|
|
|
$element = $compile(`<vn-item-tax></vn-item-tax`)($rootScope);
|
|
controller = $element.controller('vnItemTax');
|
|
}));
|
|
|
|
afterEach(() => {
|
|
$element.remove();
|
|
});
|
|
|
|
describe('getTaxes()', () => {
|
|
it('should perform a query to set the array of taxes into the controller', () => {
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.taxes[0].id).toEqual(1);
|
|
expect(controller.taxes[0].taxClassFk).toEqual(1);
|
|
});
|
|
});
|
|
|
|
describe('submit()', () => {
|
|
it('should perform a post to update taxes', () => {
|
|
spyOn(controller.$.watcher, 'notifySaved');
|
|
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'}}
|
|
];
|
|
|
|
$httpBackend.whenPOST(`api/Items/updateTaxes`).respond('oki doki');
|
|
controller.submit();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.$.watcher.notifySaved).toHaveBeenCalledWith();
|
|
expect(controller.$.watcher.updateOriginalData).toHaveBeenCalledWith();
|
|
});
|
|
});
|
|
});
|
|
});
|