diff --git a/modules/invoiceIn/front/tax/index.js b/modules/invoiceIn/front/tax/index.js index 38e393176..26557c365 100644 --- a/modules/invoiceIn/front/tax/index.js +++ b/modules/invoiceIn/front/tax/index.js @@ -5,24 +5,11 @@ class Controller extends Section { constructor($element, $) { super($element, $); } - /* - get invoiceIn() { - return this._invoiceIn; - } - set invoiceIn(value) { - this._invoiceIn = value; - if (value) { - const filter = { - currency: this.invoiceIn.currency - } - this.$http.get(`ReferenceRates`, {filter}) - .then(res => this.referenceRate = res.data); - } - }*/ get setTaxRate() { return this._setTaxRate; } + set setTaxRate(selection) { this._setTaxRate = selection; const taxTypeSage = this.$.taxTypeSage.selection; @@ -32,13 +19,11 @@ class Controller extends Section { } add() { - const defaultExpenseFk = 6000000001; - this.$.model.insert({ - invoiceIn: this.$params.id, - expenseFk: defaultExpenseFk + invoiceIn: this.$params.id }); } + onSubmit() { this.$.watcher.check(); this.$.model.save().then(() => { diff --git a/modules/invoiceIn/front/tax/index.spec.js b/modules/invoiceIn/front/tax/index.spec.js new file mode 100644 index 000000000..3780d91f1 --- /dev/null +++ b/modules/invoiceIn/front/tax/index.spec.js @@ -0,0 +1,61 @@ +import './index.js'; +import watcher from 'core/mocks/watcher'; +import crudModel from 'core/mocks/crud-model'; + +describe('InvoiceIn', () => { + describe('Component tax', () => { + let controller; + let $scope; + let vnApp; + + beforeEach(ngModule('invoiceIn')); + + beforeEach(inject(($componentController, _$httpBackend_, $rootScope, _vnApp_) => { + vnApp = _vnApp_; + jest.spyOn(vnApp, 'showError'); + $scope = $rootScope.$new(); + $scope.model = crudModel; + + $scope.watcher = watcher; + const $element = angular.element(''); + controller = $componentController('vnInvoiceInTax', {$element, $scope}); + controller.invoiceIn = {id: 1}; + })); + + describe('setTaxRate() setter', () => { + it('should set tax rate with the Sage tax type value', () => { + const taxTypeSage = { + rate: 21 + }; + $scope.taxTypeSage = {}; + $scope.taxTypeSage.selection = taxTypeSage; + + $scope.taxableBase = {}; + $scope.taxableBase.value = 100; + + controller.setTaxRate = 0; + + expect(controller.taxRate).toEqual(21); + }); + }); + + describe('onSubmit()', () => { + it('should make HTTP POST request to save tax values', () => { + controller.card = {reload: () => {}}; + jest.spyOn($scope.watcher, 'check'); + jest.spyOn($scope.watcher, 'notifySaved'); + jest.spyOn($scope.watcher, 'updateOriginalData'); + jest.spyOn(controller.card, 'reload'); + jest.spyOn($scope.model, 'save'); + + controller.onSubmit(); + + expect($scope.model.save).toHaveBeenCalledWith(); + expect($scope.watcher.updateOriginalData).toHaveBeenCalledWith(); + expect($scope.watcher.check).toHaveBeenCalledWith(); + expect($scope.watcher.notifySaved).toHaveBeenCalledWith(); + expect(controller.card.reload).toHaveBeenCalledWith(); + }); + }); + }); +});