#3521 refactor(descriptor): navigation to index after deletion
This commit is contained in:
parent
2aca5c7473
commit
4ac071d55c
|
@ -51,8 +51,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')));
|
||||
}
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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'));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue