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

88 lines
3.0 KiB
JavaScript

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;
let $httpBackend;
beforeEach(ngModule('invoiceIn'));
beforeEach(inject(($componentController, $rootScope, _vnApp_, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
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.$.model = crudModel;
controller.invoiceIn = {id: 1};
}));
describe('taxRate()', () => {
it('should set tax rate with the Sage tax type value', () => {
const taxRateSelection = {
rate: 21
};
const invoiceInTax = {
taxableBase: 200
};
const taxRate = controller.taxRate(invoiceInTax, taxRateSelection);
expect(taxRate).toEqual(42);
});
});
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();
});
});
describe('onResponse()', () => {
it('should return success message', () => {
controller.expence = {
code: 7050000005,
isWithheld: 0,
description: 'Test'
};
const params = [{
id: controller.expence.code,
isWithheld: controller.expence.isWithheld,
name: controller.expence.description
}];
jest.spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expect('POST', `Expenses`, params).respond();
controller.onResponse();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Expence saved!');
});
});
});
});