Skip to content

Commit

Permalink
Merge pull request #529 from OpenSRP/Add-project-level-support-for-mls
Browse files Browse the repository at this point in the history
Add project level support for MLS
  • Loading branch information
zzainulabidin authored Dec 7, 2020
2 parents 47bfeee + ec0780a commit 847989a
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class NativeFormLibrary {

private ClientFormContract.Dao clientFormDao;
private static NativeFormLibrary instance;
private boolean performFormTranslation = false;

@NonNull
public static NativeFormLibrary getInstance() {
Expand All @@ -30,4 +31,12 @@ public ClientFormContract.Dao getClientFormDao() {
public void setClientFormDao(@NonNull ClientFormContract.Dao clientFormDao) {
this.clientFormDao = clientFormDao;
}

public boolean isPerformFormTranslation() {
return performFormTranslation;
}

public void setPerformFormTranslation(boolean performFormTranslation) {
this.performFormTranslation = performFormTranslation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.vijay.jsonwizard.NativeFormLibrary;
import com.vijay.jsonwizard.R;
import com.vijay.jsonwizard.constants.JsonFormConstants;
import com.vijay.jsonwizard.domain.Form;
Expand Down Expand Up @@ -90,7 +91,10 @@ protected void onCreate(Bundle savedInstanceState) {
onActivityRequestPermissionResultListeners = new HashMap<>();
lifeCycleListeners = new ArrayList<>();
isFormFragmentInitialized = false;
translateForm = getIntent().getBooleanExtra(JsonFormConstants.PERFORM_FORM_TRANSLATION, false);
translateForm = getIntent().hasExtra(JsonFormConstants.PERFORM_FORM_TRANSLATION) ?
getIntent().getBooleanExtra(JsonFormConstants.PERFORM_FORM_TRANSLATION, false) :
NativeFormLibrary.getInstance().isPerformFormTranslation();

if (savedInstanceState == null) {
this.form = extractForm(getIntent().getSerializableExtra(JsonFormConstants.JSON_FORM_KEY.FORM));
init(getJsonForm());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.widget.Button;
import android.widget.LinearLayout;

import com.vijay.jsonwizard.NativeFormLibrary;
import com.vijay.jsonwizard.R;
import com.vijay.jsonwizard.constants.JsonFormConstants;
import com.vijay.jsonwizard.fragments.JsonFormFragment;
Expand Down Expand Up @@ -90,8 +91,9 @@ public void onCreate(Bundle savedInstanceState) {

// support translation of sub-forms
Intent activityIntent = getActivity().getIntent();
translateSubForm = activityIntent == null ? translateSubForm
: activityIntent.getBooleanExtra(JsonFormConstants.PERFORM_FORM_TRANSLATION, false);
translateSubForm = activityIntent != null && activityIntent.hasExtra(JsonFormConstants.PERFORM_FORM_TRANSLATION) ?
activityIntent.getBooleanExtra(JsonFormConstants.PERFORM_FORM_TRANSLATION, false) :
NativeFormLibrary.getInstance().isPerformFormTranslation();

try {
setMainFormFields(formUtils.getFormFields(getStepName(), context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.content.res.Resources;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.util.Log;

import com.vijay.jsonwizard.constants.JsonFormConstants;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import android.widget.RadioGroup;
import android.widget.RelativeLayout;

import com.vijay.jsonwizard.NativeFormLibrary;
import com.vijay.jsonwizard.R;
import com.vijay.jsonwizard.TestUtils;
import com.vijay.jsonwizard.constants.JsonFormConstants;
import com.vijay.jsonwizard.domain.Form;
import com.vijay.jsonwizard.utils.FormUtils;
Expand All @@ -30,12 +32,16 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

import static org.junit.Assert.assertEquals;

public class JsonFormActivityTest extends BaseActivityTest {
private JsonFormActivity activity;
private ActivityController<JsonFormActivity> controller;
private final TestUtils testUtils = new TestUtils();

@Before
public void setUp() throws JSONException {
Expand All @@ -59,6 +65,78 @@ public void testSetConfirmationTitleUpdatesConfirmationTitleCorrectly() {
Assert.assertEquals(DUMMY_TEST_STRING, activity.getConfirmCloseTitle());
}

@Test
public void testJsonFormShouldTranslationWhenGlobalConfigIsTrue() {
String interpolatedJsonForm = testUtils.getResourceFileContentsAsString("test_form_translation_interpolated");

Intent intent = new Intent();
intent.putExtra(JsonFormConstants.JSON_FORM_KEY.JSON, interpolatedJsonForm);
NativeFormLibrary.getInstance().setPerformFormTranslation(true);
Locale.setDefault(new Locale("en", "US"));
controller = Robolectric.buildActivity(JsonFormActivity.class, intent).create().start();
activity = controller.get();
Assert.assertNotNull(activity);

String jsonForm = activity.getJsonForm();

String expectedJsonForm = testUtils.getResourceFileContentsAsString("test_form_translation_en_US");
assertEquals(expectedJsonForm, jsonForm);
}

@Test
public void testJsonFormShouldNotTranslationWhenGlobalConfigValueIsFalse() {
String inputJsonForm = testUtils.getResourceFileContentsAsString("test_form_translation_en_US");

Intent intent = new Intent();
intent.putExtra(JsonFormConstants.JSON_FORM_KEY.JSON, inputJsonForm);
NativeFormLibrary.getInstance().setPerformFormTranslation(false);
Locale.setDefault(new Locale("en", "US"));
controller = Robolectric.buildActivity(JsonFormActivity.class, intent).create().start();
activity = controller.get();
Assert.assertNotNull(activity);

String jsonForm = activity.getJsonForm();

assertEquals(inputJsonForm, jsonForm);
}

@Test
public void testJsonFormShouldNotTranslateWhenIntentValueIsFalse() {
String inputJsonForm = testUtils.getResourceFileContentsAsString("test_form_translation_en_US");

Intent intent = new Intent();
intent.putExtra(JsonFormConstants.JSON_FORM_KEY.JSON, inputJsonForm);
intent.putExtra(JsonFormConstants.PERFORM_FORM_TRANSLATION,false);
NativeFormLibrary.getInstance().setPerformFormTranslation(true);
Locale.setDefault(new Locale("en", "US"));
controller = Robolectric.buildActivity(JsonFormActivity.class, intent).create().start();
activity = controller.get();
Assert.assertNotNull(activity);

String jsonForm = activity.getJsonForm();

assertEquals(inputJsonForm, jsonForm);
}

@Test
public void testJsonFormShouldTranslateWhenIntentValueIsTrue() {
String interpolatedJsonForm = testUtils.getResourceFileContentsAsString("test_form_translation_interpolated");

Intent intent = new Intent();
intent.putExtra(JsonFormConstants.JSON_FORM_KEY.JSON, interpolatedJsonForm);
intent.putExtra(JsonFormConstants.PERFORM_FORM_TRANSLATION,true);
NativeFormLibrary.getInstance().setPerformFormTranslation(false);
Locale.setDefault(new Locale("en", "US"));
controller = Robolectric.buildActivity(JsonFormActivity.class, intent).create().start();
activity = controller.get();
Assert.assertNotNull(activity);

String jsonForm = activity.getJsonForm();

String expectedJsonForm = testUtils.getResourceFileContentsAsString("test_form_translation_en_US");
assertEquals(expectedJsonForm, jsonForm);
}

@Test
public void testSetConfirmationMessageUpdatesConfirmationMessageCorrectly() {
Assert.assertNotNull(activity.getConfirmCloseMessage());
Expand Down Expand Up @@ -166,7 +244,7 @@ public void testSetRadioButtonOptionsDisabled() throws Exception {
RadioGroup radioGroup = new RadioGroup(activity.getBaseContext());
radioGroup.addView(radioGroupChildLayout);

Whitebox.invokeMethod(activity, "setReadOnlyRadioButtonOptions",radioGroup, false);
Whitebox.invokeMethod(activity, "setReadOnlyRadioButtonOptions", radioGroup, false);
Assert.assertFalse(appCompatRadioButton.isEnabled());
}

Expand All @@ -185,7 +263,7 @@ public void testSetRadioButtonOptionsEnabled() throws Exception {
RadioGroup radioGroup = new RadioGroup(activity.getBaseContext());
radioGroup.addView(radioGroupChildLayout);

Whitebox.invokeMethod(activity, "setReadOnlyRadioButtonOptions",radioGroup, true);
Whitebox.invokeMethod(activity, "setReadOnlyRadioButtonOptions", radioGroup, true);
Assert.assertTrue(appCompatRadioButton.isEnabled());
}

Expand All @@ -204,7 +282,7 @@ public void testSetRadioButtonOptionsEnabledWithTheWrongView() throws Exception
RelativeLayout radioGroup = new RelativeLayout(activity.getBaseContext());
radioGroup.addView(radioGroupChildLayout);

Whitebox.invokeMethod(activity, "setReadOnlyRadioButtonOptions",radioGroup, true);
Whitebox.invokeMethod(activity, "setReadOnlyRadioButtonOptions", radioGroup, true);
Assert.assertFalse(appCompatRadioButton.isEnabled());
}
}
1 change: 1 addition & 0 deletions form_tester/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ dependencies {
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'org.smartregister:opensrp-client-utils:0.0.4-SNAPSHOT'
}

0 comments on commit 847989a

Please sign in to comment.