226 lines
7.7 KiB
JavaScript
226 lines
7.7 KiB
JavaScript
import './index.js';
|
|
|
|
describe('Ticket Component vnTicketDescriptor', () => {
|
|
let $httpBackend;
|
|
let controller;
|
|
let $state;
|
|
|
|
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'));
|
|
|
|
beforeEach(inject(($componentController, _$httpBackend_, _$state_) => {
|
|
$httpBackend = _$httpBackend_;
|
|
$httpBackend.whenGET(`Tickets/${ticket.id}/canHaveStowaway`).respond(true);
|
|
$httpBackend.expect('GET', `Tickets/${ticket.id}/isEditable`).respond(true);
|
|
|
|
$state = _$state_;
|
|
$state.params.id = 1;
|
|
$state.getCurrentPath = () => [null, {state: {name: 'ticket'}}];
|
|
|
|
controller = $componentController('vnTicketDescriptor', {$element: null}, {ticket});
|
|
}));
|
|
|
|
describe('canRestoreTicket() getter', () => {
|
|
it('should return true for a ticket deleted within the last hour', () => {
|
|
controller.ticket.isDeleted = true;
|
|
controller.ticket.updated = new Date();
|
|
|
|
const result = controller.canRestoreTicket;
|
|
|
|
expect(result).toBeTruthy();
|
|
});
|
|
|
|
it('should return false for a ticket deleted more than one hour ago', () => {
|
|
const pastHour = new Date();
|
|
pastHour.setHours(pastHour.getHours() - 2);
|
|
|
|
controller.ticket.isDeleted = true;
|
|
controller.ticket.updated = pastHour;
|
|
|
|
const result = controller.canRestoreTicket;
|
|
|
|
expect(result).toBeFalsy();
|
|
});
|
|
});
|
|
|
|
describe('addTurn()', () => {
|
|
it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => {
|
|
controller.$.addTurn = {hide: () => {}};
|
|
jest.spyOn(controller.$.addTurn, 'hide');
|
|
|
|
$httpBackend.expectPATCH(`TicketWeeklies`).respond();
|
|
controller.addTurn(1);
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.$.addTurn.hide).toHaveBeenCalledWith();
|
|
});
|
|
});
|
|
|
|
describe('deleteTicket()', () => {
|
|
it('should make a query and call vnApp.showSuccess()', () => {
|
|
jest.spyOn(controller.$state, 'go').mockReturnValue('ok');
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
$httpBackend.expectPOST(`Tickets/${ticket.id}/setDeleted`).respond();
|
|
controller.deleteTicket();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('ticket.index');
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe('restoreTicket()', () => {
|
|
it('should make a query to restore the ticket and call vnApp.showSuccess()', () => {
|
|
jest.spyOn(controller, 'cardReload');
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
$httpBackend.expectPOST(`Tickets/${ticket.id}/restore`).respond();
|
|
controller.restoreTicket();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.cardReload).toHaveBeenCalled();
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe('showDeliveryNote()', () => {
|
|
it('should open a new window showing a delivery note PDF document', () => {
|
|
jest.spyOn(controller.vnReport, 'show');
|
|
|
|
window.open = jasmine.createSpy('open');
|
|
const params = {
|
|
recipientId: ticket.client.id,
|
|
ticketId: ticket.id
|
|
};
|
|
controller.showDeliveryNote();
|
|
|
|
expect(controller.vnReport.show).toHaveBeenCalledWith('delivery-note', params);
|
|
});
|
|
});
|
|
|
|
describe('sendDeliveryNote()', () => {
|
|
it('should make a query and call vnApp.showMessage()', () => {
|
|
jest.spyOn(controller.vnEmail, 'send');
|
|
|
|
const params = {
|
|
recipient: ticket.client.email,
|
|
recipientId: ticket.client.id,
|
|
ticketId: ticket.id
|
|
};
|
|
controller.sendDeliveryNote();
|
|
|
|
expect(controller.vnEmail.send).toHaveBeenCalledWith('delivery-note', params);
|
|
});
|
|
});
|
|
|
|
describe('makeInvoice()', () => {
|
|
it('should make a query and call $state.reload() method', () => {
|
|
jest.spyOn(controller.$state, 'reload').mockReturnThis();
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
$httpBackend.expectPOST(`Tickets/${ticket.id}/makeInvoice`).respond();
|
|
controller.makeInvoice();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
expect(controller.$state.reload).toHaveBeenCalledWith();
|
|
});
|
|
});
|
|
|
|
describe('regenerateInvoice()', () => {
|
|
it('should make a query and show a success snackbar', () => {
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
$httpBackend.expectPOST(`InvoiceOuts/${ticket.invoiceOut.id}/regenerate`).respond();
|
|
controller.regenerateInvoice();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe('changeShipped()', () => {
|
|
it('should make a query and change the shipped hour if the response is accept', () => {
|
|
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();
|
|
});
|
|
});
|
|
|
|
describe('canStowaway()', () => {
|
|
it('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();
|
|
});
|
|
});
|
|
|
|
describe('recalculateComponents()', () => {
|
|
it('should make a query and show a success message', () => {
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
$httpBackend.expectPOST(`Tickets/${ticket.id}/recalculateComponents`).respond();
|
|
controller.recalculateComponents();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
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`, () => {
|
|
$httpBackend.when('GET', `Tickets/${ticket.id}/isEditable`).respond();
|
|
$httpBackend.expectRoute('GET', `Tickets/${ticket.id}`).respond();
|
|
controller.loadData();
|
|
$httpBackend.flush();
|
|
});
|
|
});
|
|
});
|