From 8aa3d269eabf67212469f5d895c7edf98b338876 Mon Sep 17 00:00:00 2001 From: carlosjr Date: Tue, 15 Jun 2021 16:41:01 +0200 Subject: [PATCH] Travel descriptor now shows delete option if there are no entries --- modules/travel/front/descriptor-menu/index.html | 15 +++++++++++++++ modules/travel/front/descriptor-menu/index.js | 11 ++++++++++- .../travel/front/descriptor-menu/index.spec.js | 15 +++++++++++++++ .../travel/front/descriptor-menu/locale/es.yml | 3 +++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/modules/travel/front/descriptor-menu/index.html b/modules/travel/front/descriptor-menu/index.html index c7edcd59e..9b408994f 100644 --- a/modules/travel/front/descriptor-menu/index.html +++ b/modules/travel/front/descriptor-menu/index.html @@ -18,6 +18,13 @@ translate> Clone travel and his entries + + Delete travel + + + + + this.travel = res.data); + + this.$http.get(`Travels/${this.travelId}/getEntries`) + .then(res => this.entries = res.data); } get isBuyer() { return this.aclService.hasAny(['buyer']); } + onDeleteAccept() { + this.$http.delete(`Travels/${this.travelId}`) + .then(() => this.$state.go('travel.index')) + .then(() => this.vnApp.showSuccess(this.$t('Travel deleted'))); + } + onCloneAccept() { const params = JSON.stringify({ ref: this.travel.ref, diff --git a/modules/travel/front/descriptor-menu/index.spec.js b/modules/travel/front/descriptor-menu/index.spec.js index 3d94a0963..4ca93a6d6 100644 --- a/modules/travel/front/descriptor-menu/index.spec.js +++ b/modules/travel/front/descriptor-menu/index.spec.js @@ -40,6 +40,21 @@ describe('Travel Component vnTravelDescriptorMenu', () => { }); }); + describe('onDeleteAccept()', () => { + it('should perform a delete query', () => { + jest.spyOn(controller.$state, 'go').mockReturnValue('ok'); + controller.travelId = 1; + + $httpBackend.when('GET', `Travels/${controller.travelId}`).respond(200); + $httpBackend.when('GET', `Travels/${controller.travelId}/getEntries`).respond(200); + $httpBackend.expect('DELETE', `Travels/${controller.travelId}`).respond(200); + controller.onDeleteAccept(); + $httpBackend.flush(); + + expect(controller.$state.go).toHaveBeenCalledWith('travel.index'); + }); + }); + describe('onCloneWithEntriesAccept()', () => { it('should make an HTTP query and then call to the $state.go method with the returned id', () => { jest.spyOn(controller.$state, 'go').mockReturnValue('ok'); diff --git a/modules/travel/front/descriptor-menu/locale/es.yml b/modules/travel/front/descriptor-menu/locale/es.yml index b764ba0cd..1ab68cca5 100644 --- a/modules/travel/front/descriptor-menu/locale/es.yml +++ b/modules/travel/front/descriptor-menu/locale/es.yml @@ -2,3 +2,6 @@ Clone travel: Clonar envío Add entry: Añadir entrada Clone travel and his entries: Clonar travel y sus entradas Do you want to clone this travel and all containing entries?: ¿Quieres clonar este travel y todas las entradas que contiene? +Delete travel: Borrar envío +The travel will be deleted: El envío será borrado +Do you want to delete this travel?: ¿Quieres borrar este envío? \ No newline at end of file