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

192 lines
6.4 KiB
JavaScript
Raw Normal View History

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;
let $state;
2018-11-08 14:20:42 +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}
}
};
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_;
$httpBackend.whenGET(`Tickets/${ticket.id}/canHaveStowaway`).respond(true);
2020-06-17 07:49:14 +00:00
$httpBackend.whenGET(`Tickets/1/isEditable`).respond(true);
2018-11-08 14:20:42 +00:00
$state = _$state_;
2020-06-17 07:49:14 +00:00
$state.params.id = 1;
$state.getCurrentPath = () => [null, {state: {name: 'ticket'}}];
2018-11-08 14:20:42 +00:00
controller = $componentController('vnTicketDescriptor', {$element: null}, {ticket});
}));
2018-11-08 14:20:42 +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
$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
});
});
describe('deleteTicket()', () => {
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
$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');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
2018-11-08 14:20:42 +00:00
});
});
2019-02-11 14:01:12 +00:00
describe('showDeliveryNote()', () => {
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-06-12 12:28:29 +00:00
window.open = jasmine.createSpy('open');
2019-11-06 08:32:54 +00:00
const params = {
clientId: ticket.client.id,
ticketId: ticket.id
2019-11-06 08:32:54 +00:00
};
controller.showDeliveryNote();
2020-06-12 12:28:29 +00:00
expect(controller.vnReport.show).toHaveBeenCalledWith('delivery-note', params);
});
});
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 = {
recipient: ticket.client.email,
clientId: ticket.client.id,
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
});
});
describe('makeInvoice()', () => {
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
$httpBackend.expectPOST(`Tickets/${ticket.id}/makeInvoice`).respond();
controller.makeInvoice();
2019-04-12 11:54:31 +00:00
$httpBackend.flush();
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
describe('regenerateInvoice()', () => {
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
$httpBackend.expectPOST(`InvoiceOuts/${ticket.invoiceOut.id}/regenerate`).respond();
controller.regenerateInvoice();
2019-04-26 06:52:43 +00:00
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
2019-04-26 06:52:43 +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');
$httpBackend.expectPOST(`Tickets/${ticket.id}/updateEditableTicket`).respond();
controller.changeShipped();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.cardReload).toHaveBeenCalled();
2019-09-25 09:26:12 +00:00
});
});
describe('canStowaway()', () => {
fit('should make a query and return if the ticket can be stowawayed', () => {
controller.canStowaway();
$httpBackend.flush();
expect(controller.canShowStowaway).toBeTruthy();
});
it('should not make a query if is not on the ticket module', () => {
$state.getCurrentPath = () => [null, {state: {name: 'client'}}];
controller.canStowaway();
expect(controller.canShowStowaway).toBeFalsy();
});
});
2019-11-21 11:00:56 +00:00
describe('recalculateComponents()', () => {
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
$httpBackend.expectPOST(`Tickets/${ticket.id}/recalculateComponents`).respond();
2019-11-21 11:00:56 +00:00
controller.recalculateComponents();
$httpBackend.flush();
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();
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
});