Updated unit tests
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
82c739eab2
commit
a93d9f91cc
|
@ -25,7 +25,12 @@ class Controller extends Section {
|
|||
set id(value) {
|
||||
this._id = value;
|
||||
|
||||
if (value) this.loadData();
|
||||
if (!value) return;
|
||||
|
||||
this.loadData().then(() => {
|
||||
if (this.$params.sendSMS)
|
||||
this.showSMSDialog();
|
||||
});
|
||||
}
|
||||
|
||||
loadData() {
|
||||
|
@ -67,8 +72,10 @@ class Controller extends Section {
|
|||
}
|
||||
|
||||
reload() {
|
||||
return this.loadData().then(
|
||||
() => this.cardReload());
|
||||
return this.loadData().then(() => {
|
||||
if (this.parentReload)
|
||||
this.parentReload();
|
||||
});
|
||||
}
|
||||
|
||||
get isInvoiced() {
|
||||
|
@ -235,6 +242,6 @@ ngModule.vnComponent('vnTicketDescriptorMenu', {
|
|||
controller: Controller,
|
||||
bindings: {
|
||||
ticketId: '<',
|
||||
reload: '&'
|
||||
parentReload: '&'
|
||||
}
|
||||
});
|
||||
|
|
|
@ -0,0 +1,223 @@
|
|||
import './index.js';
|
||||
|
||||
describe('Ticket Component vnTicketDescriptorMenu', () => {
|
||||
let $httpBackend;
|
||||
let controller;
|
||||
let $state;
|
||||
|
||||
const ticket = {
|
||||
id: 16,
|
||||
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_;
|
||||
$state = _$state_;
|
||||
$state.params.id = 16;
|
||||
$state.getCurrentPath = () => [null, {state: {name: 'ticket'}}];
|
||||
|
||||
const $element = angular.element('<vn-ticket-descriptor-menu></vn-ticket-descriptor-menu>');
|
||||
controller = $componentController('vnTicketDescriptorMenu', {$element});
|
||||
controller._ticketId = ticket.id;
|
||||
controller._id = ticket.id;
|
||||
controller.ticket = 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, 'reload').mockReturnThis();
|
||||
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.reload).toHaveBeenCalled();
|
||||
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, 'reload').mockReturnThis();
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
|
||||
$httpBackend.expectPOST(`Tickets/${ticket.id}/restore`).respond();
|
||||
controller.restoreTicket();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.reload).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, 'reload').mockReturnThis();
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
|
||||
$httpBackend.expectPOST(`Tickets/${ticket.id}/makeInvoice`).respond();
|
||||
controller.makeInvoice();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.reload).toHaveBeenCalledWith();
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
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, 'reload').mockReturnThis();
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
|
||||
$httpBackend.expectPOST(`Tickets/${ticket.id}/updateEditableTicket`).respond();
|
||||
controller.changeShipped();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.reload).toHaveBeenCalled();
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('canStowaway()', () => {
|
||||
it('should make a query and return if the ticket can be stowawayed', () => {
|
||||
$httpBackend.expect('GET', `Tickets/${ticket.id}/canHaveStowaway`).respond(true);
|
||||
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, 'reload').mockReturnThis();
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
|
||||
$httpBackend.expect('POST', `Tickets/${ticket.id}/recalculateComponents`).respond();
|
||||
controller.recalculateComponents();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.reload).toHaveBeenCalled();
|
||||
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,
|
||||
ticketId: 16
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -2,7 +2,7 @@
|
|||
module="ticket"
|
||||
description="$ctrl.ticket.client.name">
|
||||
<slot-dot-menu>
|
||||
<vn-ticket-descriptor-menu ticket-id="$ctrl.ticket.id" reload="$ctrl.cardReload()"/>
|
||||
<vn-ticket-descriptor-menu ticket-id="$ctrl.ticket.id" parent-reload="$ctrl.cardReload()"/>
|
||||
</slot-dot-menu>
|
||||
<slot-body>
|
||||
<div class="attributes">
|
||||
|
@ -112,85 +112,8 @@
|
|||
vn-tooltip="Ship stowaways"
|
||||
tooltip-position="up"
|
||||
data="$ctrl.ticket.ship"
|
||||
on-change="$ctrl.goToTicket(value)">
|
||||
ui-sref="ticket.card.sale({id: value})">
|
||||
</vn-button-menu>
|
||||
</div>
|
||||
</slot-body>
|
||||
</vn-descriptor-content>
|
||||
|
||||
<!-- <vn-confirm
|
||||
vn-id="deleteConfirmation"
|
||||
on-accept="$ctrl.deleteTicket()"
|
||||
question="You are going to delete this ticket"
|
||||
message="This ticket will be removed from current route! Continue anyway?">
|
||||
</vn-confirm> -->
|
||||
<!-- <vn-confirm
|
||||
vn-id="restoreConfirmation"
|
||||
on-accept="$ctrl.restoreTicket()"
|
||||
question="You are going to restore this ticket"
|
||||
message="Are you sure you want to restore this ticket?">
|
||||
</vn-confirm> -->
|
||||
<!-- <vn-confirm
|
||||
vn-id="deleteStowaway"
|
||||
on-accept="$ctrl.deleteStowaway()"
|
||||
question="Delete stowaway"
|
||||
message="Are you sure you want to delete this stowaway?">
|
||||
</vn-confirm> -->
|
||||
<vn-confirm
|
||||
vn-id="confirmDialog"
|
||||
on-accept="$ctrl.returnDialog()"
|
||||
question="Pickup order"
|
||||
message="Do you want to send it directly?">
|
||||
</vn-confirm>
|
||||
<!-- <vn-confirm
|
||||
vn-id="makeInvoiceConfirmation"
|
||||
on-accept="$ctrl.makeInvoice()"
|
||||
question="You are going to invoice this ticket"
|
||||
message="Are you sure you want to invoice this ticket?">
|
||||
</vn-confirm>
|
||||
<vn-confirm
|
||||
vn-id="regenerateInvoiceConfirmation"
|
||||
on-accept="$ctrl.regenerateInvoice()"
|
||||
question="You are going to regenerate the invoice"
|
||||
message="Are you sure you want to regenerate the invoice?">
|
||||
</vn-confirm> -->
|
||||
<!-- <vn-confirm
|
||||
vn-id="confirmDeliveryNote"
|
||||
on-accept="$ctrl.sendDeliveryNote()"
|
||||
question="Are you sure you want to send it?"
|
||||
message="Send Delivery Note">
|
||||
</vn-confirm> -->
|
||||
<!-- <vn-confirm
|
||||
vn-id="recalculateComponentsConfirmation"
|
||||
on-accept="$ctrl.recalculateComponents()"
|
||||
question="Are you sure you want to recalculate the components?"
|
||||
message="Recalculate components">
|
||||
</vn-confirm> -->
|
||||
<!-- <vn-ticket-sms
|
||||
vn-id="sms"
|
||||
sms="$ctrl.newSMS">
|
||||
</vn-ticket-sms> -->
|
||||
<!-- <vn-add-stowaway
|
||||
vn-id="addStowaway"
|
||||
card-reload="$ctrl.cardReload()"
|
||||
ticket="$ctrl.ticket">
|
||||
</vn-add-stowaway> -->
|
||||
<!-- <vn-dialog
|
||||
vn-id="changeShippedDialog"
|
||||
on-accept="$ctrl.changeShipped()"
|
||||
message="Change shipped hour">
|
||||
<tpl-body>
|
||||
<vn-input-time
|
||||
ng-model="$ctrl.newShipped"
|
||||
label="Shipped hour"
|
||||
vn-focus>
|
||||
</vn-input-time>
|
||||
</tpl-body>
|
||||
<tpl-buttons>
|
||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||
<button response="accept" translate>Save</button>
|
||||
</tpl-buttons>
|
||||
</vn-dialog>
|
||||
<vn-worker-descriptor-popover
|
||||
vn-id="workerDescriptor">
|
||||
</vn-worker-descriptor-popover> -->
|
||||
</vn-descriptor-content>
|
|
@ -16,185 +16,6 @@ class Controller extends Descriptor {
|
|||
|
||||
set entity(value) {
|
||||
super.entity = value;
|
||||
// this.canStowaway();
|
||||
this.isTicketEditable();
|
||||
|
||||
if (value && this.$params.sendSMS)
|
||||
this.showSMSDialog();
|
||||
}
|
||||
|
||||
get isInvoiced() {
|
||||
return this.ticket.refFk !== null;
|
||||
}
|
||||
|
||||
get isTicketModule() {
|
||||
return this.$state.getCurrentPath()[1].state.name === 'ticket';
|
||||
}
|
||||
|
||||
get shouldShowDeleteStowaway() {
|
||||
if (!this.ticket || !this.isTicketModule)
|
||||
return false;
|
||||
|
||||
return this.ticket.stowaway || this.ticket.ship;
|
||||
}
|
||||
|
||||
get filter() {
|
||||
if (this.ticket)
|
||||
return JSON.stringify({clientFk: this.ticket.clientFk});
|
||||
return null;
|
||||
}
|
||||
|
||||
/* get canRestoreTicket() {
|
||||
const isDeleted = this.ticket.isDeleted;
|
||||
const now = new Date();
|
||||
const maxDate = new Date(this.ticket.updated);
|
||||
maxDate.setHours(maxDate.getHours() + 1);
|
||||
|
||||
return isDeleted && (now <= maxDate);
|
||||
} */
|
||||
|
||||
isTicketEditable() {
|
||||
if (!this.ticket) return;
|
||||
this.$http.get(`Tickets/${this.id}/isEditable`).then(res => {
|
||||
this.isEditable = res.data;
|
||||
});
|
||||
}
|
||||
|
||||
/* showChangeShipped() {
|
||||
this.newShipped = this.ticket.shipped;
|
||||
this.$.changeShippedDialog.show();
|
||||
}
|
||||
|
||||
changeShipped() {
|
||||
let data = {
|
||||
shipped: this.newShipped
|
||||
};
|
||||
return this.$http.post(`Tickets/${this.id}/updateEditableTicket`, data)
|
||||
.then(() => this.cardReload())
|
||||
.then(() => this.vnApp.showSuccess(this.$t('Shipped hour updated')));
|
||||
} */
|
||||
|
||||
goToTicket(ticketId) {
|
||||
this.$state.go('ticket.card.sale', {id: ticketId}, {absolute: true});
|
||||
}
|
||||
|
||||
/* addTurn(day) {
|
||||
let params = {
|
||||
ticketFk: this.id,
|
||||
weekDay: day,
|
||||
agencyModeFk: this.ticket.agencyModeFk
|
||||
};
|
||||
return this.$http.patch(`TicketWeeklies`, params)
|
||||
.then(() => {
|
||||
this.$.addTurn.hide();
|
||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||
});
|
||||
}
|
||||
|
||||
deleteTicket() {
|
||||
return this.$http.post(`Tickets/${this.id}/setDeleted`)
|
||||
.then(() => {
|
||||
this.$state.go('ticket.index');
|
||||
this.vnApp.showSuccess(this.$t('Ticket deleted. You can undo this action within the first hour'));
|
||||
});
|
||||
}
|
||||
|
||||
restoreTicket() {
|
||||
return this.$http.post(`Tickets/${this.id}/restore`)
|
||||
.then(() => {
|
||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||
this.cardReload();
|
||||
});
|
||||
} */
|
||||
|
||||
/* canStowaway() {
|
||||
this.canShowStowaway = false;
|
||||
if (!this.isTicketModule || !this.ticket) return;
|
||||
|
||||
this.$http.get(`Tickets/${this.id}/canHaveStowaway`)
|
||||
.then(res => this.canShowStowaway = !!res.data);
|
||||
} */
|
||||
|
||||
/* deleteStowaway() {
|
||||
return this.$http.post(`Tickets/${this.id}/deleteStowaway`)
|
||||
.then(() => {
|
||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||
this.cardReload();
|
||||
});
|
||||
} */
|
||||
|
||||
/* showDeliveryNote() {
|
||||
this.vnReport.show('delivery-note', {
|
||||
recipientId: this.ticket.client.id,
|
||||
ticketId: this.id,
|
||||
});
|
||||
}
|
||||
|
||||
sendDeliveryNote() {
|
||||
return this.vnEmail.send('delivery-note', {
|
||||
recipientId: this.ticket.client.id,
|
||||
recipient: this.ticket.client.email,
|
||||
ticketId: this.id
|
||||
});
|
||||
}
|
||||
|
||||
sendImportSms() {
|
||||
const params = {
|
||||
ticketId: this.id,
|
||||
created: this.ticket.updated
|
||||
};
|
||||
this.showSMSDialog({
|
||||
message: this.$params.message || this.$t('Minimum is needed', params)
|
||||
});
|
||||
}
|
||||
|
||||
sendPaymentSms() {
|
||||
this.showSMSDialog({
|
||||
message: this.$params.message || this.$t('Make a payment')
|
||||
});
|
||||
}
|
||||
|
||||
showSMSDialog(params) {
|
||||
const address = this.ticket.address;
|
||||
const client = this.ticket.client;
|
||||
const phone = this.$params.phone
|
||||
|| address.mobile
|
||||
|| address.phone
|
||||
|| client.mobile
|
||||
|| client.phone;
|
||||
|
||||
this.newSMS = Object.assign({
|
||||
destinationFk: this.ticket.clientFk,
|
||||
destination: phone
|
||||
}, params);
|
||||
this.$.sms.open();
|
||||
} */
|
||||
|
||||
/* makeInvoice() {
|
||||
return this.$http.post(`Tickets/${this.id}/makeInvoice`)
|
||||
.then(() => {
|
||||
this.vnApp.showSuccess(this.$t('Ticket invoiced'));
|
||||
this.$state.reload();
|
||||
});
|
||||
}
|
||||
|
||||
regenerateInvoice() {
|
||||
const invoiceId = this.ticket.invoiceOut.id;
|
||||
return this.$http.post(`InvoiceOuts/${invoiceId}/regenerate`)
|
||||
.then(() => {
|
||||
const snackbarMessage = this.$t(
|
||||
`Invoice sent for a regeneration, will be available in a few minutes`);
|
||||
this.vnApp.showSuccess(snackbarMessage);
|
||||
});
|
||||
} */
|
||||
|
||||
/* recalculateComponents() {
|
||||
return this.$http.post(`Tickets/${this.id}/recalculateComponents`)
|
||||
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
|
||||
} */
|
||||
|
||||
cardReload() {
|
||||
// Prevents error when not defined
|
||||
}
|
||||
|
||||
loadData() {
|
||||
|
@ -243,6 +64,15 @@ class Controller extends Descriptor {
|
|||
return this.getData(`Tickets/${this.id}`, {filter})
|
||||
.then(res => this.entity = res.data);
|
||||
}
|
||||
|
||||
cardReload() {
|
||||
// Prevents error when not defined
|
||||
}
|
||||
|
||||
get filter() {
|
||||
return this.ticket ?
|
||||
JSON.stringify({clientFk: this.ticket.clientFk}) : null;
|
||||
}
|
||||
}
|
||||
|
||||
ngModule.vnComponent('vnTicketDescriptor', {
|
||||
|
|
|
@ -27,197 +27,22 @@ describe('Ticket Component vnTicketDescriptor', () => {
|
|||
|
||||
beforeEach(inject(($componentController, _$httpBackend_, _$state_) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpBackend.whenGET(`Tickets/${ticket.id}/canHaveStowaway`).respond(true);
|
||||
$httpBackend.expect('GET', `Tickets/${ticket.id}/isEditable`).respond(true);
|
||||
// $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'}}];
|
||||
// $state.getCurrentPath = () => [null, {state: {name: 'ticket'}}];
|
||||
|
||||
controller = $componentController('vnTicketDescriptor', {$element: null}, {ticket});
|
||||
const $element = angular.element('<vn-ticket-descriptor></vn-ticket-descriptor>');
|
||||
controller = $componentController('vnTicketDescriptor', {$element});
|
||||
controller.ticket = 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();
|
||||
// $httpBackend.when('GET', `Tickets/${ticket.id}/isEditable`).respond();
|
||||
$httpBackend.expect('GET', `Tickets/${ticket.id}`).respond();
|
||||
controller.loadData();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
|
|
@ -12,7 +12,6 @@ describe('Ticket', () => {
|
|||
let $scope = $rootScope.$new();
|
||||
const $element = angular.element('<vn-dialog></vn-dialog>');
|
||||
controller = $componentController('vnTicketSms', {$element, $scope});
|
||||
controller.$params = {id: 11};
|
||||
controller.$.message = {
|
||||
input: {
|
||||
value: 'My SMS'
|
||||
|
@ -22,8 +21,8 @@ describe('Ticket', () => {
|
|||
|
||||
describe('onResponse()', () => {
|
||||
it('should perform a POST query and show a success snackbar', () => {
|
||||
let params = {destinationFk: 101, destination: 111111111, message: 'My SMS'};
|
||||
controller.sms = {destinationFk: 101, destination: 111111111, message: 'My SMS'};
|
||||
let params = {ticketId: 11, destinationFk: 101, destination: 111111111, message: 'My SMS'};
|
||||
controller.sms = {ticketId: 11, destinationFk: 101, destination: 111111111, message: 'My SMS'};
|
||||
|
||||
jest.spyOn(controller.vnApp, 'showMessage');
|
||||
$httpBackend.expect('POST', `Tickets/11/sendSms`, params).respond(200, params);
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
ng-click="$ctrl.setOkState()"
|
||||
vn-tooltip="Change ticket state to 'Ok'">
|
||||
</vn-button>
|
||||
<vn-ticket-descriptor-menu ticket-id="$ctrl.summary.id" reload="$ctrl.reload()"/>
|
||||
<vn-ticket-descriptor-menu ticket-id="$ctrl.summary.id" parent-reload="$ctrl.reload()"/>
|
||||
</h5>
|
||||
<vn-horizontal>
|
||||
<vn-one>
|
||||
|
|
Loading…
Reference in New Issue