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-04-30 10:48:52 +00:00
|
|
|
beforeEach(angular.mock.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);
|
2018-11-08 14:20:42 +00:00
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
$state = _$state_;
|
|
|
|
$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-04-30 10:48:52 +00:00
|
|
|
jest.spyOn(controller, 'showReport');
|
|
|
|
|
2019-11-06 08:32:54 +00:00
|
|
|
const params = {
|
2020-04-30 10:48:52 +00:00
|
|
|
clientId: ticket.client.id,
|
|
|
|
ticketId: ticket.id
|
2019-11-06 08:32:54 +00:00
|
|
|
};
|
2019-02-11 09:06:26 +00:00
|
|
|
controller.showDeliveryNote();
|
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
expect(controller.showReport).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-04-30 10:48:52 +00:00
|
|
|
jest.spyOn(controller, 'sendEmail');
|
2019-11-06 08:32:54 +00:00
|
|
|
|
|
|
|
const params = {
|
2020-04-30 10:48:52 +00:00
|
|
|
recipient: ticket.client.email,
|
|
|
|
clientId: ticket.client.id,
|
|
|
|
ticketId: ticket.id
|
2019-11-06 08:32:54 +00:00
|
|
|
};
|
|
|
|
controller.sendDeliveryNote();
|
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
expect(controller.sendEmail).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-04-30 10:48:52 +00:00
|
|
|
fit('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`, () => {
|
|
|
|
controller.ticket = null;
|
|
|
|
|
|
|
|
$httpBackend.expectRoute('GET', `Tickets/${ticket.id}`).respond(ticket);
|
|
|
|
controller.id = ticket.id;
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.ticket).toEqual(ticket);
|
2020-03-11 07:45:54 +00:00
|
|
|
});
|
|
|
|
});
|
2018-11-08 14:20:42 +00:00
|
|
|
});
|