2018-08-09 11:13:50 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Item', () => {
|
|
|
|
describe('Component vnItemTax', () => {
|
2019-10-08 15:27:27 +00:00
|
|
|
let $element;
|
2018-08-09 11:13:50 +00:00
|
|
|
let $stateParams;
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('item'));
|
2018-08-09 11:13:50 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject((_$httpBackend_, $rootScope, _$stateParams_, $compile) => {
|
2018-08-09 11:13:50 +00:00
|
|
|
$stateParams = _$stateParams_;
|
|
|
|
$stateParams.id = 1;
|
|
|
|
$httpBackend = _$httpBackend_;
|
2019-10-08 15:27:27 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.whenRoute('GET', 'TaxClasses')
|
2019-10-08 15:27:27 +00:00
|
|
|
.respond([
|
|
|
|
{id: 1, description: 'Reduced VAT', code: 'R'},
|
|
|
|
{id: 2, description: 'General VAT', code: 'G'}
|
|
|
|
]);
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.whenRoute('GET', 'Items/:id/taxes')
|
2019-10-08 15:27:27 +00:00
|
|
|
.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
|
|
|
}));
|
|
|
|
|
2019-10-08 15:27:27 +00:00
|
|
|
afterEach(() => {
|
|
|
|
$element.remove();
|
|
|
|
});
|
|
|
|
|
2018-08-09 11:13:50 +00:00
|
|
|
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
|
|
|
$httpBackend.flush();
|
|
|
|
|
2019-10-08 15:27:27 +00:00
|
|
|
expect(controller.taxes[0].id).toEqual(1);
|
|
|
|
expect(controller.taxes[0].taxClassFk).toEqual(1);
|
2018-08-09 11:13:50 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('submit()', () => {
|
2018-12-22 10:59:26 +00:00
|
|
|
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');
|
2018-08-09 11:13:50 +00:00
|
|
|
|
2020-03-09 08:00:03 +00:00
|
|
|
controller.$onInit();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
controller.taxes.push({id: 3, description: 'General VAT', code: 'G'});
|
|
|
|
|
|
|
|
$httpBackend.whenPOST(`Items/updateTaxes`).respond(true);
|
2018-08-09 11:13:50 +00:00
|
|
|
controller.submit();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2019-10-08 15:27:27 +00:00
|
|
|
expect(controller.$.watcher.notifySaved).toHaveBeenCalledWith();
|
|
|
|
expect(controller.$.watcher.updateOriginalData).toHaveBeenCalledWith();
|
2018-08-09 11:13:50 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|