2018-11-08 14:20:42 +00:00
|
|
|
import './index.js';
|
|
|
|
|
2019-11-25 06:46:00 +00:00
|
|
|
describe('Ticket Component vnTicketDescriptor', () => {
|
2018-11-08 14:20:42 +00:00
|
|
|
let $httpBackend;
|
|
|
|
let controller;
|
2019-09-06 07:47:58 +00:00
|
|
|
let $state;
|
2018-11-08 14:20:42 +00:00
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
const ticket = {
|
|
|
|
id: 2,
|
|
|
|
clientFk: 101,
|
|
|
|
invoiceOut: {id: 1},
|
|
|
|
client: {
|
|
|
|
id: 101,
|
|
|
|
email: 'client@email'
|
|
|
|
},
|
|
|
|
address: {
|
|
|
|
id: 101,
|
|
|
|
mobile: 111111111,
|
|
|
|
phone: 2222222222
|
|
|
|
},
|
|
|
|
tracking: {
|
|
|
|
state: {alertLevel: 3}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('ticket'));
|
2018-11-08 14:20:42 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, _$httpBackend_, _$state_) => {
|
2018-11-08 14:20:42 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2020-04-30 10:48:52 +00:00
|
|
|
$httpBackend.whenGET(`Tickets/${ticket.id}/canHaveStowaway`).respond(true);
|
2020-09-02 06:12:32 +00:00
|
|
|
$httpBackend.expect('GET', `Tickets/${ticket.id}/isEditable`).respond(true);
|
2018-11-08 14:20:42 +00:00
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
$state = _$state_;
|
2020-06-17 07:49:14 +00:00
|
|
|
$state.params.id = 1;
|
2020-04-30 10:48:52 +00:00
|
|
|
$state.getCurrentPath = () => [null, {state: {name: 'ticket'}}];
|
2018-11-08 14:20:42 +00:00
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
controller = $componentController('vnTicketDescriptor', {$element: null}, {ticket});
|
|
|
|
}));
|
2018-11-08 14:20:42 +00:00
|
|
|
|
2019-09-06 07:47:58 +00:00
|
|
|
describe('addTurn()', () => {
|
2018-11-08 14:20:42 +00:00
|
|
|
it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => {
|
2019-11-12 07:51:50 +00:00
|
|
|
controller.$.addTurn = {hide: () => {}};
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$.addTurn, 'hide');
|
2018-11-08 14:20:42 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.expectPATCH(`TicketWeeklies`).respond();
|
2018-11-08 14:20:42 +00:00
|
|
|
controller.addTurn(1);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2019-11-12 07:51:50 +00:00
|
|
|
expect(controller.$.addTurn.hide).toHaveBeenCalledWith();
|
2018-11-08 14:20:42 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-09-06 07:47:58 +00:00
|
|
|
describe('deleteTicket()', () => {
|
2020-04-30 10:48:52 +00:00
|
|
|
it('should make a query and call vnApp.showSuccess()', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$state, 'go').mockReturnValue('ok');
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
2018-11-08 14:20:42 +00:00
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
$httpBackend.expectPOST(`Tickets/${ticket.id}/setDeleted`).respond();
|
|
|
|
controller.deleteTicket();
|
2018-11-08 14:20:42 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('ticket.index');
|
2020-04-30 10:48:52 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2018-11-08 14:20:42 +00:00
|
|
|
});
|
|
|
|
});
|
2019-02-11 09:06:26 +00:00
|
|
|
|
2019-02-11 14:01:12 +00:00
|
|
|
describe('showDeliveryNote()', () => {
|
2019-02-11 09:06:26 +00:00
|
|
|
it('should open a new window showing a delivery note PDF document', () => {
|
2020-06-12 12:28:29 +00:00
|
|
|
jest.spyOn(controller.vnReport, 'show');
|
2020-04-30 10:48:52 +00:00
|
|
|
|
2020-06-12 12:28:29 +00:00
|
|
|
window.open = jasmine.createSpy('open');
|
2019-11-06 08:32:54 +00:00
|
|
|
const params = {
|
2020-09-02 11:09:30 +00:00
|
|
|
recipientId: ticket.client.id,
|
2020-04-30 10:48:52 +00:00
|
|
|
ticketId: ticket.id
|
2019-11-06 08:32:54 +00:00
|
|
|
};
|
2019-02-11 09:06:26 +00:00
|
|
|
controller.showDeliveryNote();
|
|
|
|
|
2020-06-12 12:28:29 +00:00
|
|
|
expect(controller.vnReport.show).toHaveBeenCalledWith('delivery-note', params);
|
2019-02-11 09:06:26 +00:00
|
|
|
});
|
|
|
|
});
|
2019-04-12 11:54:31 +00:00
|
|
|
|
2019-11-06 08:32:54 +00:00
|
|
|
describe('sendDeliveryNote()', () => {
|
|
|
|
it('should make a query and call vnApp.showMessage()', () => {
|
2020-06-12 12:28:29 +00:00
|
|
|
jest.spyOn(controller.vnEmail, 'send');
|
2019-11-06 08:32:54 +00:00
|
|
|
|
|
|
|
const params = {
|
2020-04-30 10:48:52 +00:00
|
|
|
recipient: ticket.client.email,
|
2020-09-02 11:09:30 +00:00
|
|
|
recipientId: ticket.client.id,
|
2020-04-30 10:48:52 +00:00
|
|
|
ticketId: ticket.id
|
2019-11-06 08:32:54 +00:00
|
|
|
};
|
|
|
|
controller.sendDeliveryNote();
|
|
|
|
|
2020-06-12 12:28:29 +00:00
|
|
|
expect(controller.vnEmail.send).toHaveBeenCalledWith('delivery-note', params);
|
2019-11-06 08:32:54 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-09-06 07:47:58 +00:00
|
|
|
describe('makeInvoice()', () => {
|
2020-04-30 10:48:52 +00:00
|
|
|
it('should make a query and call $state.reload() method', () => {
|
2020-02-27 06:19:42 +00:00
|
|
|
jest.spyOn(controller.$state, 'reload').mockReturnThis();
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
2019-04-12 11:54:31 +00:00
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
$httpBackend.expectPOST(`Tickets/${ticket.id}/makeInvoice`).respond();
|
|
|
|
controller.makeInvoice();
|
2019-04-12 11:54:31 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2019-04-12 11:54:31 +00:00
|
|
|
expect(controller.$state.reload).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
2019-04-26 06:52:43 +00:00
|
|
|
|
2019-09-06 07:47:58 +00:00
|
|
|
describe('regenerateInvoice()', () => {
|
2020-04-30 10:48:52 +00:00
|
|
|
it('should make a query and show a success snackbar', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
2019-04-26 06:52:43 +00:00
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
$httpBackend.expectPOST(`InvoiceOuts/${ticket.invoiceOut.id}/regenerate`).respond();
|
|
|
|
controller.regenerateInvoice();
|
2019-04-26 06:52:43 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2019-04-26 06:52:43 +00:00
|
|
|
});
|
|
|
|
});
|
2019-04-29 05:48:59 +00:00
|
|
|
|
2019-09-06 07:47:58 +00:00
|
|
|
describe('changeShipped()', () => {
|
2019-10-30 15:57:14 +00:00
|
|
|
it('should make a query and change the shipped hour if the response is accept', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
jest.spyOn(controller, 'cardReload');
|
2019-05-03 10:23:57 +00:00
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
$httpBackend.expectPOST(`Tickets/${ticket.id}/updateEditableTicket`).respond();
|
|
|
|
controller.changeShipped();
|
2019-04-29 05:48:59 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
expect(controller.cardReload).toHaveBeenCalled();
|
2019-09-25 09:26:12 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-09-06 07:47:58 +00:00
|
|
|
describe('canStowaway()', () => {
|
2020-09-02 07:42:10 +00:00
|
|
|
it('should make a query and return if the ticket can be stowawayed', () => {
|
2019-09-06 07:47:58 +00:00
|
|
|
controller.canStowaway();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.canShowStowaway).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not make a query if is not on the ticket module', () => {
|
2020-04-30 10:48:52 +00:00
|
|
|
$state.getCurrentPath = () => [null, {state: {name: 'client'}}];
|
2019-09-06 07:47:58 +00:00
|
|
|
controller.canStowaway();
|
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
expect(controller.canShowStowaway).toBeFalsy();
|
2019-09-06 07:47:58 +00:00
|
|
|
});
|
|
|
|
});
|
2019-11-21 11:00:56 +00:00
|
|
|
|
|
|
|
describe('recalculateComponents()', () => {
|
2020-04-30 10:48:52 +00:00
|
|
|
it('should make a query and show a success message', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
2019-11-21 11:00:56 +00:00
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
$httpBackend.expectPOST(`Tickets/${ticket.id}/recalculateComponents`).respond();
|
2019-11-21 11:00:56 +00:00
|
|
|
controller.recalculateComponents();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2019-11-21 11:00:56 +00:00
|
|
|
});
|
|
|
|
});
|
2020-03-11 07:45:54 +00:00
|
|
|
|
|
|
|
describe('showSMSDialog()', () => {
|
|
|
|
it('should set the destionationFk and destination properties and then call the sms open() method', () => {
|
|
|
|
controller.$.sms = {open: () => {}};
|
|
|
|
jest.spyOn(controller.$.sms, 'open');
|
|
|
|
|
|
|
|
controller.showSMSDialog();
|
|
|
|
|
|
|
|
expect(controller.$.sms.open).toHaveBeenCalledWith();
|
2020-04-30 10:48:52 +00:00
|
|
|
expect(controller.newSMS).toEqual({
|
|
|
|
destinationFk: ticket.clientFk,
|
|
|
|
destination: ticket.address.mobile
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('loadData()', () => {
|
|
|
|
it(`should perform a get query to store the ticket data into the controller`, () => {
|
2020-09-02 11:09:30 +00:00
|
|
|
$httpBackend.when('GET', `Tickets/${ticket.id}/isEditable`).respond();
|
|
|
|
$httpBackend.expectRoute('GET', `Tickets/${ticket.id}`).respond();
|
|
|
|
controller.loadData();
|
2020-04-30 10:48:52 +00:00
|
|
|
$httpBackend.flush();
|
2020-03-11 07:45:54 +00:00
|
|
|
});
|
|
|
|
});
|
2018-11-08 14:20:42 +00:00
|
|
|
});
|