diff --git a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/activity/BaseMalariaProfileActivity.java b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/activity/BaseMalariaProfileActivity.java index b0e61e1..c669a05 100644 --- a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/activity/BaseMalariaProfileActivity.java +++ b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/activity/BaseMalariaProfileActivity.java @@ -28,7 +28,9 @@ import org.smartregister.chw.malaria.presenter.BaseMalariaProfilePresenter; import org.smartregister.chw.malaria.util.Constants; import org.smartregister.chw.malaria.util.Util; +import org.smartregister.commonregistry.CommonPersonObjectClient; import org.smartregister.domain.AlertStatus; +import org.smartregister.helper.ImageRenderHelper; import org.smartregister.malaria.R; import org.smartregister.view.activity.BaseProfileActivity; @@ -37,10 +39,14 @@ import java.util.Date; import java.util.Locale; +import de.hdodenhof.circleimageview.CircleImageView; + public class BaseMalariaProfileActivity extends BaseProfileActivity implements MalariaProfileContract.View, MalariaProfileContract.InteractorCallBack { protected MemberObject MEMBER_OBJECT; protected MalariaProfileContract.Presenter profilePresenter; + protected CommonPersonObjectClient client; + protected CircleImageView imageView; protected TextView textViewName; protected TextView textViewGender; protected TextView textViewLocation; @@ -54,6 +60,8 @@ public class BaseMalariaProfileActivity extends BaseProfileActivity implements M protected RelativeLayout rlLastVisit; protected RelativeLayout rlUpcomingServices; protected RelativeLayout rlFamilyServicesDue; + protected RelativeLayout visitStatus; + protected TextView textViewUndo; private TextView tvUpComingServices; private TextView tvFamilyStatus; private SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM", Locale.getDefault()); @@ -106,6 +114,8 @@ protected void onCreation() { progressBar = findViewById(R.id.progress_bar); + visitStatus = findViewById(R.id.record_visit_status_bar); + findViewById(R.id.rlLastVisit).setOnClickListener(this); findViewById(R.id.rlUpcomingServices).setOnClickListener(this); findViewById(R.id.rlFamilyServicesDue).setOnClickListener(this); @@ -119,7 +129,14 @@ protected void onCreation() { textViewAncVisitNotDone = findViewById(R.id.textview_anc_visit_not_done); textViewAncVisitNotDone.setOnClickListener(this); + textViewUndo = findViewById(R.id.textview_undo); + textViewUndo.setOnClickListener(this); + + imageView = findViewById(R.id.imageview_profile); + imageRenderHelper = new ImageRenderHelper(this); + MEMBER_OBJECT = (MemberObject) getIntent().getSerializableExtra(Constants.MALARIA_MEMBER_OBJECT.MEMBER_OBJECT); + client = (CommonPersonObjectClient) getIntent().getSerializableExtra("CLIENT"); initializePresenter(); diff --git a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaProfilePresenter.java b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaProfilePresenter.java index 137b69c..d8a4cd0 100644 --- a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaProfilePresenter.java +++ b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaProfilePresenter.java @@ -32,8 +32,9 @@ public void fillProfileData(MemberObject memberObject) { @Override public void recordMalariaButton(int days_from_malaria_test_date) { - if (getView() == null) + if (getView() == null) { return; + } if (days_from_malaria_test_date < 7 || days_from_malaria_test_date > 14) { getView().hideView(); diff --git a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaRegisterPresenter.java b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaRegisterPresenter.java index 6c96b4f..d7dd691 100644 --- a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaRegisterPresenter.java +++ b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaRegisterPresenter.java @@ -16,7 +16,7 @@ public class BaseMalariaRegisterPresenter implements MalariaRegisterContract.Pre public static final String TAG = BaseMalariaRegisterPresenter.class.getName(); protected WeakReference viewReference; - protected MalariaRegisterContract.Interactor interactor; + private MalariaRegisterContract.Interactor interactor; protected MalariaRegisterContract.Model model; public BaseMalariaRegisterPresenter(MalariaRegisterContract.View view, MalariaRegisterContract.Model model, MalariaRegisterContract.Interactor interactor) { diff --git a/opensrp-chw-malaria/src/main/res/drawable/border.xml b/opensrp-chw-malaria/src/main/res/drawable/border.xml new file mode 100644 index 0000000..b70eee0 --- /dev/null +++ b/opensrp-chw-malaria/src/main/res/drawable/border.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/opensrp-chw-malaria/src/main/res/layout/view_record_malaria.xml b/opensrp-chw-malaria/src/main/res/layout/view_record_malaria.xml index deb8f71..564df4c 100644 --- a/opensrp-chw-malaria/src/main/res/layout/view_record_malaria.xml +++ b/opensrp-chw-malaria/src/main/res/layout/view_record_malaria.xml @@ -1,35 +1,36 @@ + android:id="@+id/record_malaria" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@color/white" + android:orientation="vertical" + android:paddingTop="10dp"> + + android:textColor="@color/white" /> + android:textColor="@color/grey" + android:visibility="visible" /> + + + + + + + + + + + + + + android:id="@+id/view_record" + android:layout_width="match_parent" + android:layout_height="1px" + android:layout_marginTop="5dp" + android:background="@color/light_grey" /> \ No newline at end of file diff --git a/opensrp-chw-malaria/src/main/res/values/strings.xml b/opensrp-chw-malaria/src/main/res/values/strings.xml index 0e9f472..9e98daa 100644 --- a/opensrp-chw-malaria/src/main/res/values/strings.xml +++ b/opensrp-chw-malaria/src/main/res/values/strings.xml @@ -36,5 +36,7 @@ Call Record ANC visit ANC visit not done + Not visiting this month + UNDO diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/activity/BaseMalariaProfileActivityTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/activity/BaseMalariaProfileActivityTest.java index bbdc1c5..45e5938 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/activity/BaseMalariaProfileActivityTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/activity/BaseMalariaProfileActivityTest.java @@ -1,27 +1,16 @@ package org.smartregister.activity; -import android.graphics.Color; -import android.view.View; - import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.mockito.Spy; import org.smartregister.chw.malaria.activity.BaseMalariaProfileActivity; public class BaseMalariaProfileActivityTest { @Mock protected BaseMalariaProfileActivity baseMalariaProfileActivity; - @Spy - protected BaseMalariaProfileActivity spy; - - @Mock - protected View view; - @Before public void setUp() { MockitoAnnotations.initMocks(this); diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java deleted file mode 100644 index 1570bdb..0000000 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.smartregister.domain; - -import org.junit.Assert; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.smartregister.chw.malaria.domain.MemberObject; -import org.smartregister.commonregistry.CommonPersonObjectClient; - -public class MemberObjectTest { - @Mock - private CommonPersonObjectClient client = Mockito.mock(CommonPersonObjectClient.class); - - private MemberObject memberObject = new MemberObject(client); - - @Test - public void getFirstName() { - memberObject.setFirstName("Denis"); - Assert.assertEquals("Denis", memberObject.getFirstName()); - } - - @Test - public void getMiddleName() { - memberObject.setMiddleName("Talemwa"); - Assert.assertEquals("Talemwa", memberObject.getMiddleName()); - } - - @Test - public void getLastName() { - memberObject.setLastName("Rwelamila"); - Assert.assertEquals("Rwelamila", memberObject.getLastName()); - } - - @Test - public void getAddress() { - memberObject.setAddress("123 Rd"); - Assert.assertEquals("123 Rd", memberObject.getAddress()); - } - - @Test - public void getGender() { - memberObject.setGender("Male"); - Assert.assertEquals("Male", memberObject.getGender()); - } - - @Test - public void getAge() { - memberObject.setAge("123"); - Assert.assertEquals("123", memberObject.getAge()); - } - - @Test - public void testIsClosed() { - memberObject.setIsClosed(false); - Assert.assertFalse(memberObject.getIsClosed()); - } -} - diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/model/BaseMalariaRegisterFragmentModelTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/model/BaseMalariaRegisterFragmentModelTest.java new file mode 100644 index 0000000..bc2d476 --- /dev/null +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/model/BaseMalariaRegisterFragmentModelTest.java @@ -0,0 +1,4 @@ +package org.smartregister.model; + +public class BaseMalariaRegisterFragmentModelTest { +} diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaProfilePresenterTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaProfilePresenterTest.java index 9f69578..ef35381 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaProfilePresenterTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaProfilePresenterTest.java @@ -56,4 +56,10 @@ public void malariaTestDatePeriodGreaterThanTen() { profilePresenter.recordMalariaButton(14); verify(view).setOverDueColor(); } -} + + @Test + public void refreshProfileBottom() { + profilePresenter.refreshProfileBottom(); + verify(interactor).refreshProfileInfo(memberObject, profilePresenter.getView()); + } + } diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterFragmentPresenterTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterFragmentPresenterTest.java index ca8d307..c8a3297 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterFragmentPresenterTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterFragmentPresenterTest.java @@ -7,12 +7,17 @@ import org.mockito.MockitoAnnotations; import org.smartregister.chw.malaria.contract.MalariaRegisterFragmentContract; import org.smartregister.chw.malaria.presenter.BaseMalariaRegisterFragmentPresenter; +import org.smartregister.chw.malaria.util.Constants; +import org.smartregister.chw.malaria.util.DBConstants; public class BaseMalariaRegisterFragmentPresenterTest { @Mock protected MalariaRegisterFragmentContract.View view; + + @Mock protected MalariaRegisterFragmentContract.Model model; + private BaseMalariaRegisterFragmentPresenter baseMalariaRegisterFragmentPresenter; @Before @@ -28,8 +33,25 @@ public void assertNotNull() { } @Test - public void testGetMainCondition() { + public void getMainCondition() { Assert.assertEquals("", baseMalariaRegisterFragmentPresenter.getMainCondition()); } + @Test + public void getDueFilterCondition() { + Assert.assertEquals(" (cast( julianday(STRFTIME('%Y-%m-%d', datetime('now'))) - julianday(IFNULL(SUBSTR(malaria_test_date,7,4)|| '-' || SUBSTR(malaria_test_date,4,2) || '-' || SUBSTR(malaria_test_date,1,2),'')) as integer) between 7 and 14) ", baseMalariaRegisterFragmentPresenter.getDueFilterCondition()); + } + + @Test + public void getDefaultSortQuery() { + Assert.assertEquals(Constants.TABLES.MALARIA_CONFIRMATION + "." + DBConstants.KEY.LAST_INTERACTED_WITH + " DESC ", baseMalariaRegisterFragmentPresenter.getDefaultSortQuery()); + } + + @Test + public void getMainTable() { + Assert.assertEquals(Constants.TABLES.MALARIA_CONFIRMATION, baseMalariaRegisterFragmentPresenter.getMainTable()); + } + + + } \ No newline at end of file diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java index ae75645..bdcd046 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java @@ -1,12 +1,14 @@ package org.smartregister.presenter; import org.json.JSONObject; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.reflect.Whitebox; import org.smartregister.chw.malaria.contract.MalariaRegisterContract; import org.smartregister.chw.malaria.presenter.BaseMalariaRegisterPresenter; @@ -16,31 +18,50 @@ public class BaseMalariaRegisterPresenterTest { @Mock protected BaseMalariaRegisterPresenter baseMalariaRegisterPresenter; - @Mock - protected MalariaRegisterContract.View view; + protected MalariaRegisterContract.Interactor interactor; + @Mock + protected MalariaRegisterContract.Model model; + @Mock + protected MalariaRegisterContract.View baseView; + private BaseMalariaRegisterPresenter presenter; @Before public void setUp() { MockitoAnnotations.initMocks(this); + presenter = new BaseMalariaRegisterPresenter(baseView, model, interactor); } @Test - public void startForm() throws Exception { - baseMalariaRegisterPresenter.startForm("formName", "", "121212121212", "231231231231"); - Mockito.verify(view, Mockito.never()).startFormActivity(null); + public void startFormWhenEntityIdIsNull() throws Exception { + presenter.startForm("formName", "", "121212121212", "231231231231"); + Mockito.verify(baseView, Mockito.never()).startFormActivity(null); } @Test - public void startFormWithEntityId() throws Exception { - baseMalariaRegisterPresenter.startForm("formName", "12121212", "121212121212", "231231231231"); - Mockito.verify(view, Mockito.never()).startFormActivity(new JSONObject()); + public void startFormWhenEntityIdIsNotNull() throws Exception { + JSONObject form = model.getFormAsJson("formName", "12131212", "231231231231"); + Mockito.when(model.getFormAsJson("formName", "12131212", "231231231231")).thenReturn(form); + Mockito.doNothing().when(baseView).startFormActivity(form); + presenter.startForm("formName", "12131212", "121212121212", "231231231231"); + Mockito.verify(baseView).startFormActivity(form); } @Test public void saveForm() { - baseMalariaRegisterPresenter.saveForm("{}"); - Mockito.verify(view, Mockito.never()).showProgressDialog(1); + presenter.saveForm("{}"); + Mockito.verify(interactor).saveRegistration("{}", presenter); + } + + @Test + public void getViewWhenViewIsNull() throws Exception { + Assert.assertNull(Whitebox.invokeMethod(baseMalariaRegisterPresenter, "getView")); + } + + @Test + public void onRegistrationSaved() { + presenter.onRegistrationSaved(); + Mockito.verify(baseView).hideProgressDialog(); } }