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

188 lines
7.3 KiB
JavaScript
Raw Normal View History

2018-11-08 14:20:42 +00:00
import './index.js';
2019-02-12 13:40:13 +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
2019-09-13 14:09:14 +00:00
beforeEach(angular.mock.module('ticket', $translateProvider => {
$translateProvider.translations('en', {});
}));
2018-11-08 14:20:42 +00:00
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => {
$state = _$state_;
$state.getCurrentPath = () => {
return [
{state: {}},
{state: {name: 'ticket'}}
];
};
2018-11-08 14:20:42 +00:00
$httpBackend = _$httpBackend_;
controller = $componentController('vnTicketDescriptor', {$state});
controller._ticket = {id: 2, invoiceOut: {id: 1}};
controller.cardReload = ()=> {
return true;
};
2018-11-08 14:20:42 +00:00
}));
describe('showAddTurnDialog()', () => {
it('should call contrtoller.$scope.addTurn.show()', () => {
controller.$scope.addTurn = {show: () => {}};
spyOn(controller.$scope.addTurn, 'show');
controller.showAddTurnDialog();
expect(controller.$scope.addTurn.show).toHaveBeenCalledWith();
});
});
describe('addTurn()', () => {
2018-11-08 14:20:42 +00:00
it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => {
controller.$scope.addTurn = {hide: () => {}};
spyOn(controller.$scope.addTurn, 'hide');
$httpBackend.expectPATCH(`/ticket/api/TicketWeeklies`).respond();
controller.addTurn(1);
$httpBackend.flush();
expect(controller.$scope.addTurn.hide).toHaveBeenCalledWith();
});
});
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}};
controller.$scope.deleteConfirmation = {show: () => {}};
spyOn(controller.$scope.deleteConfirmation, 'show');
controller.showDeleteTicketDialog();
expect(controller.$scope.deleteConfirmation.show).toHaveBeenCalledWith();
});
});
describe('deleteTicket()', () => {
2018-11-08 14:20:42 +00:00
it('should make a query and call vnApp.showSuccess() if the response is ACCEPT', () => {
spyOn(controller.$state, 'go');
spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectPOST(`/api/Tickets/2/setDeleted`).respond();
2018-11-08 14:20:42 +00:00
controller.deleteTicket('ACCEPT');
$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', () => {
let expectedPath = '/api/report/rpt-delivery-note?ticketFk=2';
spyOn(window, 'open');
controller.showDeliveryNote();
expect(window.open).toHaveBeenCalledWith(expectedPath);
});
});
2019-04-12 11:54:31 +00:00
describe('makeInvoice()', () => {
2019-04-12 11:54:31 +00:00
it('should make a query and call $state.reload() method if the response is ACCEPT', () => {
spyOn(controller.$state, 'reload');
spyOn(controller.vnApp, 'showSuccess');
$httpBackend.when('POST', '/ticket/api/Tickets/2/makeInvoice').respond();
$httpBackend.expect('POST', '/ticket/api/Tickets/2/makeInvoice').respond();
2019-04-26 06:52:43 +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-04-26 06:52:43 +00:00
it('should make a query and show a success snackbar if the response is ACCEPT', () => {
spyOn(controller.vnApp, 'showSuccess');
$httpBackend.when('POST', '/invoiceOut/api/InvoiceOuts/1/regenerate').respond();
$httpBackend.expect('POST', '/invoiceOut/api/InvoiceOuts/1/regenerate').respond();
2019-04-26 06:52:43 +00:00
controller.regenerateInvoice('ACCEPT');
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Invoice sent for a regeneration, will be available in a few minutes');
});
});
describe('changeShipped()', () => {
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', '/ticket/api/Tickets/12/updateEditableTicket').respond();
$httpBackend.expect('POST', '/ticket/api/Tickets/12/updateEditableTicket').respond();
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', () => {
controller.$scope.addStowaway = {};
controller.$scope.addStowaway.show = jasmine.createSpy('show');
controller.showAddStowaway();
expect(controller.$scope.addStowaway.show).toHaveBeenCalledWith();
});
});
describe('showRemoveStowaway()', () => {
it('should show a dialog for an stowaway removal', () => {
controller.$scope.removeStowaway = {};
controller.$scope.removeStowaway.show = jasmine.createSpy('show');
controller.showRemoveStowaway();
expect(controller.$scope.removeStowaway.show).toHaveBeenCalledWith();
});
});
describe('canStowaway()', () => {
it('should make a query and return if the ticket can be stowawayed', () => {
controller.ticket.id = 16;
spyOn(controller, 'isTicketModule').and.callThrough();
2019-09-25 09:26:12 +00:00
$httpBackend.when('GET', '/api/Tickets/16/canHaveStowaway').respond(true);
$httpBackend.expect('GET', '/api/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();
});
});
2018-11-08 14:20:42 +00:00
});