From 2451d13955862bd657ca83013964007ea702b5f4 Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Wed, 22 Feb 2023 15:14:27 +0500 Subject: [PATCH 1/5] Adf Fix problem Task for Consult Beneficiaries --- .../smartregister/eusm/adapter/EusmTaskRegisterAdapter.java | 2 ++ .../eusm/fragment/EusmTasksRegisterFragment.java | 2 ++ .../main/java/org/smartregister/eusm/util/AppConstants.java | 2 ++ .../java/org/smartregister/eusm/util/AppJsonFormUtils.java | 3 ++- .../eusm/viewholder/TaskRegisterViewHolder.java | 5 ++++- 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/opensrp-eusm/src/main/java/org/smartregister/eusm/adapter/EusmTaskRegisterAdapter.java b/opensrp-eusm/src/main/java/org/smartregister/eusm/adapter/EusmTaskRegisterAdapter.java index b3f002d..0c77ec9 100644 --- a/opensrp-eusm/src/main/java/org/smartregister/eusm/adapter/EusmTaskRegisterAdapter.java +++ b/opensrp-eusm/src/main/java/org/smartregister/eusm/adapter/EusmTaskRegisterAdapter.java @@ -70,6 +70,8 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int po productName = context.getString(R.string.consult_beneficiaries_task_title); } else if( AppConstants.TaskCode.WAREHOUSE_CHECK.equals(productName)){ productName = context.getString(R.string.warehouse_check_task_title); + } else if( AppConstants.TaskCode.FIX_PROBLEM_CONSULT_BENEFICIARIES.equals(productName)){ + productName = String.format(context.getString(R.string.fix_problem_prefix), context.getString(R.string.consult_beneficiaries_task_title)); } taskRegisterViewHolder.setProductName(productName, taskDetail.isChecked()); diff --git a/opensrp-eusm/src/main/java/org/smartregister/eusm/fragment/EusmTasksRegisterFragment.java b/opensrp-eusm/src/main/java/org/smartregister/eusm/fragment/EusmTasksRegisterFragment.java index 853f913..c1384e3 100644 --- a/opensrp-eusm/src/main/java/org/smartregister/eusm/fragment/EusmTasksRegisterFragment.java +++ b/opensrp-eusm/src/main/java/org/smartregister/eusm/fragment/EusmTasksRegisterFragment.java @@ -130,6 +130,8 @@ public void onViewClicked(View view) { presenter.startForm(structureDetail, taskDetail, getBeneficiaryConsultationForm()); } else if (AppConstants.NonProductTasks.WAREHOUSE_CHECK.equalsIgnoreCase(taskDetail.getEntityName().trim())) { presenter.startForm(structureDetail, taskDetail, getWarehouseCheckForm()); + } else if (AppConstants.TaskCode.FIX_PROBLEM_CONSULT_BENEFICIARIES.equalsIgnoreCase(taskDetail.getTaskCode())) { + presenter.startForm(structureDetail, taskDetail, getFixProblemForm()); } } } diff --git a/opensrp-eusm/src/main/java/org/smartregister/eusm/util/AppConstants.java b/opensrp-eusm/src/main/java/org/smartregister/eusm/util/AppConstants.java index 57ff0e2..357b914 100644 --- a/opensrp-eusm/src/main/java/org/smartregister/eusm/util/AppConstants.java +++ b/opensrp-eusm/src/main/java/org/smartregister/eusm/util/AppConstants.java @@ -128,6 +128,8 @@ interface TaskCode { String CONSULT_BENEFICIARIES = "Consult Beneficiaries"; String WAREHOUSE_CHECK = "Warehouse Check"; + + String FIX_PROBLEM_CONSULT_BENEFICIARIES = "fix_problem_consult_beneficiaries"; } interface TaskStatus { diff --git a/opensrp-eusm/src/main/java/org/smartregister/eusm/util/AppJsonFormUtils.java b/opensrp-eusm/src/main/java/org/smartregister/eusm/util/AppJsonFormUtils.java index 4123a47..f77816c 100644 --- a/opensrp-eusm/src/main/java/org/smartregister/eusm/util/AppJsonFormUtils.java +++ b/opensrp-eusm/src/main/java/org/smartregister/eusm/util/AppJsonFormUtils.java @@ -60,7 +60,8 @@ public JSONObject getFormObjectWithDetails(Context context, String formName, Str map.put(AppConstants.EventDetailKey.MISSION, PreferencesUtil.getInstance().getCurrentPlan()); String entityId; if (AppConstants.JsonForm.RECORD_GPS_FORM.equals(formName) || AppConstants.JsonForm.SERVICE_POINT_CHECK_FORM.equals(formName) - || AppConstants.JsonForm.BENEFICIARY_CONSULTATION_FORM.equals(formName) || AppConstants.JsonForm.WAREHOUSE_CHECK_FORM.equals(formName)) { + || AppConstants.JsonForm.BENEFICIARY_CONSULTATION_FORM.equals(formName) || AppConstants.JsonForm.WAREHOUSE_CHECK_FORM.equals(formName) + || (AppConstants.JsonForm.FIX_PROBLEM_FORM.equals(formName) && taskDetail.getTaskCode().equals(AppConstants.TaskCode.FIX_PROBLEM_CONSULT_BENEFICIARIES))) { entityId = structureDetail.getStructureId(); } else { map.put(AppConstants.EventDetailKey.PRODUCT_NAME, taskDetail.getEntityName()); diff --git a/opensrp-eusm/src/main/java/org/smartregister/eusm/viewholder/TaskRegisterViewHolder.java b/opensrp-eusm/src/main/java/org/smartregister/eusm/viewholder/TaskRegisterViewHolder.java index c91ce8b..feafb79 100644 --- a/opensrp-eusm/src/main/java/org/smartregister/eusm/viewholder/TaskRegisterViewHolder.java +++ b/opensrp-eusm/src/main/java/org/smartregister/eusm/viewholder/TaskRegisterViewHolder.java @@ -74,7 +74,8 @@ public void setProductImage(@Nullable TaskDetail taskDetail) { } else { checkedOverlayImageView.setVisibility(View.GONE); rectangleOverlayImageView.setVisibility(View.GONE); - if (AppConstants.EncounterType.FIX_PROBLEM.equals(taskDetail.getTaskCode())) { + if (AppConstants.EncounterType.FIX_PROBLEM.equals(taskDetail.getTaskCode()) + || AppConstants.TaskCode.FIX_PROBLEM_CONSULT_BENEFICIARIES.equalsIgnoreCase(taskDetail.getTaskCode())) { statusOverlayImageView.setVisibility(View.VISIBLE); } } @@ -88,6 +89,8 @@ public void setProductImage(@Nullable TaskDetail taskDetail) { this.productImageView.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.service_point_check_thumbnail, context.getTheme())); } else if (AppConstants.NonProductTasks.WAREHOUSE_CHECK.equalsIgnoreCase(taskDetail.getEntityName())) { this.productImageView.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.service_point_check_thumbnail, context.getTheme())); + } else if (AppConstants.TaskCode.FIX_PROBLEM_CONSULT_BENEFICIARIES.equalsIgnoreCase(taskDetail.getTaskCode())) { + this.productImageView.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.service_point_check_thumbnail, context.getTheme())); } } } From 4f6d475ac56267c65bfc6b417e9e7ec00f11565c Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Wed, 22 Feb 2023 16:15:34 +0500 Subject: [PATCH 2/5] Fix Failing tests --- .../org/smartregister/eusm/util/AppJsonFormUtilsTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/opensrp-eusm/src/test/java/org/smartregister/eusm/util/AppJsonFormUtilsTest.java b/opensrp-eusm/src/test/java/org/smartregister/eusm/util/AppJsonFormUtilsTest.java index 3feffde..e973e0d 100644 --- a/opensrp-eusm/src/test/java/org/smartregister/eusm/util/AppJsonFormUtilsTest.java +++ b/opensrp-eusm/src/test/java/org/smartregister/eusm/util/AppJsonFormUtilsTest.java @@ -92,8 +92,10 @@ public void testSaveImageShouldSaveImageToFileAndImageTable() throws JSONExcepti @Test public void testGetFormObjectWithDetailsShouldReturnJsonForm() { + TaskDetail taskDetail = new TaskDetail(); + taskDetail.setTaskCode("fix_problem"); JSONObject jsonObject = jsonFormUtils.getFormObjectWithDetails(RuntimeEnvironment.application, - AppConstants.JsonForm.FIX_PROBLEM_FORM, new StructureDetail(), new TaskDetail()); + AppConstants.JsonForm.FIX_PROBLEM_FORM, new StructureDetail(), taskDetail); assertNotNull(jsonObject); } } \ No newline at end of file From a3c31dddef82b58d87e8a16eaed427b72d8483a4 Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Wed, 22 Feb 2023 18:51:01 +0500 Subject: [PATCH 3/5] Increase Code Coverage --- .../EusmTasksRegisterFragmentTest.java | 22 +++++++++++++++++++ .../eusm/util/AppJsonFormUtilsTest.java | 1 + .../TaskRegisterViewHolderTest.java | 22 +++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/opensrp-eusm/src/test/java/org/smartregister/eusm/fragment/EusmTasksRegisterFragmentTest.java b/opensrp-eusm/src/test/java/org/smartregister/eusm/fragment/EusmTasksRegisterFragmentTest.java index 329a4e4..790adea 100644 --- a/opensrp-eusm/src/test/java/org/smartregister/eusm/fragment/EusmTasksRegisterFragmentTest.java +++ b/opensrp-eusm/src/test/java/org/smartregister/eusm/fragment/EusmTasksRegisterFragmentTest.java @@ -8,6 +8,7 @@ import org.json.JSONException; import org.json.JSONObject; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -157,4 +158,25 @@ public void testStartFormActivityShouldInvokeStartActivityForResult() { } }); } + + @Test + public void testOnTaskRegisterRowClickShouldStartFixProblemFormForConsultBeneficiaries() { + TaskDetail taskDetail = new TaskDetail(); + taskDetail.setTaskCode(AppConstants.TaskCode.FIX_PROBLEM_CONSULT_BENEFICIARIES); + taskDetail.setNonProductTask(true); + taskDetail.setEntityName(AppConstants.TaskCode.FIX_PROBLEM_CONSULT_BENEFICIARIES); + View view = new View(RuntimeEnvironment.application); + view.setId(R.id.task_register_row); + view.setTag(R.id.task_detail, taskDetail); + + Assert.assertNotNull(fragmentScenario); + fragmentScenario.onFragment(fragment -> { + EusmTasksRegisterFragment fragmentSpy = spy(fragment); + ReflectionHelpers.setField(fragmentSpy, "presenter", presenter); + EusmTaskRegisterActivity activity = Robolectric.buildActivity(EusmTaskRegisterActivity.class).get(); + doReturn(activity).when(fragmentSpy).getActivity(); + fragmentSpy.onViewClicked(view); + verify(presenter).startForm(any(StructureDetail.class), eq(taskDetail), eq(AppConstants.JsonForm.FIX_PROBLEM_FORM)); + }); + } } \ No newline at end of file diff --git a/opensrp-eusm/src/test/java/org/smartregister/eusm/util/AppJsonFormUtilsTest.java b/opensrp-eusm/src/test/java/org/smartregister/eusm/util/AppJsonFormUtilsTest.java index e973e0d..6debfed 100644 --- a/opensrp-eusm/src/test/java/org/smartregister/eusm/util/AppJsonFormUtilsTest.java +++ b/opensrp-eusm/src/test/java/org/smartregister/eusm/util/AppJsonFormUtilsTest.java @@ -94,6 +94,7 @@ public void testSaveImageShouldSaveImageToFileAndImageTable() throws JSONExcepti public void testGetFormObjectWithDetailsShouldReturnJsonForm() { TaskDetail taskDetail = new TaskDetail(); taskDetail.setTaskCode("fix_problem"); + assertNotNull(jsonFormUtils); JSONObject jsonObject = jsonFormUtils.getFormObjectWithDetails(RuntimeEnvironment.application, AppConstants.JsonForm.FIX_PROBLEM_FORM, new StructureDetail(), taskDetail); assertNotNull(jsonObject); diff --git a/opensrp-eusm/src/test/java/org/smartregister/eusm/viewholder/TaskRegisterViewHolderTest.java b/opensrp-eusm/src/test/java/org/smartregister/eusm/viewholder/TaskRegisterViewHolderTest.java index e942c99..50fe6b9 100644 --- a/opensrp-eusm/src/test/java/org/smartregister/eusm/viewholder/TaskRegisterViewHolderTest.java +++ b/opensrp-eusm/src/test/java/org/smartregister/eusm/viewholder/TaskRegisterViewHolderTest.java @@ -1,5 +1,6 @@ package org.smartregister.eusm.viewholder; +import android.graphics.drawable.Drawable; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; @@ -15,8 +16,11 @@ import org.smartregister.eusm.domain.TaskDetail; import org.smartregister.eusm.util.AppConstants; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; public class TaskRegisterViewHolderTest extends BaseUnitTest { @@ -74,4 +78,22 @@ public void testSetProductImageIfTaskISCheckedShouldLoadWithOverlay() { verify(statusOverlayImageView).setVisibility(eq(View.GONE)); verify(statusOverlayImageView).setVisibility(eq(View.VISIBLE)); } + + @Test + public void testSetProductImageShouldCallSetImageDrawableForFixProblemForCOnsultBeneficiaries() { + TaskDetail taskDetail = new TaskDetail(); + taskDetail.setNonProductTask(true); + taskDetail.setChecked(false); + taskDetail.setTaskCode(AppConstants.TaskCode.FIX_PROBLEM_CONSULT_BENEFICIARIES); + + ImageView productImageView = mock(ImageView.class); + ReflectionHelpers.setField(taskRegisterViewHolder, "checkedOverlayImageView", checkedOverlayImageView); + ReflectionHelpers.setField(taskRegisterViewHolder, "rectangleOverlayImageView", rectangleOverlayImageView); + ReflectionHelpers.setField(taskRegisterViewHolder, "statusOverlayImageView", statusOverlayImageView); + ReflectionHelpers.setField(taskRegisterViewHolder, "productImageView", productImageView); + + taskRegisterViewHolder.setProductImage(taskDetail); + + verify(productImageView, times(2)).setImageDrawable(any(Drawable.class)); + } } \ No newline at end of file From 249998cce31a27c3a6def964ca90a32295d7a852 Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Tue, 28 Feb 2023 11:23:34 +0500 Subject: [PATCH 4/5] PR feedback changes --- .../smartregister/eusm/fragment/EusmTasksRegisterFragment.java | 2 +- .../smartregister/eusm/viewholder/TaskRegisterViewHolder.java | 2 +- .../eusm/viewholder/TaskRegisterViewHolderTest.java | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/opensrp-eusm/src/main/java/org/smartregister/eusm/fragment/EusmTasksRegisterFragment.java b/opensrp-eusm/src/main/java/org/smartregister/eusm/fragment/EusmTasksRegisterFragment.java index c1384e3..8a7d1b1 100644 --- a/opensrp-eusm/src/main/java/org/smartregister/eusm/fragment/EusmTasksRegisterFragment.java +++ b/opensrp-eusm/src/main/java/org/smartregister/eusm/fragment/EusmTasksRegisterFragment.java @@ -130,7 +130,7 @@ public void onViewClicked(View view) { presenter.startForm(structureDetail, taskDetail, getBeneficiaryConsultationForm()); } else if (AppConstants.NonProductTasks.WAREHOUSE_CHECK.equalsIgnoreCase(taskDetail.getEntityName().trim())) { presenter.startForm(structureDetail, taskDetail, getWarehouseCheckForm()); - } else if (AppConstants.TaskCode.FIX_PROBLEM_CONSULT_BENEFICIARIES.equalsIgnoreCase(taskDetail.getTaskCode())) { + } else if (AppConstants.TaskCode.FIX_PROBLEM_CONSULT_BENEFICIARIES.equalsIgnoreCase(taskDetail.getEntityName())) { presenter.startForm(structureDetail, taskDetail, getFixProblemForm()); } } diff --git a/opensrp-eusm/src/main/java/org/smartregister/eusm/viewholder/TaskRegisterViewHolder.java b/opensrp-eusm/src/main/java/org/smartregister/eusm/viewholder/TaskRegisterViewHolder.java index feafb79..8fe3f29 100644 --- a/opensrp-eusm/src/main/java/org/smartregister/eusm/viewholder/TaskRegisterViewHolder.java +++ b/opensrp-eusm/src/main/java/org/smartregister/eusm/viewholder/TaskRegisterViewHolder.java @@ -89,7 +89,7 @@ public void setProductImage(@Nullable TaskDetail taskDetail) { this.productImageView.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.service_point_check_thumbnail, context.getTheme())); } else if (AppConstants.NonProductTasks.WAREHOUSE_CHECK.equalsIgnoreCase(taskDetail.getEntityName())) { this.productImageView.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.service_point_check_thumbnail, context.getTheme())); - } else if (AppConstants.TaskCode.FIX_PROBLEM_CONSULT_BENEFICIARIES.equalsIgnoreCase(taskDetail.getTaskCode())) { + } else if (AppConstants.TaskCode.FIX_PROBLEM_CONSULT_BENEFICIARIES.equalsIgnoreCase(taskDetail.getEntityName())) { this.productImageView.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.service_point_check_thumbnail, context.getTheme())); } } diff --git a/opensrp-eusm/src/test/java/org/smartregister/eusm/viewholder/TaskRegisterViewHolderTest.java b/opensrp-eusm/src/test/java/org/smartregister/eusm/viewholder/TaskRegisterViewHolderTest.java index 50fe6b9..48002ba 100644 --- a/opensrp-eusm/src/test/java/org/smartregister/eusm/viewholder/TaskRegisterViewHolderTest.java +++ b/opensrp-eusm/src/test/java/org/smartregister/eusm/viewholder/TaskRegisterViewHolderTest.java @@ -80,11 +80,12 @@ public void testSetProductImageIfTaskISCheckedShouldLoadWithOverlay() { } @Test - public void testSetProductImageShouldCallSetImageDrawableForFixProblemForCOnsultBeneficiaries() { + public void testSetProductImageShouldCallSetImageDrawableForFixProblemForConsultBeneficiaries() { TaskDetail taskDetail = new TaskDetail(); taskDetail.setNonProductTask(true); taskDetail.setChecked(false); taskDetail.setTaskCode(AppConstants.TaskCode.FIX_PROBLEM_CONSULT_BENEFICIARIES); + taskDetail.setEntityName(AppConstants.TaskCode.FIX_PROBLEM_CONSULT_BENEFICIARIES); ImageView productImageView = mock(ImageView.class); ReflectionHelpers.setField(taskRegisterViewHolder, "checkedOverlayImageView", checkedOverlayImageView); From 676bf9a96f4f3f25f54edc2535b2c1b116adad53 Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Thu, 2 Mar 2023 19:35:30 +0500 Subject: [PATCH 5/5] PR feedback 3 --- .../main/java/org/smartregister/eusm/util/AppJsonFormUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-eusm/src/main/java/org/smartregister/eusm/util/AppJsonFormUtils.java b/opensrp-eusm/src/main/java/org/smartregister/eusm/util/AppJsonFormUtils.java index f77816c..00f5ff0 100644 --- a/opensrp-eusm/src/main/java/org/smartregister/eusm/util/AppJsonFormUtils.java +++ b/opensrp-eusm/src/main/java/org/smartregister/eusm/util/AppJsonFormUtils.java @@ -61,7 +61,7 @@ public JSONObject getFormObjectWithDetails(Context context, String formName, Str String entityId; if (AppConstants.JsonForm.RECORD_GPS_FORM.equals(formName) || AppConstants.JsonForm.SERVICE_POINT_CHECK_FORM.equals(formName) || AppConstants.JsonForm.BENEFICIARY_CONSULTATION_FORM.equals(formName) || AppConstants.JsonForm.WAREHOUSE_CHECK_FORM.equals(formName) - || (AppConstants.JsonForm.FIX_PROBLEM_FORM.equals(formName) && taskDetail.getTaskCode().equals(AppConstants.TaskCode.FIX_PROBLEM_CONSULT_BENEFICIARIES))) { + || (AppConstants.JsonForm.FIX_PROBLEM_FORM.equals(formName) && AppConstants.TaskCode.FIX_PROBLEM_CONSULT_BENEFICIARIES.equals(taskDetail.getTaskCode()))) { entityId = structureDetail.getStructureId(); } else { map.put(AppConstants.EventDetailKey.PRODUCT_NAME, taskDetail.getEntityName());