Skip to content

Commit

Permalink
Merge branch 'develop_dev' of https://github.com/opensrp/opensrp-clie…
Browse files Browse the repository at this point in the history
…nt-anc into develop_dev
  • Loading branch information
junaidwarsivd committed Apr 6, 2022
2 parents ff7eb4d + 0e852af commit 9d062c8
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.sectionHeader.setText(processUnderscores(mData.get(position).getGroup()));

List<YamlConfigItem> fields = mData.get(position).getFields();
StringBuilder outputBuilder = new StringBuilder();
for (YamlConfigItem yamlConfigItem : fields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,9 @@ public void updateFormFields(JSONObject form, JSONArray fields) {

/**
* Update form properties file name according to the test fields populated
* @param taskValue {@link JSONObject}
* @param form {@link JSONObject}
*
* @param taskValue {@link JSONObject}
* @param form {@link JSONObject}
*/
public void updateFormPropertiesFileName(JSONObject form, JSONObject taskValue, Context context) {
try {
Expand All @@ -757,8 +758,9 @@ public void updateFormPropertiesFileName(JSONObject form, JSONObject taskValue,

/**
* get translated form name according to key
*
* @param formKey {@link String}
* @param context {@link Context}
* @param context {@link Context}
*/
public String getTranslatedFormTitle(String formKey, Context context) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.powermock.reflect.Whitebox;
import org.powermock.reflect.internal.WhiteboxImpl;
import org.robolectric.RuntimeEnvironment;
import org.smartregister.anc.library.activity.BaseUnitTest;
import org.smartregister.anc.library.domain.YamlConfig;
import org.smartregister.anc.library.domain.YamlConfigItem;

import java.util.ArrayList;
import java.util.List;

import timber.log.Timber;
Expand All @@ -24,11 +27,35 @@ public class ContactSummaryFinishAdapterTest extends BaseUnitTest {
private List<YamlConfig> mData;
@Mock
private Facts facts;
private List<YamlConfigItem> yamlConfigItems;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mData=new ArrayList<>();
String template = "group: reason_for_visit\n" +
"fields:\n" +
" - template: \"{{contact_summary.reason_for_visit.reason_for_coming_to_facility}}: {contact_reason_value}\"\n" +
" relevance: \"contact_reason_value != ''\"\n" +
"\n" +
" - template: \"{{contact_summary.reason_for_visit.health_complaint}}: {specific_complaint_value}\"\n" +
" relevance: \"specific_complaint_value != ''\"";
YamlConfig config = new YamlConfig();
config.setGroup("urine_tests_group");
config.setTestResults(template);
config.setPropertiesFileName("tests_file_name");
config.setSubGroup("urine_tests_subgroup");
yamlConfigItems=new ArrayList<>();
YamlConfigItem configItem=new YamlConfigItem();
configItem.setIsRedFont("user1");
configItem.setRelevance("true");
configItem.setIsMultiWidget(true);
configItem.setTemplate(template);
yamlConfigItems.add(configItem);
config.setFields(yamlConfigItems);
mData.add(config);
adapter = new ContactSummaryFinishAdapter(RuntimeEnvironment.application, mData, facts);

}

@Test
Expand Down Expand Up @@ -62,4 +89,21 @@ public void testProcessUnderscores() {
Timber.e(e, this.getClass().getCanonicalName() + " --> testProcessUnderscores");
}
}

@Test
public void testPrefillInjectibleFacts() throws Exception {
String template = "{key1},{key2},{key3},{key4},{key5},{key6},{key7}";
WhiteboxImpl.invokeMethod(adapter, "prefillInjectableFacts", facts, template);
}

@Test
public void testOnBindViewHolder() {
LinearLayout viewGroup = new LinearLayout(RuntimeEnvironment.application);
viewGroup.setLayoutParams(new LinearLayout.LayoutParams(100, 200));
ContactSummaryFinishAdapter.ViewHolder viewHolder = adapter.onCreateViewHolder(viewGroup, 0);
Assert.assertNotNull(viewHolder);
Whitebox.getInternalState(adapter, "mData");
adapter.onBindViewHolder(viewHolder, 0);
Assert.assertNotNull(mData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,13 @@ public void getPreviousContactTestsFactsTest()

}

// @Test
// public void getPreviousContact() {
// previousContact.setContactNo("2");
// previousContact.setBaseEntityId("4faf5afa-fa7f-4d98-b4cd-4ee39c8d1eb1");
// previousContact.setKey("weight_cat");
// Assert.assertNotNull(previousContact);
// PreviousContact returnPreviousContact = ancLibrary.getPreviousContactRepository().getPreviousContact(previousContact);
// Assert.assertNotNull(returnPreviousContact);
//
// }
@Test
public void getPreviousContact() {
PreviousContactRepository previousContactRepository=Mockito.mock(PreviousContactRepository.class);
Mockito.when(ancLibrary.getPreviousContactRepository()).thenReturn(previousContactRepository);
previousContact.setContactNo("2");
previousContact.setBaseEntityId("4faf5afa-fa7f-4d98-b4cd-4ee39c8d1eb1");
previousContact.setKey("weight_cat");
Assert.assertNotNull(previousContact);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import android.content.Context;

import com.vijay.jsonwizard.constants.JsonFormConstants;

import net.sqlcipher.database.SQLiteDatabase;
Expand All @@ -17,21 +19,23 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.robolectric.util.ReflectionHelpers;
import org.smartregister.Context;
import org.smartregister.CoreLibrary;
import org.smartregister.anc.library.AncLibrary;
import org.smartregister.anc.library.activity.BaseUnitTest;
import org.smartregister.anc.library.domain.Contact;
import org.smartregister.anc.library.model.PartialContact;
import org.smartregister.anc.library.repository.PartialContactRepository;
import org.smartregister.repository.Repository;
import org.smartregister.view.activity.DrishtiApplication;

import java.util.List;

import edu.emory.mathcs.backport.java.util.Arrays;

@PrepareForTest({AncLibrary.class, SQLiteDatabase.class, DrishtiApplication.class})
@PrepareForTest({AncLibrary.class, SQLiteDatabase.class, DrishtiApplication.class, CoreLibrary.class, Context.class})
public class ANCFormUtilsTest extends BaseUnitTest {

private final String quickCheckForm = "{\"validate_on_submit\":true,\"display_scroll_bars\":true,\"count\":\"1\",\"encounter_type\":\"Quick Check\",\"entity_id\":\"\",\"relational_id\":\"\",\"form_version\":\"0.0.1\",\"step1\":{\"title\":\"Quick Check\",\"fields\":" +
Expand All @@ -47,13 +51,16 @@ public class ANCFormUtilsTest extends BaseUnitTest {
@Mock
private Context context;
@Mock
private org.smartregister.Context context1;
@Mock
private PartialContactRepository partialContactRepository;

@Before
public void setUp() {

MockitoAnnotations.openMocks(this);
AncLibrary.init(context, 1);
mockedAncFormUtils = Mockito.mock(ANCFormUtils.class);
AncLibrary.init(org.smartregister.Context.getInstance(), 1);
mockedAncFormUtils = Mockito.spy(ANCFormUtils.class);
try {
accordionValuesJson = new JSONArray("[{\"key\":\"ultrasound\",\"type\":\"extended_radio_button\",\"label\":\"Ultrasound test\",\"values\":[\"done_today:Done today\"]," +
"\"openmrs_attributes\":{\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\"},\"value_openmrs_attributes\":[{\"key\":\"ultrasound\"," +
Expand Down Expand Up @@ -187,6 +194,7 @@ public void testObtainValueFromNumberSelector() throws JSONException {
public void testObtainValueFromHiddenValues() throws JSONException {
String actual = "39 weeks 6 days";
String result = ANCFormUtils.obtainValue("ultrasound_gest_age", accordionValuesJson);
ANCFormUtils.obtainValue("ultrasound_gest_age", accordionValuesJson);
assertEquals(result, actual);
}

Expand Down Expand Up @@ -235,7 +243,7 @@ public void testFilterCheckboxValuesWhenFilterOptionSourceIsDefined() throws Exc
@Test
public void testGetFormJsonCoreShouldReturnSameFormPassed() throws JSONException {
PartialContact partialContact = new PartialContact();
Mockito.when(partialContactRepository.getPartialContact(partialContact)).thenReturn(null);
Mockito.when(partialContactRepository.getPartialContact(partialContact)).thenReturn(partialContact);
Mockito.when(ancLibrary.getPartialContactRepository()).thenReturn(partialContactRepository);
ReflectionHelpers.setStaticField(AncLibrary.class, "instance", ancLibrary);
JSONObject form = new JSONObject(quickCheckForm);
Expand Down Expand Up @@ -281,9 +289,19 @@ public void testSavePreviousContactItem() throws Exception {
@Test
public void testPersistPartialContacts() {
Contact contact = new Contact();
contact.setContactNumber(1);
contact.setFormName("Malaria Tests");
contact.setJsonForm(" \"content_form\": [\n" +
String baseEnitityId = "29f324e8-8984-4977-bb68-b54ec1972d6e";
SQLiteDatabase database = Mockito.mock(SQLiteDatabase.class);
DrishtiApplication drishtiApplication = Mockito.mock(DrishtiApplication.class);
ReflectionHelpers.setStaticField(DrishtiApplication.class, "mInstance", drishtiApplication);
PartialContactRepository partialContactRepository = Mockito.mock(PartialContactRepository.class);
Repository repository = Mockito.mock(Repository.class);
Mockito.when(drishtiApplication.getRepository()).thenReturn(repository);
Mockito.when(repository.getWritableDatabase()).thenReturn(database);
CoreLibrary coreLibrary = PowerMockito.mock(CoreLibrary.class);
ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", coreLibrary);
contact.setContactNumber(3);
contact.setFormName("anc_quick_check");
contact.setJsonForm(" \"anc_quick_check\": [\n" +
" {\n" +
" \"key\": \"breast_exam_abnormal\",\n" +
" \"openmrs_entity_parent\": \"\",\n" +
Expand Down Expand Up @@ -376,8 +394,12 @@ public void testPersistPartialContacts() {
" }\n" +
" }\n" +
" ]");
Mockito.verify(mockedAncFormUtils, Mockito.times(0));
ANCFormUtils.persistPartial(DUMMY_BASE_ENTITY_ID, contact);
PartialContact partialContact = new PartialContact();
partialContact.setContactNo(contact.getContactNumber());
partialContact.setFormJson(contact.getJsonForm());
partialContact.setBaseEntityId(baseEnitityId);
partialContactRepository.savePartialContact(partialContact);


}
}
78 changes: 0 additions & 78 deletions reference-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -188,84 +188,6 @@ android {
}
}
flavorDimensions 'baseDimension'
// productFlavors {
// bzl {
// dimension 'baseDimension'
// applicationIdSuffix ".bzl"
// versionCode 8
// versionName "1.0.8"
// buildConfigField "string", 'opensrp_url', '"https://anc.labs.smartregister.org/opensrp/"'
// buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '250'
// buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '100'
// buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2'
// buildConfigField "int", "DATABASE_VERSION", '2'
// buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l"
// buildConfigField "boolean", "TIME_CHECK", "false"
// buildConfigField "int", "DATA_SYNC_DURATION_MINUTES", '15'
// buildConfigField "int", "VACCINE_SYNC_PROCESSING_MINUTES", '15'
// buildConfigField "int", "IMAGE_UPLOAD_MINUTES", '15'
// buildConfigField "int", "PULL_UNIQUE_IDS_MINUTES", '15'
// buildConfigField "int", "VIEW_SYNC_CONFIGURATIONS_MINUTES", '15'
// buildConfigField "int", "CLIENT_SETTINGS_SYNC_MINUTES", '15'
// }
// inds {
// dimension 'baseDimension'
// applicationIdSuffix '.inds'
// versionCode 8
// versionName "1.0.8"
// buildConfigField "string", 'opensrp_url', '"https://anc.labs.smartregister.org/opensrp/"'
// buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '250'
// buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '100'
// buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2'
// buildConfigField "int", "DATABASE_VERSION", '2'
// buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l"
// buildConfigField "boolean", "TIME_CHECK", "false"
// buildConfigField "int", "DATA_SYNC_DURATION_MINUTES", '15'
// buildConfigField "int", "VACCINE_SYNC_PROCESSING_MINUTES", '15'
// buildConfigField "int", "IMAGE_UPLOAD_MINUTES", '15'
// buildConfigField "int", "PULL_UNIQUE_IDS_MINUTES", '15'
// buildConfigField "int", "VIEW_SYNC_CONFIGURATIONS_MINUTES", '15'
// buildConfigField "int", "CLIENT_SETTINGS_SYNC_MINUTES", '15'
// }
// zmb {
// dimension 'baseDimension'
// applicationIdSuffix '.zmb'
// versionCode 8
// versionName "1.0.8"
// buildConfigField "string", 'opensrp_url', '"https://anc.labs.smartregister.org/opensrp/"'
// buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '250'
// buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '100'
// buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2'
// buildConfigField "int", "DATABASE_VERSION", '2'
// buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l"
// buildConfigField "boolean", "TIME_CHECK", "false"
// buildConfigField "int", "DATA_SYNC_DURATION_MINUTES", '15'
// buildConfigField "int", "VACCINE_SYNC_PROCESSING_MINUTES", '15'
// buildConfigField "int", "IMAGE_UPLOAD_MINUTES", '15'
// buildConfigField "int", "PULL_UNIQUE_IDS_MINUTES", '15'
// buildConfigField "int", "VIEW_SYNC_CONFIGURATIONS_MINUTES", '15'
// buildConfigField "int", "CLIENT_SETTINGS_SYNC_MINUTES", '15'
// }
// rwd {
// dimension 'baseDimension'
// applicationIdSuffix '.rwd'
// versionCode 8
// versionName "1.0.8"
// buildConfigField "string", 'opensrp_url', '"https://anc.labs.smartregister.org/opensrp/"'
// buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '250'
// buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '100'
// buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2'
// buildConfigField "int", "DATABASE_VERSION", '2'
// buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l"
// buildConfigField "boolean", "TIME_CHECK", "false"
// buildConfigField "int", "DATA_SYNC_DURATION_MINUTES", '15'
// buildConfigField "int", "VACCINE_SYNC_PROCESSING_MINUTES", '15'
// buildConfigField "int", "IMAGE_UPLOAD_MINUTES", '15'
// buildConfigField "int", "PULL_UNIQUE_IDS_MINUTES", '15'
// buildConfigField "int", "VIEW_SYNC_CONFIGURATIONS_MINUTES", '15'
// buildConfigField "int", "CLIENT_SETTINGS_SYNC_MINUTES", '15'
// }
// }

configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
Expand Down

0 comments on commit 9d062c8

Please sign in to comment.