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

227 lines
8.8 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', () => {
2019-11-06 08:32:54 +00:00
let $httpParamSerializer;
2018-11-08 14:20:42 +00:00
let $httpBackend;
let controller;
let $state;
2018-11-08 14:20:42 +00:00
beforeEach(ngModule('ticket'));
2018-11-08 14:20:42 +00:00
beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope, $compile, _$state_, _$httpParamSerializer_) => {
2019-11-12 07:51:50 +00:00
let $element = $compile(`<vn-autocomplete></vn-autocomplete>`)($rootScope);
$state = _$state_;
$state.getCurrentPath = () => {
return [
{state: {}},
{state: {name: 'ticket'}}
];
};
2018-11-08 14:20:42 +00:00
$httpBackend = _$httpBackend_;
2019-11-06 08:32:54 +00:00
$httpParamSerializer = _$httpParamSerializer_;
2019-11-12 07:51:50 +00:00
controller = $componentController('vnTicketDescriptor', {$element});
2019-11-06 08:32:54 +00:00
controller._ticket = {id: 2, invoiceOut: {id: 1}, client: {id: 101, email: 'client@email'}};
controller.cardReload = ()=> {
return true;
};
2018-11-08 14:20:42 +00:00
}));
describe('showAddTurnDialog()', () => {
2019-11-12 07:51:50 +00:00
it('should call controller.$.addTurn.show()', () => {
controller.$.addTurn = {show: () => {}};
spyOn(controller.$.addTurn, 'show');
2018-11-08 14:20:42 +00:00
controller.showAddTurnDialog();
2019-11-12 07:51:50 +00:00
expect(controller.$.addTurn.show).toHaveBeenCalledWith();
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: () => {}};
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('showDeleteTicketDialog()', () => {
it('should call vnApp.showError() if the ticket isnt editable', () => {
controller.ticket.tracking = {state: {alertLevel: 3}};
spyOn(controller.vnApp, 'showError');
controller.showDeleteTicketDialog();
expect(controller.vnApp.showError).toHaveBeenCalledWith('This ticket cant be deleted');
});
it('should call deleteConfirmation.show() if the ticket is editable', () => {
controller.ticket.tracking = {state: {alertLevel: 0}};
2019-11-12 07:51:50 +00:00
controller.$.deleteConfirmation = {show: () => {}};
spyOn(controller.$.deleteConfirmation, 'show');
2018-11-08 14:20:42 +00:00
controller.showDeleteTicketDialog();
2019-11-12 07:51:50 +00:00
expect(controller.$.deleteConfirmation.show).toHaveBeenCalledWith();
2018-11-08 14:20:42 +00:00
});
});
describe('deleteTicket()', () => {
2019-10-30 15:57:14 +00:00
it('should make a query and call vnApp.showSuccess() if the response is accept', () => {
2018-11-08 14:20:42 +00:00
spyOn(controller.$state, 'go');
spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectPOST(`Tickets/2/setDeleted`).respond();
2019-10-30 15:57:14 +00:00
controller.deleteTicket('accept');
2018-11-08 14:20:42 +00:00
$httpBackend.flush();
expect(controller.$state.go).toHaveBeenCalledWith('ticket.index');
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Ticket deleted');
});
});
2019-02-11 14:01:12 +00:00
describe('showDeliveryNote()', () => {
it('should open a new window showing a delivery note PDF document', () => {
2019-11-06 08:32:54 +00:00
const params = {
clientId: controller.ticket.client.id,
ticketId: controller.ticket.id
};
const serializedParams = $httpParamSerializer(params);
let expectedPath = `api/report/delivery-note?${serializedParams}`;
spyOn(window, 'open');
controller.showDeliveryNote();
expect(window.open).toHaveBeenCalledWith(expectedPath);
});
});
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()', () => {
spyOn(controller.vnApp, 'showMessage');
const params = {
recipient: 'client@email',
clientId: controller.ticket.client.id,
ticketId: controller.ticket.id
};
const serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `email/delivery-note?${serializedParams}`).respond();
$httpBackend.expect('GET', `email/delivery-note?${serializedParams}`).respond();
controller.sendDeliveryNote();
$httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Notification sent!');
});
});
describe('makeInvoice()', () => {
2019-10-30 15:57:14 +00:00
it('should make a query and call $state.reload() method if the response is accept', () => {
2019-04-12 11:54:31 +00:00
spyOn(controller.$state, 'reload');
spyOn(controller.vnApp, 'showSuccess');
$httpBackend.when('POST', 'Tickets/2/makeInvoice').respond();
$httpBackend.expect('POST', 'Tickets/2/makeInvoice').respond();
2019-10-30 15:57:14 +00:00
controller.makeInvoice('accept');
2019-04-12 11:54:31 +00:00
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Ticket invoiced');
expect(controller.$state.reload).toHaveBeenCalledWith();
});
});
2019-04-26 06:52:43 +00:00
describe('regenerateInvoice()', () => {
2019-10-30 15:57:14 +00:00
it('should make a query and show a success snackbar if the response is accept', () => {
2019-04-26 06:52:43 +00:00
spyOn(controller.vnApp, 'showSuccess');
$httpBackend.when('POST', 'InvoiceOuts/1/regenerate').respond();
$httpBackend.expect('POST', 'InvoiceOuts/1/regenerate').respond();
2019-10-30 15:57:14 +00:00
controller.regenerateInvoice('accept');
2019-04-26 06:52:43 +00:00
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Invoice sent for a regeneration, will be available in a few minutes');
});
});
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', () => {
controller.ticket.id = 12;
spyOn(controller.vnApp, 'showSuccess');
spyOn(controller, 'cardReload');
$httpBackend.when('POST', 'Tickets/12/updateEditableTicket').respond();
$httpBackend.expect('POST', 'Tickets/12/updateEditableTicket').respond();
2019-10-30 15:57:14 +00:00
controller.changeShipped('accept');
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Shipped hour updated');
expect(controller.cardReload).toHaveBeenCalledWith();
});
});
2019-09-25 09:26:12 +00:00
describe('showAddStowaway()', () => {
it('should show a dialog with a list of tickets available for an stowaway', () => {
2019-11-12 07:51:50 +00:00
controller.$.addStowaway = {};
controller.$.addStowaway.show = jasmine.createSpy('show');
2019-09-25 09:26:12 +00:00
controller.showAddStowaway();
2019-11-12 07:51:50 +00:00
expect(controller.$.addStowaway.show).toHaveBeenCalledWith();
2019-09-25 09:26:12 +00:00
});
});
describe('showRemoveStowaway()', () => {
it('should show a dialog for an stowaway removal', () => {
2019-11-12 07:51:50 +00:00
controller.$.removeStowaway = {};
controller.$.removeStowaway.show = jasmine.createSpy('show');
2019-09-25 09:26:12 +00:00
controller.showRemoveStowaway();
2019-11-12 07:51:50 +00:00
expect(controller.$.removeStowaway.show).toHaveBeenCalledWith();
2019-09-25 09:26:12 +00:00
});
});
describe('canStowaway()', () => {
it('should make a query and return if the ticket can be stowawayed', () => {
controller.ticket.id = 16;
spyOn(controller, 'isTicketModule').and.callThrough();
$httpBackend.when('GET', 'Tickets/16/canHaveStowaway').respond(true);
$httpBackend.expect('GET', 'Tickets/16/canHaveStowaway').respond(true);
controller.canStowaway();
$httpBackend.flush();
expect(controller.canShowStowaway).toBeTruthy();
expect(controller.isTicketModule).toHaveBeenCalledWith();
});
it('should not make a query if is not on the ticket module', () => {
controller.ticket.id = 16;
$state.getCurrentPath = () => {
return [
{state: {}},
{state: {name: 'client'}}
];
};
spyOn(controller, 'isTicketModule').and.callThrough();
controller.canStowaway();
expect(controller.canShowStowaway).toBeUndefined();
expect(controller.isTicketModule).toHaveBeenCalledWith();
});
});
2019-11-21 11:00:56 +00:00
describe('recalculateComponents()', () => {
it('should make a query and show a success snackbar', () => {
spyOn(controller.vnApp, 'showSuccess');
$httpBackend.when('POST', 'Tickets/2/recalculateComponents').respond();
$httpBackend.expect('POST', 'Tickets/2/recalculateComponents').respond();
controller.recalculateComponents();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
2018-11-08 14:20:42 +00:00
});