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

62 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-06-29 06:59:55 +00:00
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('<vn-invoice-in-tax></vn-invoice-in-tax>');
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 = {};
2021-07-03 07:19:03 +00:00
$scope.taxableBase.value = 200;
2021-06-29 06:59:55 +00:00
2021-07-03 07:19:03 +00:00
controller.taxRateSelection = 0;
2021-06-29 06:59:55 +00:00
2021-07-03 07:19:03 +00:00
expect(controller.taxRate).toEqual(42);
2021-06-29 06:59:55 +00:00
});
});
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();
});
});
});
});