From 1922280c617205d677c6c0b727a80f8086a3e9a8 Mon Sep 17 00:00:00 2001
From: jorgebl <jorgebl.verdnatura@gmail.com>
Date: Mon, 8 Mar 2021 17:49:04 +0100
Subject: [PATCH] QA rename some descriptions in test and reworked the test

---
 modules/item/front/botanical/index.spec.js | 32 +++++++++-------------
 1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/modules/item/front/botanical/index.spec.js b/modules/item/front/botanical/index.spec.js
index 6192b72e6c..afec83cfdb 100644
--- a/modules/item/front/botanical/index.spec.js
+++ b/modules/item/front/botanical/index.spec.js
@@ -30,6 +30,11 @@ describe('vnItemBotanical', () => {
                 }};
         }));
 
+        beforeEach(() => {
+            const response = {data: 'MyResult'};
+            $httpBackend.whenRoute('GET', 'ItemBotanicals').respond(response);
+        });
+
         describe('showGenus()', () => {
             it('should do nothing in genus field if it default is prevented', () => {
                 const event = {
@@ -93,7 +98,7 @@ describe('vnItemBotanical', () => {
         });
 
         describe('onGenusAccept()', () => {
-            it('should throw an error if genus field has not name', () => {
+            it('should throw an error if the item botanical has no genus name', () => {
                 jest.spyOn(controller.vnApp, 'showMessage');
 
                 controller.data = {};
@@ -103,11 +108,7 @@ describe('vnItemBotanical', () => {
                 expect(controller.vnApp.showError).toHaveBeenCalledWith(`The name of the genus can't be empty`);
             });
 
-            it('should do add the new genus', () => {
-                const response = {data: 'MyResult'};
-                $httpBackend.whenRoute('GET', 'ItemBotanicals').respond(response);
-                $httpBackend.resetExpectations();
-
+            it('should add the new genus', () => {
                 controller.data = {
                     id: 4,
                     name: 'Anilius'
@@ -117,12 +118,15 @@ describe('vnItemBotanical', () => {
 
                 controller.onGenusAccept();
                 $httpBackend.flush();
+
                 controller.onGenusResponse(controller.data);
+
+                expect(controller.botanical.genusFk).toEqual(controller.data.id);
             });
         });
 
         describe('onSpeciesAccept()', () => {
-            it('should throw an error if species field has not name', () => {
+            it('should throw an error if the item botanical has no species name', () => {
                 jest.spyOn(controller.vnApp, 'showMessage');
 
                 controller.data = {};
@@ -132,11 +136,7 @@ describe('vnItemBotanical', () => {
                 expect(controller.vnApp.showError).toHaveBeenCalledWith(`The name of the species can't be empty`);
             });
 
-            it('should do add the new species', () => {
-                const response = {data: 'MyResult'};
-                $httpBackend.whenRoute('GET', 'ItemBotanicals').respond(response);
-                $httpBackend.resetExpectations();
-
+            it('should add the new species', () => {
                 controller.data = {
                     id: 2,
                     name: 'Spasiva'
@@ -152,10 +152,6 @@ describe('vnItemBotanical', () => {
 
         describe('onSubmit()', () => {
             it('should make HTTP POST request to save the genus and species data', () => {
-                const response = {data: 'MyResult'};
-                $httpBackend.whenRoute('GET', 'ItemBotanicals').respond(response);
-                $httpBackend.resetExpectations();
-
                 jest.spyOn(controller.$.watcher, 'updateOriginalData');
                 jest.spyOn(controller.$.watcher, 'check');
                 jest.spyOn(controller.$.watcher, 'notifySaved');
@@ -172,12 +168,10 @@ describe('vnItemBotanical', () => {
 
         describe('getBotanicalData()', () => {
             it('should get the species and genus data references of the item', () => {
-                const response = ['MyResult'];
-                $httpBackend.whenRoute('GET', `ItemBotanicals`).respond(response);
                 controller.getBotanicalData();
                 $httpBackend.flush();
 
-                expect(controller.botanical).toEqual(response[0]);
+                expect(controller.botanical).toEqual(controller.$params);
             });
         });
     });