Skip to content

Commit

Permalink
Test for malaria due state
Browse files Browse the repository at this point in the history
  • Loading branch information
whoisladleo committed Jul 2, 2019
1 parent a7dc147 commit 53d7e11
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 28 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=1.1.9-SNAPSHOT
VERSION_NAME=1.0.0-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client CHW Malaria Library
Expand Down
1 change: 1 addition & 0 deletions opensrp-chw-malaria/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ dependencies {

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.+'
testImplementation 'org.robolectric:robolectric:3.8'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@
import org.smartregister.malaria.R;
import org.smartregister.view.activity.BaseProfileActivity;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;


public class BaseMalariaProfileActivity extends BaseProfileActivity implements MalariaProfileContract.View {
protected MemberObject MEMBER_OBJECT;
private BaseMalariaProfilePresenter profilePresenter;
private TextView textViewName, textViewGender, textViewLocation, textViewUniqueID;
private TextView textViewName, textViewGender, textViewLocation, textViewUniqueID, textViewRecordMalaria;
private View recordMalariaView;

public static void startProfileActivity(Activity activity, MemberObject memberObject) {
Intent intent = new Intent(activity, BaseMalariaProfileActivity.class);
Expand Down Expand Up @@ -60,6 +66,8 @@ public void onClick(View v) {
textViewGender = findViewById(R.id.textview_gender);
textViewLocation = findViewById(R.id.textview_address);
textViewUniqueID = findViewById(R.id.textview_id);
textViewRecordMalaria = findViewById(R.id.textview_record_malaria);
recordMalariaView = findViewById(R.id.record_visit_malaria);

MEMBER_OBJECT = (MemberObject) getIntent().getSerializableExtra(Constants.MALARIA_MEMBER_OBJECT.MEMBER_OBJECT);

Expand All @@ -79,27 +87,17 @@ public void setProfileViewWithData() {
textViewLocation.setText(MEMBER_OBJECT.getAddress());
textViewUniqueID.setText(MEMBER_OBJECT.getUniqueId());

recordMalariaButton(MEMBER_OBJECT.getMalariaTestDate());

}

private void recordMalariaButton(String malaria_test_date) {
try {
Date date = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).parse(malaria_test_date);
int malaria_test_date_processed = new Period(new DateTime(date), new DateTime()).getDays();
if(malaria_test_date_processed >= 7 && malaria_test_date_processed < 10) {
//do nothing
//malaria follow up is overdue
textViewRecordMalaria.setBackgroundColor(ContextCompat.getColor(context, R.color.due_profile_blue));
} else if(malaria_test_date_processed >= 10) {
//malaria follow up is overdue
textViewRecordMalaria.setBackgroundColor(ContextCompat.getColor(context, R.color.visit_status_over_due));
} else {
recordMalariaView.setVisibility(View.GONE);
if (MEMBER_OBJECT.getMalariaTestDate() != null) {
try {
Date date =
new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).parse((MEMBER_OBJECT.getMalariaTestDate()));
int malaria_test_date_processed = new Period(new DateTime(date), new DateTime()).getDays();
profilePresenter.recordMalariaButton(malaria_test_date_processed, textViewRecordMalaria, this);
} catch (ParseException e) {
e.printStackTrace();
}
} catch (ParseException e) {
e.printStackTrace();
}

}


Expand All @@ -124,13 +122,7 @@ public void onClick(View view) {
if (id == R.id.title_layout) {
onBackPressed();
} else if (id == R.id.textview_record_malaria) {
try {
Date date = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).parse(MEMBER_OBJECT.getMalariaTestDate());
int malaria_test_date_processed = new Period(new DateTime(date), new DateTime()).getDays();
Toast.makeText(context, "Record Malaria" + malaria_test_date_processed, Toast.LENGTH_SHORT).show();
} catch (ParseException e) {
e.printStackTrace();
}
profilePresenter.recordMalariaFollowUp(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package org.smartregister.chw.malaria.presenter;

import android.content.Context;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.Toast;

import org.smartregister.chw.malaria.contract.MalariaProfileContract;
import org.smartregister.chw.malaria.domain.MemberObject;
import org.smartregister.malaria.R;


public class BaseMalariaProfilePresenter {
Expand Down Expand Up @@ -31,4 +36,25 @@ public void fillProfileData(MemberObject memberObject) {
view.setProfileViewWithData();
}
}

public void recordMalariaButton(int days_from_malaria_test_date, View view, Context context) {
if(days_from_malaria_test_date >= 7 && days_from_malaria_test_date < 10) {
changeViewColor(view, context, R.color.due_profile_blue);
} else if (days_from_malaria_test_date >= 10){
changeViewColor(view, context, R.color.visit_status_over_due);
}
}


public void recordMalariaFollowUp(Context context) {
//call the form from this function
Toast.makeText(context, "Record Malaria", Toast.LENGTH_SHORT).show();
}

public void changeViewColor(View view, Context context, int color) {
view.setBackgroundColor(ContextCompat.getColor(context,
color));

}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package org.smartregister.presenter;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.TextView;

import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import static org.junit.Assert.*;

import org.robolectric.RuntimeEnvironment;
import org.smartregister.chw.malaria.contract.MalariaProfileContract;
import org.smartregister.chw.malaria.domain.MemberObject;
import org.smartregister.chw.malaria.presenter.BaseMalariaProfilePresenter;
import org.smartregister.malaria.R;

import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
Expand All @@ -14,14 +24,35 @@ public class BaseMalariaProfilePresenterTest {
@Mock
private MalariaProfileContract.View view = Mockito.mock(MalariaProfileContract.View.class);
@Mock
private View androidView = Mockito.mock(View.class);
@Mock
BaseMalariaProfilePresenter profilePresenter = Mockito.mock(BaseMalariaProfilePresenter.class);

@Mock
MemberObject memberObject = Mockito.mock(MemberObject.class);

@Mock
private Context context = Mockito.mock(Context.class);

@Test
public void fillProfileData_doesntCallsSetProfileViewWithDataIfMemberObjectEmpty() {
profilePresenter.fillProfileData(memberObject);
verify(view, never()).setProfileViewWithData();
}

@Test
public void malariaTestDatePeriodIsBetweenSevenAndTenSevenInclusive_recordMalariaButtonHasDueColor() {
profilePresenter.recordMalariaButton(7, androidView, context);
Drawable recordMalariaButton = Mockito.spy(new TextView(RuntimeEnvironment.application)).getBackground();
ColorDrawable recordMalariaButtonColor = (ColorDrawable) recordMalariaButton;
assertEquals(R.color.due_profile_blue, recordMalariaButtonColor.getColor());
}

@Test
public void malariaTestDatePeriodIsTenOrGreater_recordMalariaButtonHasOverDueColor() {
profilePresenter.recordMalariaButton(10, androidView, context);
Drawable recordMalariaButton = Mockito.spy(new TextView(RuntimeEnvironment.application)).getBackground();
ColorDrawable recordMalariaButtonColor = (ColorDrawable) recordMalariaButton;
assertEquals(R.color.visit_status_over_due, recordMalariaButtonColor.getColor());
}
}

0 comments on commit 53d7e11

Please sign in to comment.