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;
|
|
|
|
|
2019-02-12 13:40:13 +00:00
|
|
|
beforeEach(ngModule('ticket'));
|
2018-11-08 14:20:42 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => {
|
2018-11-08 14:20:42 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
controller = $componentController('vnTicketDescriptor');
|
|
|
|
controller.ticket = {id: 2};
|
|
|
|
}));
|
|
|
|
|
|
|
|
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(day)', () => {
|
|
|
|
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(response)', () => {
|
|
|
|
it('should make a query and call vnApp.showSuccess() if the response is ACCEPT', () => {
|
|
|
|
spyOn(controller.$state, 'go');
|
|
|
|
spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
|
|
|
|
$httpBackend.expectPOST(`/ticket/api/Tickets/deleted`, {id: 2}).respond();
|
|
|
|
controller.deleteTicket('ACCEPT');
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('ticket.index');
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Ticket deleted');
|
|
|
|
});
|
|
|
|
});
|
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', () => {
|
|
|
|
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('invoiceMakeOut(response)', () => {
|
|
|
|
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-23 07:08:28 +00:00
|
|
|
controller.makeInvoiceOut('ACCEPT');
|
2019-04-12 11:54:31 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Ticket invoiced');
|
|
|
|
expect(controller.$state.reload).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
2018-11-08 14:20:42 +00:00
|
|
|
});
|
|
|
|
|