Merge pull request '3521-Monitors_ticket_summary' (#854) from 3521-Monitors_ticket_summary into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #854
Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
Joan Sanchez 2022-01-20 11:28:08 +00:00
commit 02256201da
4 changed files with 53 additions and 3 deletions

View File

@ -55,8 +55,13 @@ class Controller extends Section {
deleteInvoiceOut() { deleteInvoiceOut() {
return this.$http.post(`InvoiceOuts/${this.invoiceOut.id}/delete`) return this.$http.post(`InvoiceOuts/${this.invoiceOut.id}/delete`)
.then(() => this.$state.go('invoiceOut.index')) .then(() => {
.then(() => this.$state.reload()) const isInsideInvoiceOut = this.$state.current.name.startsWith('invoiceOut');
if (isInsideInvoiceOut)
this.$state.go('invoiceOut.index');
else
this.$state.reload();
})
.then(() => this.vnApp.showSuccess(this.$t('InvoiceOut deleted'))); .then(() => this.vnApp.showSuccess(this.$t('InvoiceOut deleted')));
} }

View File

@ -50,6 +50,35 @@ describe('vnInvoiceOutDescriptorMenu', () => {
}); });
}); });
describe('deleteInvoiceOut()', () => {
it(`should make a query and call showSuccess()`, () => {
controller.invoiceOut = invoiceOut;
controller.$state.reload = jest.fn();
jest.spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectPOST(`InvoiceOuts/${invoiceOut.id}/delete`).respond();
controller.deleteInvoiceOut();
$httpBackend.flush();
expect(controller.$state.reload).toHaveBeenCalled();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
it(`should make a query and call showSuccess() after state.go if the state wasn't in invoiceOut module`, () => {
controller.invoiceOut = invoiceOut;
jest.spyOn(controller.$state, 'go').mockReturnValue('ok');
jest.spyOn(controller.vnApp, 'showSuccess');
controller.$state.current.name = 'invoiceOut.card.something';
$httpBackend.expectPOST(`InvoiceOuts/${invoiceOut.id}/delete`).respond();
controller.deleteInvoiceOut();
$httpBackend.flush();
expect(controller.$state.go).toHaveBeenCalledWith('invoiceOut.index');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
describe('sendPdfInvoice()', () => { describe('sendPdfInvoice()', () => {
it('should make a query to the email invoice endpoint and show a message snackbar', () => { it('should make a query to the email invoice endpoint and show a message snackbar', () => {
jest.spyOn(controller.vnApp, 'showMessage'); jest.spyOn(controller.vnApp, 'showMessage');

View File

@ -149,7 +149,10 @@ class Controller extends Section {
return this.$http.post(`Tickets/${this.id}/setDeleted`) return this.$http.post(`Tickets/${this.id}/setDeleted`)
.then(() => this.reload()) .then(() => this.reload())
.then(() => { .then(() => {
this.$state.go('ticket.index'); const isInsideTicket = this.$state.current.name.startsWith('ticket');
if (isInsideTicket)
this.$state.go('ticket.index');
this.vnApp.showSuccess(this.$t('Ticket deleted. You can undo this action within the first hour')); this.vnApp.showSuccess(this.$t('Ticket deleted. You can undo this action within the first hour'));
}); });
} }

View File

@ -78,9 +78,22 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
describe('deleteTicket()', () => { describe('deleteTicket()', () => {
it('should make a query and call vnApp.showSuccess()', () => { it('should make a query and call vnApp.showSuccess()', () => {
jest.spyOn(controller, 'reload').mockReturnThis();
jest.spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectPOST(`Tickets/${ticket.id}/setDeleted`).respond();
controller.deleteTicket();
$httpBackend.flush();
expect(controller.reload).toHaveBeenCalled();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
it(`should make a query and call showSuccess() after state.go if the state wasn't inside ticket module`, () => {
jest.spyOn(controller, 'reload').mockReturnThis(); jest.spyOn(controller, 'reload').mockReturnThis();
jest.spyOn(controller.$state, 'go').mockReturnValue('ok'); jest.spyOn(controller.$state, 'go').mockReturnValue('ok');
jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.vnApp, 'showSuccess');
controller.$state.current.name = 'ticket.card.something';
$httpBackend.expectPOST(`Tickets/${ticket.id}/setDeleted`).respond(); $httpBackend.expectPOST(`Tickets/${ticket.id}/setDeleted`).respond();
controller.deleteTicket(); controller.deleteTicket();