78 lines
2.6 KiB
JavaScript
78 lines
2.6 KiB
JavaScript
import './index';
|
|
|
|
describe('vnInvoiceInDescriptor', () => {
|
|
let controller;
|
|
let $httpBackend;
|
|
|
|
beforeEach(ngModule('invoiceIn'));
|
|
|
|
beforeEach(inject(($componentController, _$httpBackend_) => {
|
|
$httpBackend = _$httpBackend_;
|
|
const $element = angular.element('<vn-invoice-in-descriptor></vn-invoice-in-descriptor>');
|
|
|
|
controller = $componentController('vnInvoiceInDescriptor', {$element});
|
|
controller.invoiceIn = {id: 1};
|
|
$httpBackend.when('GET', `InvoiceIns/${controller.invoiceIn.id}`).respond({id: 1});
|
|
}));
|
|
|
|
describe('loadData()', () => {
|
|
it(`should perform a get query to store the invoice in data into the controller`, () => {
|
|
expect(controller.invoiceIn).toEqual({id: 1});
|
|
});
|
|
});
|
|
|
|
describe('onAcceptToBook()', () => {
|
|
it(`should perform a post query to book the invoice`, () => {
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
controller.$state.reload = jest.fn();
|
|
|
|
const id = 1;
|
|
|
|
$httpBackend.expectPOST(`InvoiceIns/${id}/toBook`).respond();
|
|
controller.onAcceptToBook();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('InvoiceIn booked');
|
|
});
|
|
});
|
|
|
|
describe('checktoBook()', () => {
|
|
it(`should show both warning messages`, () => {
|
|
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();
|
|
|
|
controller.checktoBook();
|
|
$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();
|
|
|
|
controller.checktoBook();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.onAcceptToBook).toHaveBeenCalledWith();
|
|
});
|
|
});
|
|
});
|