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

91 lines
3.0 KiB
JavaScript
Raw Permalink Normal View History

2021-03-03 06:44:09 +00:00
import './index';
describe('vnInvoiceInDescriptor', () => {
let controller;
let $httpBackend;
beforeEach(ngModule('invoiceIn'));
beforeEach(inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
2021-12-14 07:33:29 +00:00
const $element = angular.element('<vn-invoice-in-descriptor></vn-invoice-in-descriptor>');
controller = $componentController('vnInvoiceInDescriptor', {$element});
2021-10-05 09:19:48 +00:00
controller.invoiceIn = {id: 1};
2021-03-03 06:44:09 +00:00
}));
describe('loadData()', () => {
it(`should perform a get query to store the invoice in data into the controller`, () => {
const invoiceIn = {
id: 1,
invoiceInDueDay: [
{amount: 1},
{amount: 2}
]
};
const expectedAmount = invoiceIn.invoiceInDueDay[0].amount + invoiceIn.invoiceInDueDay[1].amount;
$httpBackend.when('GET', `InvoiceIns/${controller.invoiceIn.id}`).respond(invoiceIn);
controller.loadData();
$httpBackend.flush();
expect(controller.invoiceIn.id).toEqual(invoiceIn.id);
expect(controller.invoiceIn.amount).toEqual(expectedAmount);
2021-03-03 06:44:09 +00:00
});
});
2021-09-24 06:24:34 +00:00
2021-10-05 09:19:48 +00:00
describe('onAcceptToBook()', () => {
it(`should perform a post query to book the invoice`, () => {
2021-12-14 07:33:29 +00:00
jest.spyOn(controller.vnApp, 'showSuccess');
controller.$state.reload = jest.fn();
2021-09-24 06:24:34 +00:00
const id = 1;
2021-10-05 09:19:48 +00:00
$httpBackend.expectPOST(`InvoiceIns/${id}/toBook`).respond();
controller.onAcceptToBook();
2021-09-24 06:24:34 +00:00
$httpBackend.flush();
2021-10-05 09:19:48 +00:00
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('InvoiceIn booked');
2021-09-24 06:24:34 +00:00
});
});
2022-01-19 13:21:19 +00:00
2022-01-20 09:05:24 +00:00
describe('checkToBook()', () => {
2022-01-24 14:35:32 +00:00
it(`should show a warning before book`, () => {
2022-01-19 13:21:19 +00:00
controller.$.confirmToBookAnyway = {show: () => {}};
jest.spyOn(controller.$.confirmToBookAnyway, 'show');
const invoceInId = 1;
const data = {
totalDueDay: 'an amount',
totalTaxableBase: 'distinct amount'
};
$httpBackend.expectGET(`InvoiceIns/${invoceInId}/getTotals`).respond(data);
$httpBackend.expectGET(`InvoiceInDueDays/count`).respond();
2022-01-20 09:05:24 +00:00
controller.checkToBook();
2022-01-19 13:21:19 +00:00
$httpBackend.flush();
expect(controller.$.confirmToBookAnyway.show).toHaveBeenCalledWith();
});
it(`should call onAcceptToBook`, () => {
controller.onAcceptToBook = jest.fn();
const invoceInId = 1;
const data = {
totalDueDay: 'same amount',
totalTaxableBase: 'same amount'
};
$httpBackend.expectGET(`InvoiceIns/${invoceInId}/getTotals`).respond(data);
$httpBackend.expectGET(`InvoiceInDueDays/count`).respond();
2022-01-20 09:05:24 +00:00
controller.checkToBook();
2022-01-19 13:21:19 +00:00
$httpBackend.flush();
expect(controller.onAcceptToBook).toHaveBeenCalledWith();
});
});
2021-03-03 06:44:09 +00:00
});