diff --git a/modules/invoiceOut/front/descriptor-menu/index.js b/modules/invoiceOut/front/descriptor-menu/index.js index 7e80a4a7c1..7738845f97 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.js +++ b/modules/invoiceOut/front/descriptor-menu/index.js @@ -55,8 +55,13 @@ class Controller extends Section { deleteInvoiceOut() { return this.$http.post(`InvoiceOuts/${this.invoiceOut.id}/delete`) - .then(() => this.$state.go('invoiceOut.index')) - .then(() => this.$state.reload()) + .then(() => { + 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'))); } diff --git a/modules/invoiceOut/front/descriptor-menu/index.spec.js b/modules/invoiceOut/front/descriptor-menu/index.spec.js index 19822f0947..fced12e0d5 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.spec.js +++ b/modules/invoiceOut/front/descriptor-menu/index.spec.js @@ -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()', () => { it('should make a query to the email invoice endpoint and show a message snackbar', () => { jest.spyOn(controller.vnApp, 'showMessage'); diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index 142f44989c..9d4381f7c5 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -149,7 +149,10 @@ class Controller extends Section { return this.$http.post(`Tickets/${this.id}/setDeleted`) .then(() => this.reload()) .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')); }); } diff --git a/modules/ticket/front/descriptor-menu/index.spec.js b/modules/ticket/front/descriptor-menu/index.spec.js index e9486bcd07..288c7508ba 100644 --- a/modules/ticket/front/descriptor-menu/index.spec.js +++ b/modules/ticket/front/descriptor-menu/index.spec.js @@ -78,9 +78,22 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { describe('deleteTicket()', () => { 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.$state, 'go').mockReturnValue('ok'); jest.spyOn(controller.vnApp, 'showSuccess'); + controller.$state.current.name = 'ticket.card.something'; $httpBackend.expectPOST(`Tickets/${ticket.id}/setDeleted`).respond(); controller.deleteTicket();